The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on April 30, 2010, 02:28:02 AM

Title: Update Encounter Percentage
Post by: modern algebra on April 30, 2010, 02:28:02 AM
Update Encounter Percentage
Version: 1.0
Author: modern algebra
Date: April 29, 2010

Version History



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


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



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.
Title: Re: Update Encounter Percentage
Post by: LuKo on May 01, 2010, 03:43:31 PM
This may look simple, but is awesome for those who use the basic ecounter system of rpg maker 'o'

Awesome job^^
Title: Re: Update Encounter Percentage
Post by: simus on July 12, 2010, 08:15:37 PM
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'

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fwww.hizliupload.com%2Fimg%2F240504Adsiz.jpg&hash=c430f09378f17bec045f1f09174aa481ab4b7c53)

Can you give a demo ?
Title: Re: Update Encounter Percentage
Post by: modern algebra on July 12, 2010, 08:36:28 PM
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.
Title: Re: Update Encounter Percentage
Post by: DarkMessiah on August 03, 2010, 12:47:10 AM
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
Title: Re: Update Encounter Percentage
Post by: Underking on August 03, 2010, 10:06:43 PM
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.
Title: Re: Update Encounter Percentage
Post by: modern algebra on August 24, 2010, 01:49:24 PM
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.
Title: Re: Update Encounter Percentage
Post by: thanatos2k1 on August 01, 2011, 02:44:46 AM
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?
Title: Re: Update Encounter Percentage
Post by: modern algebra on August 01, 2011, 11:50:35 AM
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
Title: Re: Update Encounter Percentage
Post by: thanatos2k1 on August 01, 2011, 12:52:49 PM
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. >.<
Title: Re: Update Encounter Percentage
Post by: modern algebra on August 01, 2011, 01:08:30 PM
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
Title: Re: Update Encounter Percentage
Post by: thanatos2k1 on August 01, 2011, 01:11:05 PM
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???  :-/


 
Title: Re: Update Encounter Percentage
Post by: thanatos2k1 on August 01, 2011, 02:12:33 PM
Scratch that, I figured it out! Thank you very much!