Advanced Map Encounters
This script allows you to assign something that always bothered me that was not in the RPG maker by default: Make on a map some enemy encounters more likely than others. There are other scripts that fix this, but I wanted to make one simple and as intuitive as possible, apart from putting some unique things on it.The map encounters still work basically as always, I simplified the encounter formula (now it's a bit more random when you will encounter them, but just as likely after all), but the important thing is that you can assign encounters by hand using an event controlling the steps necessary for that meeting. Allowing encounters or not also works the same, as does pressing CTRL in Debug mode.
Author: Wecoc
First Release: October 2016
Last Version: November 2017
Terms of use
- Giving credits (Wecoc) is optional, but appreciated.
- You can repost this code.
- You can edit this code freely, and distribute the edits as well.
- This code can be used on commercial games.
Script
Ruby:
#==============================================================================
# ** Advanced Map Encounters v1.2
#------------------------------------------------------------------------------
#Author: Wecoc - No credits required
#==============================================================================
#==============================================================================
# ** RPG encounter rates
#==============================================================================
module RPG
for Klass in
class Klass
attr_accessor :encounter_rate
define_method(:encounter_rate) { @encounter_rate ||= 1.0}
end
end
end
#==============================================================================
# ** Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
def encounter_rate
result = $data_actors[@actor_id].encounter_rate
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
result *= weapon.encounter_rate if weapon != nil
result *= armor1.encounter_rate if armor1 != nil
result *= armor2.encounter_rate if armor2 != nil
result *= armor3.encounter_rate if armor3 != nil
result *= armor4.encounter_rate if armor4 != nil
for state in @states
state = $data_states
result *= state.encounter_rate if state != nil
end
return result
end
end
#==============================================================================
# ** Game_Map
#==============================================================================
class Game_Map
attr_reader :encounters
#--------------------------------------------------------------------------
# * Setup
#--------------------------------------------------------------------------
alias adv_encounter_setup setup unless $@
def setup(map_id)
adv_encounter_setup(map_id)
@encounters = []
# Define the default map encounters
encounter_list = @map.encounter_list
encounter_steps = @map.encounter_step * encounter_list.size
for troop_id in encounter_list
set_encounter(troop_id, encounter_steps, nil)
end
end
#--------------------------------------------------------------------------
# * Clear default encounter list
#--------------------------------------------------------------------------
def encounter_list
return []
end
#--------------------------------------------------------------------------
# * Clear steps for default encounter
#--------------------------------------------------------------------------
def encounter_step
return 0
end
#--------------------------------------------------------------------------
# * Set new encounter
#--------------------------------------------------------------------------
def set_encounter(troop_id, steps, area=nil)
steps = [.max, 999].min
@encounters.push()
@encounters.uniq!
@encounters.sort!{|b,a| b - a}
end
#--------------------------------------------------------------------------
# * Clear encounter
#--------------------------------------------------------------------------
def clear_encounter(troop_id, steps, area=nil)
steps = [.max, 999].min
@encounters.delete!()
end
end
#==============================================================================
# ** Game_Player
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Increase steps
#--------------------------------------------------------------------------
alias adv_encounter_steps increase_steps unless $@
def increase_steps
adv_encounter_steps
return if $DEBUG && Input.press?(Input::CTRL)
return if $game_system.encounter_disabled == true
rate = 1.0
for actor in $game_party.actors
rate *= actor.encounter_rate
end
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
$game_party.item_number(i).times do
rate *= $data_items.encounter_rate
end
end
end
return if rate == 0
$game_map.encounters.each do |encounter|
get_encounter_data(encounter, rate)
return if $game_temp.battle_calling
end
end
#--------------------------------------------------------------------------
# * Evaluate the info on each encounter
#--------------------------------------------------------------------------
def get_encounter_data(encounter, rate)
troop_id = encounter
return if $data_troops == nil
ratio = encounter * (1.0 / rate)
encounter_area = encounter
if Game_Player.method_defined?(:area) && encounter_area != nil
next if self.area != encounter_area
end
if rand < ratio
# Empezar batalla
$game_temp.battle_calling = true
$game_temp.battle_troop_id = troop_id
$game_temp.battle_can_escape = true
$game_temp.battle_can_lose = false
$game_temp.battle_proc = nil
end
end
end
#==============================================================================
# ** Game_Temp
#==============================================================================
class Game_Temp
attr_accessor :force_battleback
alias area_battleback_ini initialize unless $@
def initialize
area_battleback_ini
@force_battleback = false
end
end
#==============================================================================
# ** Game_Map (Battleback Areas)
#==============================================================================
class Game_Map
BATTLEBACK_AREAS = {} # {AREA ID => 'BATTLEBACK NAME'}
def battleback_name
return @battleback_name if $game_temp.force_battleback == true
area = $game_player.area rescue 0
battleback_area = BATTLEBACK_AREAS
return battleback_area if !battleback_area.nil?
return @battleback_name
end
end
Instructions
To set an encounter from an event use:
$game_map.set_encounter(Troop ID, Steps)(Steps must be between 1 and 999)
If that encounter is already defined and you want to remove it, use:
$game_map.clear_encounter(Troop ID, Steps)
Spoiler: AreaIf you are using Area Support, you can assign encounters by area.
$game_map.set_encounter(Troop ID, Steps, Area ID)
You can also assign battlebacks by area.
To do that, search this line:
BATTLEBACK_AREAS = {}
And set the battleback there by area ID, like this:
BATTLEBACK_AREAS = {1 => '001-Grassland01'}
Finally, you can control in-game if that's being considered or if you want to use the default battleback. To do that use:
$game_temp.force_battleback = true / false
Spoiler: Encounter rateYou can set encounter rates on certain actors, items, weapons, protectors or states.
$data_actors[ID].encounter_rate = 1.0
$data_items[ID].encounter_rate = 1.0
$data_weapons[ID].encounter_rate = 1.0
$data_armors[ID].encounter_rate = 1.0
$data_states[ID].encounter_rate = 1.0
Spoiler: Encounter conditionsThis little Addon allows defining some advanced encounter conditions.
Ruby:
#==============================================================================
# ** Encounter Conditions
#------------------------------------------------------------------------------
# Author: Wecoc (no credits required)
# This script requires the script Advanced Map Encounters
#==============================================================================
class Game_Map
def set_encounter(troop_id, steps, area=nil, condition=nil)
steps = [.max, 999].min
@encounters.push()
@encounters.uniq!
@encounters.sort!{|b,a| b - a}
end
def clear_encounter(troop_id, steps, area=nil, condition=nil)
steps = [.max, 999].min
@encounters.delete!()
end
end
class Game_Player
alias condition_encounter_data get_encounter_data unless $@
def get_encounter_data(encounter, rate)
if encounter != nil
return if eval(encounter) == false
end
condition_encounter_data(encounter, rate)
end
end
It works as before, but with a new optional argument on the callers:
$game_map.set_encounter(Troop ID, Steps, Area, Condition)
Example:
$game_map.set_encounter(1, 20, nil, "$game_switches == true")
本贴来自国际rpgmaker官方论坛作者:Wecoc处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/advanced-map-encounters.139675/
页:
[1]