Zerbu 40 Posted January 5, 2012 (edited) Troop RandomizerIntroductionThis script creates a variable-based enemy swap. When an enemy appears in battle that matches the lits of randomized troops (defined in the setting), the enemies are all swapped with one from a list that depends on the value of a variable. This not only allows you to have a random set of enemies appear without having to manually create ever possible combination, but, being variable based, it allows you to have many different factors that determine what enemies appear.You can disable this at any time duing the game using ze_tr(:enabled, false), you can enable it again using ze_tr(:enabled, true)Script #============================================================================ # Zerbu Engine - Troop Randomizer #---------------------------------------------------------------------------- # This script creates a variable-based enemy swap. When an enemy appears in # battle that matches the lits of randomized troops (defined in the setting), # the enemies are all swapped with one from a list that depends on the # value of a variable. This not only allows you to have a random set of # enemies appear without having to manually create ever possible combination, # but, being variable based, it allows you to have many different factors # that determine what enemies appear. #---------------------------------------------------------------------------- # You can disable this at any time duing the game using # ze_tr(:enabled, false), you can enable it again using ze_tr(:enabled, true) #---------------------------------------------------------------------------- # ze_tr(:setting, value) - set the value of a setting #============================================================================ #============================================================================ # ZE_Troop_Randomizer #============================================================================ class ZE_Troop_Randomizer #-------------------------------------------------------------------------- # new method: initialize #-------------------------------------------------------------------------- def initialize #--- @data = { #---------------------------------------------------------------------- # Options #---------------------------------------------------------------------- # This option will enable or disable the system. #---------------------------------------------------------------------- :ENABLED => true, #---------------------------------------------------------------------- # This is the list of troop IDs to randomize. If a troop with one of # these IDs is used in battle, all the enemies will be swapped. The # amount and position of the enemies will remain the same. #---------------------------------------------------------------------- :RANDOMIZE_TROOPS => [1, 2, 3, 4, 5, 6, 7, 8], #---------------------------------------------------------------------- # This is the variable that adjusts what enemies should appear. #---------------------------------------------------------------------- :TROOPS_VARIABLE => 1, #---------------------------------------------------------------------- # This is the list of variable values and enemy IDs the randomized # enemies should be replaced with. #---------------------------------------------------------------------- # The format to use is: # VARIABLE => [ENEMIES] #---------------------------------------------------------------------- :ENEMIES => { 0 => [2, 3, 4], 1 => [4, 5, 6], }, } #--- end #-------------------------------------------------------------------------- # new method: [] #-------------------------------------------------------------------------- def [](setting) #--- @data[setting] || false #--- end #-------------------------------------------------------------------------- # new method: []= #-------------------------------------------------------------------------- def []=(setting, value) #--- @data[setting] = value #--- end end #============================================================================ # DataManager #============================================================================ module DataManager class << self #------------------------------------------------------------------------ # alias method: create_game_objects #------------------------------------------------------------------------ alias ze_tr_create_game_objects create_game_objects def create_game_objects #--- ze_tr_create_game_objects $ze_tr = ZE_Troop_Randomizer.new #--- end #------------------------------------------------------------------------ # alias method: make_save_contents #------------------------------------------------------------------------ alias ze_tr_make_save_contents make_save_contents def make_save_contents #--- contents = ze_tr_make_save_contents contents[:ze_tr] = $ze_tr contents #--- end #------------------------------------------------------------------------ # alias method: extract_save_contents #------------------------------------------------------------------------ alias ze_tr_extract_save_contents extract_save_contents def extract_save_contents(contents) #--- ze_tr_extract_save_contents(contents) $ze_tr = contents[:ze_tr] ? contents[:ze_tr] : ZE_Troop_Randomizer.new #--- end end end #============================================================================ # Game_Troop #============================================================================ class Game_Troop < Game_Unit #-------------------------------------------------------------------------- # alias method: setup #-------------------------------------------------------------------------- alias ze_tr_setup setup def setup(troop_id) #--- if $ze_tr[:ENABLED] && $ze_tr[:ENEMIES][$game_variables[$ze_tr[:TROOPS_VARIABLE]]] && $ze_tr[:RANDOMIZE_TROOPS].include?(troop_id) #--- clear #--- @troop_id = troop_id @enemies = [] #--- troop.members.each do |member| #--- next unless $data_enemies[member.enemy_id] #--- enemy = Game_Enemy.new(@enemies.size, $ze_tr[:ENEMIES][$game_variables[$ze_tr[:TROOPS_VARIABLE]]][rand($ze_tr[:ENEMIES][$game_variables[$ze_tr[:TROOPS_VARIABLE]]] #--- enemy.hide if member.hidden enemy.screen_x = member.x enemy.screen_y = member.y @enemies.push(enemy) #--- end #--- init_screen_tone make_unique_names #--- else #--- ze_tr_setup(troop_id) #--- end #--- end end #============================================================================ # Game_Interpreter #============================================================================ class Game_Interpreter #-------------------------------------------------------------------------- # new method: ze_tr #-------------------------------------------------------------------------- def ze_tr(setting, value) #--- $ze_tr[setting.upcase] = value #--- end end Edited February 19, 2014 by Zerbu Share this post Link to post Share on other sites
Deus_Ex_Mittenz 0 Posted May 9, 2012 so with this script, it would be possible to alter enemy encounters based on the level of the characters in my party? (e.g. my party members are around level 25, so level 20-30 monsters appear) i've been trying to get a script that does exactly that for some time now, and have yet to make one myself that functions properly. Share this post Link to post Share on other sites
Tsukihime 1,487 Posted May 9, 2012 No, the script does not know anything about things like monster levels. It only knows enemy indices. Share this post Link to post Share on other sites
bloodyliao 5 Posted July 30, 2014 Something wrong with the following line! enemy = Game_Enemy.new(@enemies.size, $ze_tr[:ENEMIES][$game_variables[$ze_tr[:TROOPS_VARIABLE]]][rand($ze_tr[:ENEMIES][$game_variables[$ze_tr[:TROOPS_VARIABLE]]] maybe ')])' is expected, but after adding ')])', still can't work in the game, showing can't convert Array into Integer! Share this post Link to post Share on other sites