Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Swap Actor (VXACE)
- # V 1.00
- # by Mithran
- # forums.rpgmakerweb.com
- %Q(
- INSTRUCTIONS
- This simple script adds an easy way to simulate "designation by variable" on all
- actor functions, including in conditional branches.
- Simply create a single "dummy" actor in the database and set its ID below.
- Whenever this actor is targeted by an event, it will instead switch the target to
- the index held by the designated variable.
- For example, if SWAP_ACTOR_DESIGNATION_VARIABLE_ID = 2, then whatever the current
- value of game variable 2 will be the index of the targeted actor.(*)
- Special Values in the designation variable -
- (*) A value of 0 will make the event target the whole party if the option below
- is set to true, and providing the event command will allow targeting more
- than one actor. For example, getting the value for the conditional branch
- will only ever target one actor.
- If the option is set to false, this will only target the party leader.
- (*) Values of less than 0 will be assumed as the party leader and count backward.
- eg., -1 is the party leader, -2 is the second person in the party, and so on.
- (*) Values equal to the ID of the dummy actor will be ignored.
- )
- SWAP_ACTOR_ID = 11 # the id of the actor that should be swapped whenever encountered
- SWAP_ACTOR_DESIGNATION_VARIABLE_ID = 105 # the id of the variable which controls the id of
- # the actor to be swapped in
- SWAP_ACTOR_ZERO_TARGET_PARTY = false # if set to true, a value of 0 in the
- # varialbe will cause the event command to target the whole party
- # if set to false, the action will be sent to the party leader in cases
- # where the variable value is 0
- # note that some actions, such as getting a value for conditional branch, can
- # only target one actor and therefore will always only use the leader
- class Game_Interpreter
- alias iterate_actor_id_noswapactor iterate_actor_id
- def iterate_actor_id(param)
- if param == SWAP_ACTOR_ID
- var = $game_variables[SWAP_ACTOR_DESIGNATION_VARIABLE_ID]
- if var == 0 and !SWAP_ACTOR_ZERO_TARGET_PARTY
- var = $game_party.leader_id
- elsif var < 0
- return iterate_actor_index(-var - 1) { |a| yield a }
- end
- return if var == SWAP_ACTOR_ID # insulation against dummy actor being in party
- iterate_actor_id_noswapactor(var) { |a| yield a }
- else
- iterate_actor_id_noswapactor(param) { |a| yield a }
- end
- end
- alias command_129_swapactor command_129
- def command_129 # add or remove actor
- if @params[0] == SWAP_ACTOR_ID
- @params = @params.clone
- var = $game_variables[SWAP_ACTOR_DESIGNATION_VARIABLE_ID]
- return if var == SWAP_ACTOR_ID # never add dummy actor to party
- if var == 0
- @params[0] = $game_party.leader_id
- else
- @params[0] = var
- end
- end
- command_129_swapactor
- end
- end
- class Game_Actors
- alias get_data_swapactor []
- def [](actor_id)
- if actor_id == SWAP_ACTOR_ID
- actor_id = $game_variables[SWAP_ACTOR_DESIGNATION_VARIABLE_ID]
- return DummyParty if actor_id == 0 and SWAP_ACTOR_ZERO_TARGET_PARTY
- actor_id = $game_party.leader_id if actor_id == 0 if $game_party
- actor_id = $game_party.ordered_ids[-actor_id - 1] if actor_id < 0 if $game_party
- actor_id ||= 0
- return nil if actor_id == SWAP_ACTOR_ID
- end
- get_data_swapactor(actor_id)
- end
- end
- class Game_Party
- def leader_id
- @actors[0].nil? ? 0 : @actors[0]
- end
- def ordered_ids
- @actors
- end
- end
- module DummyParty
- class << self
- undef :name
- end
- def self.method_missing(symb, *args)
- value = nil
- $game_party.members.each { |m| value ||= m.send(symb, *args) }
- value
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement