Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=============================================================================
- #
- # Unlimited Battle Page Conditions
- # Authors: Heretic (edited by LiTTleDRAgo)
- # Version 1.0
- # Monday, January 20th, 2014
- #
- #-----------------------------------------------------------------------------
- #
- # --- OVERVIEW ---
- #
- # This script will allow you to add an Unlimited Number of Page Conditions
- # for Battle Events by using Comments as a Condition on each Battle Page
- #
- # --- IMPORTANT! ---
- #
- # The Conditions that you put in to the Comment MUST be able to evaluate
- # to true / false!
- #
- # What this means is that a Condition of var = 1 will run, but not evaluate
- # to true, so it wont ever be recognized as a valid condition. By placing
- # a Condition of "if var == 1" will return true, which makes it valid when
- # the proper conditions are met.
- #
- # --- USAGE ---
- #
- # Create a Condition by making a Comment ANYWHERE on a Battle Event Page
- # with "condition:" followed by your Scripted Condition in the Comment.
- #
- # Example #1:
- #
- # @>Comment: condition: if $foo == $bar
- #
- #
- # Comment Conditions will run Eval for ALL of the contents for each Comment
- # all at once. This allows you to have a Multi Line Condition.
- #
- # Example #2:
- #
- # @>Comment: condition: if ($foo == $bar and
- # $lorem == $ipsum)
- #
- #
- # Comments run as Scripts just like a Script Event, so you can put anything
- # into the Script. Loops, Iterations, Create Variables, Self Switches, etc.
- #
- # Example #3
- #
- # @>Comment: condition: result = false
- # for actor in $game_party.actors
- # if actor.weapon_id == 12
- # result = true
- # end
- # end
- # return true if result == true
- #
- #
- # Each Comment Condition you add will add another Condition to check before
- # the Battle Event Page can be run. This allows you to add as many Conditions
- # as you want. THERE IS NO LIMIT. Each Comment Condition is considered as
- # its own Condition.
- #
- # Example #4:
- #
- # @>Comment: condition: $game_party.actors[0].hp == $game_party.actors[0].maxhp &&
- # @>Comment: $game_party.actors[0].id == 2
- #
- # In the above example, BOTH Conditions MUST BE MET for the Battle Event Page
- # to be considered Valid and thus run.
- #
- #
- # You can use OR Statements inside of a single Comment Condition allowing for
- # greater flexibility of Battle Page Conditions.
- #
- # Examle #5:
- #
- # @>Comment: condition: if $foo == $bar OR $lorem == $ipsum
- #
- #
- # ANY Sript Logic can be used provided it fits in the comment. Its all
- # evaluated the same way.
- #
- # --- BATTLE EVENTING ---
- #
- # Battle Eventing has a Menu for a few things already. Such as checking to
- # make sure a certain Switch is on before running the Battle Event Page. You
- # can now use a Comment Condition to check if a certain Switch is OFF before
- # running a Battle Event Page.
- #
- # Battle Event also uses what is called SPAN.
- #
- # SPAN controls when and how many times to run a Battle Event Page.
- #
- # Span: Battle - Page runs ONCE per the entire Battle
- # Turn: Page runs ONCE per Turn, even if conditions are still met.
- # Moment: Runs when Conditions are met, and continues to run as long as
- # those conditions are met.
- #
- # Comment Conditions are EXTREMELY USEFUL for allowing a Span Moment Page
- # to STOP RUNNING. It allows you to run the Page once. Like a specific
- # enemy has a State of "Immune to Fire", run some dialogue once, then
- # use some variable to set that the page has run already. You could use
- # a Switch, or even any other variable like @this_page_ran = true, and set
- # that as a Condition.
- #
- # Example #6
- #
- # @>Comment: condition: if $game_troop.enemies[0].states.include?(12)
- # @this_new_var_for_page_ran = true
- # else
- # unless @this_new_var_for_page_ran
- # @this_new_var_for_page_ran = false
- # end
- # end
- # @>Conditional Branch: Script: @this_new_var_for_page_ran != true
- # @>Text: "Don't cast Fire on him! He is now Immune to Fire!"
- # @>End Branch
- #
- # --- COMMAND LIST ---
- #
- # I'd like to make this as easy as possible for people to use. So to do that
- # these list of Commands should make adding Comment Conditions easier.
- #
- # Example of Command:
- #
- # - item_in_inventory?(item_id)
- #
- # @>Comment condition: # If Party has a Potion in their Inventory
- # if item_in_inventory(1)
- #
- #
- # Command List
- # - item_in_inventory?(item_id)
- #
- #-----------------------------------------------------------------------------
- #==============================================================================
- # ** Scene_Battle
- #------------------------------------------------------------------------------
- # This class performs battle screen processing.
- #==============================================================================
- class Scene_Battle
- #--------------------------------------------------------------------------
- # * Battle Event Setup
- #
- # - Replacement for default XP Battle System setup_battle_event
- # - Any Script Conflicts would most likely come from this method
- #--------------------------------------------------------------------------
- def setup_battle_event
- # If battle event is running
- return if $game_system.battle_interpreter.running?
- # Search for all battle event pages
- for index in 0...$data_troops[@troop_id].pages.size
- # Get event pages
- page = $data_troops[@troop_id].pages[index]
- # Make event conditions possible for reference with c
- c = page.condition
- # This code is mostly default with the addition of "page_condition_valid"
- # Go to next page if no conditions are appointed
- unless c.turn_valid || c.enemy_valid || c.actor_valid || c.switch_valid ||
- page.cond_eval_valid
- next
- end
- # Default code
- # Go to next page if action has been completed
- next if $game_temp.battle_event_flags[index]
- # Confirm turn conditions
- if c.turn_valid
- n, a, b = $game_temp.battle_turn, c.turn_a, c.turn_b
- m = (n < 1 || n < a || n % b != a % b)
- next if (b == 0 && n != a) || (b > 0 && m)
- end
- # Confirm enemy conditions
- if c.enemy_valid
- enemy = $game_troop.enemies[c.enemy_index]
- next if enemy == nil or enemy.hp * 100.0 / enemy.maxhp > c.enemy_hp
- end
- # Confirm actor conditions
- if c.actor_valid
- actor = $game_actors[c.actor_id]
- next if actor == nil or actor.hp * 100.0 / actor.maxhp > c.actor_hp
- end
- # Confirm switch conditions
- if c.switch_valid
- next unless $game_switches[c.switch_id]
- end
- # This small block is also all that was added to the Default code
- # Confirm Page Condition (if Additional Page Condition exists)
- if (cond = page.cond_eval_valid)
- # If running the extra Page Condition returns false (which is default)
- next unless eval(cond)
- end
- # The rest of the code in this method is Default
- # Set up event
- $game_system.battle_interpreter.setup(page.list, 0)
- # If this page span is [battle] or [turn]
- # Set action completed flag
- $game_temp.battle_event_flags[index] = true if page.span <= 1
- return
- end
- end
- #--------------------------------------------------------------------------#
- # ** Custom Commands for Easy Checks for Conditional Switches #
- # #
- # ALL METHODS MUST RETURN TRUE OR FALSE #
- #--------------------------------------------------------------------------#
- #--------------------------------------------------------------------------
- # * Item In Inventory
- # item_id : Item Id from Database
- #
- # Example: 1 is a Potion
- # # If Party has a Potion in the Inventory
- # item_in_inventory?(1)
- #
- # 2 is a High Potion
- # # If Party has a High Potion in the Inventory
- # item_in_inventory?(2)
- #
- # This is an Example Script. It could be accomplished by copying and
- # pasting the one "return true if ..." line of code. I provided this
- # because it makes it easy for us to script easier condition checks
- # for others that may use this script.
- #--------------------------------------------------------------------------
- def item_in_inventory?(item_id)
- # If Item is in Inventory, return True
- return true if $game_party.item_number(item_id) > 0
- # Default
- return false
- end
- end
- #==============================================================================
- # ** Game_Enemy
- #------------------------------------------------------------------------------
- # This class handles enemies. It's used within the Game_Troop class
- # ($game_troop).
- #==============================================================================
- class Game_Enemy
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :escaped # escaped flag
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- $@ || alias_method(:escaped_flag_addition, :escape)
- #--------------------------------------------------------------------------
- # * Escape
- #--------------------------------------------------------------------------
- define_method(:escape){|*s| (@escaped = true) && escaped_flag_addition(*s)}
- end
- #==============================================================================
- # ** Scene_Battle
- #------------------------------------------------------------------------------
- # This class performs battle screen processing.
- #==============================================================================
- class Scene_Battle
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- $@ || alias_method(:escaped_judge, :judge)
- #--------------------------------------------------------------------------
- # * Shortcut
- #--------------------------------------------------------------------------
- define_method(:all_visible_defeated?) { visible_enemies.empty? }
- define_method(:all_hidden_defeated?) { unescaped_enemies.empty? }
- #--------------------------------------------------------------------------
- # * Frame Update (main phase step 1 : action preparation)
- #--------------------------------------------------------------------------
- def judge(*args)
- if all_visible_defeated? #&& !all_hidden_defeated?
- setup_battle_event
- return false if $game_system.battle_interpreter.running?
- end
- escaped_judge(*args)
- end
- #--------------------------------------------------------------------------
- # * unescaped_enemies
- #--------------------------------------------------------------------------
- def unescaped_enemies
- $game_troop.enemies.select {|e| !e.dead? && e.hidden && !e.escaped }
- end
- #--------------------------------------------------------------------------
- # * visible_enemies
- #--------------------------------------------------------------------------
- def visible_enemies
- $game_troop.enemies.select {|e| !e.dead? && !e.hidden }
- end
- end
- #==============================================================================
- # ** Interpreter
- #------------------------------------------------------------------------------
- # This interpreter runs event commands. This class is used within the
- # Game_System class and the Game_Event class.
- #==============================================================================
- class Interpreter
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- $@ || alias_method(:escaped_command_335, :command_335)
- #--------------------------------------------------------------------------
- # * Enemy Appearance
- #--------------------------------------------------------------------------
- def command_335(*args)
- enemy = $game_troop.enemies[@parameters[0]]
- enemy && enemy.escaped = false
- escaped_command_335(*args)
- end
- end
- #==============================================================================
- # ** RPG::Troop::Page
- #------------------------------------------------------------------------------
- #
- #==============================================================================
- class RPG::Troop::Page
- #--------------------------------------------------------------------------
- # * cond_eval_valid
- #--------------------------------------------------------------------------
- def cond_eval_valid
- @cond_eval.nil? ? @cond_eval ||= get_cond_eval : @cond_eval
- end
- #--------------------------------------------------------------------------
- # * Eval Page Conditions
- # - Finds ALL Page Conditions in Comments, then Evaluates them
- #
- # NOTE: Conditions MUST be able to return a Value
- # $foo = "Bar" will not return anything, thus evals to False
- # if $foo == "Bar" will return either True or False
- #
- # This code will check to enusre ALL of the Comment Conditions on a
- # Battle Event Page are met. If you have Two Conditions, both must
- # eval to True for an Event Page to be considered "valid". Each Comment
- # Condition is considered as a Separate Condition. Everything in the
- # Comment Box is evaluated all at once, so you can create temporary
- # variables, Loops, OR statements, etc as long as it is all contained
- # in ONE Comment. IE "if $foo == $bar OR actor_id == 2". Complex
- # scripts may adversely affect performance.
- #
- # This is NEW CODE and should not cause any Script Conflicts.
- #
- #--------------------------------------------------------------------------
- def get_cond_eval
- for i in 0...list.size
- # If Command is First Line of a Comment
- next unless list[i].code == 108
- # Check each Commment if it has "condition:" as String
- condition = $1 if list[i].parameters[0][/^condition:\s*(.*)/i]
- # If Battle Condition in a Comment
- next unless condition
- # Check for more lines in the Comment to Eval all at once
- while (list[i + 1] and [108,408].include?(list[i + 1].code))
- # Add Next Line of Comment (code 408) to Condition to eval
- condition += "\n" + list[i += 1].parameters[0]
- end
- return condition
- end
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement