Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###--------------------------------------------------------------------------###
- # Scale Encounters script #
- # Version 1.0 #
- # #
- # Credits: #
- # Original code by: Neonblack #
- # Modified by: #
- # #
- # This work is licensed under the Creative Commons Attribution-NonCommercial #
- # 3.0 Unported License. To view a copy of this license, visit #
- # http://creativecommons.org/licenses/by-nc/3.0/. #
- # Permissions beyond the scope of this license are available at #
- # http://cphouseset.wordpress.com/liscense-and-terms-of-use/. #
- # #
- # Contact: #
- # NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype #
- ###--------------------------------------------------------------------------###
- ###--------------------------------------------------------------------------###
- # Revision information: #
- # V1.0 - 7.17.2012 #
- # Wrote and debugged main script #
- ###--------------------------------------------------------------------------###
- ###--------------------------------------------------------------------------###
- # Compatibility: #
- # Alias - Game_Player: encounter, update_encounter #
- # Scene_Map: create_all_windows #
- # Overwrites - Game_Player: make_encounter_count #
- # Scene_Map: update_encounter #
- # New Objects - Game_Interpreter: encounters #
- # Game_Player: set_encounters_total, encounter_rate_refresh, #
- # lower_scale_val, lower_enc_scale #
- # Scene_Map: create_encounter_window #
- # Window_ScaleEncounter: initialize, update, refresh #
- ###--------------------------------------------------------------------------###
- ###--------------------------------------------------------------------------###
- # Instructions: #
- # Place this script in the "Materials" section of the scripts above main. #
- # This script modifies how random encounters are generated by creating a #
- # random value each step rather than using a static value at the start of #
- # each map and battle. The random value will also scale from a top ratio to #
- # a bottom ratio based on the map encounter rate. There are a few settings #
- # that need to be set and depending on the settings you may need to use the #
- # command below. #
- # #
- # encounter(x) - When using the "encounter gauge", you need to manually #
- # set the number of battles that appear in an area. To do #
- # this, set up a script call somewhere in the transfer #
- # event at the start of the area with this script call in #
- # it. You set the total number of battles you can find in #
- # the area by changing "x" to the number of battles you #
- # want to be able to find. #
- ###--------------------------------------------------------------------------###
- ###--------------------------------------------------------------------------###
- # Config: #
- # These are the default values used by several of the functions in the #
- # script. You may change these values as you find your game requires in #
- # order to give the player a better playing experience based on your game. #
- # #
- module CP # Do not #
- module SCALE_ENCOUNTER # change these. #
- # #
- ###----- -----###
- # This is the top ratio value to use for random encounters. After entering a #
- # map or fighting in a battle, the encounter ratio resets to this value and #
- # on each step will scale down to at least the map average steps. This means #
- # you have a higher chance of getting into a battle on later steps. #
- TOP_VALUE = 100 # Default = 100 #
- # #
- # The rate at which the guage scales down to the average steps. The higher #
- # this number, the faster the encounters scale down. #
- SCALE_AMOUNT = 1.0 # Default = 1.0 #
- # #
- ###----- -----###
- # Choose wether or not to use the encounters gauge. If this is set to true #
- # you will need to set the number of encounters in an area using the command #
- # above (see the instructions section). If set to false, you do not need to #
- # set any of the following options and are done with the config. #
- ENCOUNTERS_GAUGE = true # Default = true #
- # #
- # Choose if you want to show the encounter gauge on the map. This changes #
- # color depending on the scale and also decreases as the number of battles #
- # remaining drops. The gauge does not show up on maps with no encounters or #
- # with 0 average steps. #
- SHOW_GAUGE = true # Default = true #
- # #
- # Set the colors for the gauge. "LO" colors are for when scaling has a high #
- # ratio, "HI" colors are for when the ratio has a low scaling. #
- GAUGE_COLOR_LO_1 = Color.new( 50, 200, 50) #
- GAUGE_COLOR_LO_2 = Color.new(125, 255, 125) #
- # #
- GAUGE_COLOR_HI_1 = Color.new(200, 50, 50) #
- GAUGE_COLOR_HI_2 = Color.new(255, 125, 125) #
- # #
- ###--------------------------------------------------------------------------###
- ###--------------------------------------------------------------------------###
- # The following lines are the actual core code of the script. While you are #
- # certainly invited to look, modifying it may result in undesirable results. #
- # Modify at your own risk! #
- ###--------------------------------------------------------------------------###
- end
- end
- $imported = {} if $imported.nil?
- $imported["CP_SCALE_ENCOUNTER"] = 1.0
- class Game_Interpreter
- def encounters(i = 1) ## So an encounters script call works.
- $game_player.set_encounters_total(i)
- end
- end
- class Game_Player < Game_Character
- attr_reader :scale_enc_max ## Sets all the new readers.
- attr_reader :scale_enc_min
- attr_reader :scale_enc_cur
- attr_reader :scale_enc_total
- attr_reader :scale_enc_left
- def set_encounters_total(i = 1) ## Makes new total and current encounters.
- @scale_enc_total = i
- @scale_enc_left = i
- end
- def make_encounter_count ## Overwriten. Resets the scale.
- @scale_enc_max = CP::SCALE_ENCOUNTER::TOP_VALUE
- @scale_enc_min = $game_map.encounter_step
- @scale_enc_cur = @scale_enc_max
- @scale_enc_total = 1 if @scale_enc_total.nil?
- @scale_enc_left = 1 if @scale_enc_left.nil?
- @encounter_count = @scale_enc_cur
- end
- alias cp_se_encounter encounter unless $@
- def encounter ## Ignores encounters if there are none left.
- return false if @scale_enc_left <= 0
- cp_se_encounter
- end
- alias cp_se_update_encounter update_encounter unless $@
- def update_encounter
- cp_se_update_encounter ## Gets the encounter chance via the ratio.
- @encounter_count = encounter_rate_refresh
- end
- def encounter_rate_refresh ## Reduces the scale and gets an encounter value.
- @scale_enc_cur -= lower_scale_val if @scale_enc_cur > @scale_enc_min
- @scale_enc_cur = @scale_enc_min if @scale_enc_cur < @scale_enc_min
- return rand(@scale_enc_cur) ## Returns the random number.
- end
- def lower_scale_val ## Used to find the scale speed.
- res = 1 * encounter_progress_value * CP::SCALE_ENCOUNTER::SCALE_AMOUNT
- return res
- end
- def lower_enc_scale ## Reduces the number of encounters by 1.
- return unless CP::SCALE_ENCOUNTER::ENCOUNTERS_GAUGE
- @scale_enc_left -= 1
- end
- end
- class Window_ScaleEncounter < Window_Base
- def initialize ## Sets the encounter window's size.
- super(Graphics.width - 146, Graphics.height - 40, 138, 32)
- self.back_opacity = 0 ## Makes the back clear.
- self.openness = 0 ## Closes the window.
- @gcur = 0 ## Gives nul values to the variables.
- @gtot = 0 ## gcur is for scaling, gtot is for encounter numbers.
- end
- def update
- super ## Ignores a refresh if nothing has changed.
- refresh if (@gcur != $game_player.scale_enc_cur) ||
- (@gtot != $game_player.scale_enc_left)
- end
- def refresh
- if $game_map.encounter_step == 0 || $game_map.encounter_list.empty?
- self.openness = 0 ## Keep closed if there are no battles.
- else
- open ## Open up the gauge if needed.
- if $game_player.scale_enc_total == 0
- width = 0 ## Prevents "divided by zero" errors.
- else
- width = $game_player.scale_enc_left.to_f / $game_player.scale_enc_total
- width *= 112 ## Gets gauge width.
- end
- cb1 = CP::SCALE_ENCOUNTER::GAUGE_COLOR_LO_1 ## Gets all colors.
- cb2 = CP::SCALE_ENCOUNTER::GAUGE_COLOR_LO_2
- ct1 = CP::SCALE_ENCOUNTER::GAUGE_COLOR_HI_1
- ct2 = CP::SCALE_ENCOUNTER::GAUGE_COLOR_HI_2 ## Find scale rate.
- rate1 = $game_player.scale_enc_max - $game_player.scale_enc_min
- if rate1 <= 0 ## Ignores the "High" gauge in non-scaling cases.
- alp = 0
- else
- rate2 = $game_player.scale_enc_max - $game_player.scale_enc_cur
- alp = rate2.to_f / rate1
- alp *= 255 ## Makes the alpha rate for the "high" gauge.
- end
- contents.fill_rect(1, 1, 112, 6, gauge_back_color) ## Gauge back.
- contents.gradient_fill_rect(1, 1, width, 6, cb1, cb2) ## "Low" gauge.
- bitmap = Bitmap.new(contents.width, contents.height)
- bitmap.gradient_fill_rect(1, 1, width, 6, ct1, ct2) ## "High" gauge.
- contents.blt(0, 0, bitmap, bitmap.rect, alp) ## BLT in the "high" gauge.
- end
- @gcur = $game_player.scale_enc_cur ## Sets the variable values.
- @gtot = $game_player.scale_enc_left ## This prevents constant refreshes.
- end
- end
- class Scene_Map < Scene_Base
- def update_encounter ## Overwrite this to decrease encounters total.
- if $game_player.encounter
- $game_player.lower_enc_scale
- SceneManager.call(Scene_Battle)
- end
- end
- alias cp_se_create_all_windows create_all_windows unless $@
- def create_all_windows
- create_encounter_window if CP::SCALE_ENCOUNTER::SHOW_GAUGE
- cp_se_create_all_windows ## Adds a new window.
- end
- def create_encounter_window ## Creates that new window.
- @map_encounter_window = Window_ScaleEncounter.new
- end
- end
- ###--------------------------------------------------------------------------###
- # End of script. #
- ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement