RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Update Encounter Percentage

0 Members and 2 Guests are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Update Encounter Percentage
Version: 1.0
Author: modern algebra
Date: April 29, 2010

Version History


  • <Version 1.0> 04.29.2010 - Original Release

Description


This script allows you to dynamically alter the rate at which encounters happen. It is useful particularly for making items or skills that can reduce or increase the rate of encounters. What this script does is allow you to specify a variable to control encounter rate, so you can use events and common events to change the percentage of the map default at which encounters occur.

Features

  • Allows you to dynamically alter encounter rate in the same map
  • Can be used to make areas of the same map where encounters are more or less frequent
  • Can be used with common events to make items or skills that make random encounters more or less frequent
  • Everything is done with a single in-game variable that you specify

Instructions

Please see the header for instructions on how to use this script.

Script


Code: [Select]
#==============================================================================
#    Update Encounter Percentage
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: April 29, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to dynamically alter the rate at which encounters
#   happen. It is useful particularly for making items or skills that can
#   reduce or increase the rate of encounters. What this script does is allow
#   you to specify a variable to control encounter rate, so you can use events
#   and common events to change the percentage of the default at which
#   encounters occur.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Paste this script into its own slot in the Script Editor (F11) above Main
#   but below Materials.
#
#    To set up which variable you want to control Encounter Rate, go to line 38
#   and set UEP_CONTROL_VARIABLE_ID to the ID of the variable you want.
#
#    The in-game value of the variable that you set will be the modified
#   percentage of encounters.
#    EX: If that variable is set to 100, then the encounter rate will not
#   change at all. If it's set to 50, then encounters will occur half as
#   frequently. If it's set to 200, then encounters will occur twice as
#   frequently. As a default measure, when that variable is set to 0, then it
#   will not alter encounter rate in any way. If you set the variable to
#   anything below 0 then no encounters will occur at all.
#==============================================================================

#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#  EDITABLE REGION
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# The ID of the variable that controls how the encounter rate is updated
UEP_CONTROL_VARIABLE_ID = 1
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#  END EDITABLE REGION
#//////////////////////////////////////////////////////////////////////////////
#==============================================================================
# ** Game Variables
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - []=
#==============================================================================

class Game_Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Variable
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malg_upep_setvar_7uj1 []=
  def []= (var_id, *args)
    old_val = self[var_id]
    malg_upep_setvar_7uj1 (var_id, *args)
    # Scale Encounter percentage if this is the control variable
    if var_id == UEP_CONTROL_VARIABLE_ID && old_val != self[var_id]
      $game_player.calc_encounter_percent (old_val)
    end
  end
end

#==============================================================================
# ** Game Player
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - update_encounter, make_encounter_count
#    new method - calc_enc_percent
#==============================================================================

class Game_Player
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Make Encounter Count
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modern_ueper_mkencnt_5fv1 make_encounter_count
  def make_encounter_count (*args)
    modern_ueper_mkencnt_5fv1 (*args)
    calc_encounter_percent
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Encounter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malg_uep_updenc_6yj2 update_encounter
  def update_encounter (*args)
    variable = $game_variables[UEP_CONTROL_VARIABLE_ID]
    return if variable.nil? || variable < 0
    malg_uep_updenc_6yj2 (*args) # Run Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Calculate Encounter Percentage
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def calc_encounter_percent (old_mod = 100)
    variable = $game_variables[UEP_CONTROL_VARIABLE_ID]
    return if variable.nil? || variable < 0 || old_mod < 0
    old_mod = 100 if old_mod == 0
    variable = 100 if variable == 0
    @encounter_count = (@encounter_count*(old_mod.to_f / variable.to_f)).to_i
  end
end

Credit


  • modern algebra

Support


Please post in this topic at RMRK.net with any bugs or incompatibilities you encounter when using this script.

Known Compatibility Issues

No currently known compatibility issues.

**
Rep:
Level 81
Dark Matter
This may look simple, but is awesome for those who use the basic ecounter system of rpg maker 'o'

Awesome job^^

*
Rep: +0/-0Level 76
RMRK Junior
I am from Turkey and I have google translate well into your topic. I came into the game and gave this error.

Error:

Script ' ' line 53: NameEror occurred.
undefined method '[]=' for class 'Game_Variables'



Can you give a demo ?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I can only see you getting that error if you tried pasting this script above Game_Variables, or if you replaced Game_Variables altogether, neither of which you should do.

In the script editor, make sure you paste the script above Main but below all the other default scripts. I attached a screenshot of where it should be in the script order.

***
herp derp
Rep:
Level 81
Newclear Bomb
Good script for "Repel" items so Random encounters can be avoided(Think pokemon)Unrelated, howd you get your scrips all organized like that? like with a dropdown menu and such. Mines just a big cluster of scripts

**
Rep: +0/-0Level 76
So ace
Cool script, I'll be using it fo' sho'.

Now, @DylanMachinima:
Try closing XP for a moment and then try opening VX. Then keep XP closed, and scroll up to the top of this screen. Yeah, it should say this (in your web browser):

> The RPG Maker Resource Kit
> RMRK Game Creation
> Scripts
> RMVX Scripts Database
>Post reply ( Re: Update Encounter Percentage )

Now let's take a look at the fourth line...

> RMVX Scripts Database

Right, so this is an RMVX script! And the screenshot's from RMVX! Wow...!

Joke aside, if you are actually in VX then you probably have an illegal version or something. You can do it customly: You'll want this to make it cool-looking: ?
Or just copy and paste the 'scripts.rvdata' from (and to...) the data folder from someone's unencrypted game.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, first, there is no Variable 0000, so you need to set it to something different. Secondly, if it's set to 30, then encounters will occur 30% of the time they would have. So, if encounters were normally set to happen every 30 steps, they will instead happen every 100 steps. If you wanted 70%, you'd set it to 70.

As for setting it back; that's up to you and eventing. There is a Control Variable option that sets a Variable to the number of steps the party has taken. You could easily set up an event that does that and subtracts steps from the last time the encounter percentage was changed and, when it reaches a certain number, resets the encounter variable back to 100.

***
Rep:
Level 69
RMRK Junior
This is perfect for my game.. I'm trying to use it and I'm attempting to make it turn off after 200 steps, I'm having a difficult time setting up the common event, what I have is not working.  Can anyone tell me what it should look like?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
In the event where you change the encounter percentage, set a variable (in my example, it is [X: Steps at Event]) to the number of steps at the time. It is an option under other. Also, turn on a switch (in my example, [Z: Encounter Step Counter]) and use that switch as a trigger for a parallel process common event that looks something like this:

Control Variables: [Y: Player Steps Now] = Steps
Control Variables: [Y: Player Steps Now] -= Variable [X: Steps at Event]
Conditional Branch: Variable [Y: Player Steps Now] >= 200
  # Change the Encounter Variable Back to Normal
  Control Switch: [Z: Encounter Step Counter] = OFF
 : Branch END
Wait: 12 frames

***
Rep:
Level 69
RMRK Junior
I used the common event accurately, however it turns off as soon as it's used..  don't know what I'm doing wrong, I made it exactly how you explained. >.<

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, send me a demo of what you have I guess.

There is no reason that would turn off immediately unless you aren't setting the X: Steps at Event variable to Steps when you first change the encounter percentage

***
Rep:
Level 69
RMRK Junior
Here is what I have for the Common event that is used when you use the skill:

@>COntrol Variables:[0022:SKILLUP = Random No. (1..100)
@>Conditional Branch: Variable [0022:SKILL UP >= 85
    @>Control Variables: [0028:Sense Evil] += 1
    @>Text
         :Your skill in Sense Evil has gone up. It is now \v[028].
    @>
    Else
    @>
@>Control Variables: [0022:SKILL UP] = Random No. (1...100)
@>Conditional Branch: Variable [0022:SKILL UP] >= 25
   @>Text
           :You were able to Sense Evil.  Encounter rate is now \v[028]% lower.
   @>Control Variables:[0029:Encounter Minus] = 100
   @>Control Variables:[0029:Encounter Minus] -= Variable[0028:Sense Evil]
   @>Control Variables:[0030:Steps At Event] = Steps
   @>Control Switches:[0088:StepCounter] = ON
   @>Call Common Event: StepCounter
   @>
   Else
   @>Text
            :You were not able to Sense Evil.
   @>
:  Branch End
@>



This is what I have for Common Event StepCounter

Trigger: Parallel,  Condition Switch:  [0088:Step Counter]

@> Control Variables: [0031:StepsNew] = Steps
@>Control Variables: [0031:StepsNew] -= Variable [0030:Steps At Event]
@>Conditional Branch: Variable [0031:StepsNew] >= 200
    @>Control Variables: [0029:Encounter Minus] = 100
    @>Text:
    :    Your Sense Evil has worn off.
    @>Control Switches: [0088: Stepcounter] = OFF
    @>
    Else
    @>
    Branch End
@>Wait: 12 frame(s)
@>




Can anyone see something I'm doing wrong???  :-/


 

***
Rep:
Level 69
RMRK Junior
Scratch that, I figured it out! Thank you very much!