Advertisement
Mithran

Swap Actor

Aug 16th, 2012
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. # Swap Actor (VXACE)
  2. # V 1.00
  3. # by Mithran
  4. # forums.rpgmakerweb.com
  5.  
  6. %Q(
  7. INSTRUCTIONS
  8.  
  9. This simple script adds an easy way to simulate "designation by variable" on all
  10. actor functions, including in conditional branches.
  11.  
  12. Simply create a single "dummy" actor in the database and set its ID below.
  13.  
  14. Whenever this actor is targeted by an event, it will instead switch the target to
  15. the index held by the designated variable.
  16.  
  17. For example, if SWAP_ACTOR_DESIGNATION_VARIABLE_ID = 2, then whatever the current
  18. value of game variable 2 will be the index of the targeted actor.(*)
  19.  
  20. Special Values in the designation variable -
  21.  
  22. (*) A value of 0 will make the event target the whole party if the option below
  23. is set to true, and providing the event command will allow targeting more
  24. than one actor. For example, getting the value for the conditional branch
  25. will only ever target one actor.
  26. If the option is set to false, this will only target the party leader.
  27.  
  28. (*) Values of less than 0 will be assumed as the party leader and count backward.
  29. eg., -1 is the party leader, -2 is the second person in the party, and so on.
  30.  
  31. (*) Values equal to the ID of the dummy actor will be ignored.
  32. )
  33.  
  34. SWAP_ACTOR_ID = 11 # the id of the actor that should be swapped whenever encountered
  35.  
  36. SWAP_ACTOR_DESIGNATION_VARIABLE_ID = 105 # the id of the variable which controls the id of
  37. # the actor to be swapped in
  38.  
  39. SWAP_ACTOR_ZERO_TARGET_PARTY = false # if set to true, a value of 0 in the
  40. # varialbe will cause the event command to target the whole party
  41. # if set to false, the action will be sent to the party leader in cases
  42. # where the variable value is 0
  43. # note that some actions, such as getting a value for conditional branch, can
  44. # only target one actor and therefore will always only use the leader
  45.  
  46.  
  47. class Game_Interpreter
  48.  
  49. alias iterate_actor_id_noswapactor iterate_actor_id
  50. def iterate_actor_id(param)
  51. if param == SWAP_ACTOR_ID
  52. var = $game_variables[SWAP_ACTOR_DESIGNATION_VARIABLE_ID]
  53. if var == 0 and !SWAP_ACTOR_ZERO_TARGET_PARTY
  54. var = $game_party.leader_id
  55. elsif var < 0
  56. return iterate_actor_index(-var - 1) { |a| yield a }
  57. end
  58. return if var == SWAP_ACTOR_ID # insulation against dummy actor being in party
  59. iterate_actor_id_noswapactor(var) { |a| yield a }
  60. else
  61. iterate_actor_id_noswapactor(param) { |a| yield a }
  62. end
  63. end
  64.  
  65. alias command_129_swapactor command_129
  66. def command_129 # add or remove actor
  67. if @params[0] == SWAP_ACTOR_ID
  68. @params = @params.clone
  69. var = $game_variables[SWAP_ACTOR_DESIGNATION_VARIABLE_ID]
  70. return if var == SWAP_ACTOR_ID # never add dummy actor to party
  71. if var == 0
  72. @params[0] = $game_party.leader_id
  73. else
  74. @params[0] = var
  75. end
  76. end
  77. command_129_swapactor
  78. end
  79. end
  80.  
  81. class Game_Actors
  82. alias get_data_swapactor []
  83. def [](actor_id)
  84. if actor_id == SWAP_ACTOR_ID
  85. actor_id = $game_variables[SWAP_ACTOR_DESIGNATION_VARIABLE_ID]
  86. return DummyParty if actor_id == 0 and SWAP_ACTOR_ZERO_TARGET_PARTY
  87. actor_id = $game_party.leader_id if actor_id == 0 if $game_party
  88. actor_id = $game_party.ordered_ids[-actor_id - 1] if actor_id < 0 if $game_party
  89. actor_id ||= 0
  90. return nil if actor_id == SWAP_ACTOR_ID
  91. end
  92. get_data_swapactor(actor_id)
  93. end
  94.  
  95. end
  96.  
  97. class Game_Party
  98. def leader_id
  99. @actors[0].nil? ? 0 : @actors[0]
  100. end
  101.  
  102. def ordered_ids
  103. @actors
  104. end
  105.  
  106. end
  107.  
  108. module DummyParty
  109. class << self
  110. undef :name
  111. end
  112.  
  113. def self.method_missing(symb, *args)
  114. value = nil
  115. $game_party.members.each { |m| value ||= m.send(symb, *args) }
  116. value
  117. end
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement