modern_algebra

[VXA] Lock Actor in Formation

Feb 2nd, 2013
220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. #    Lock Actor in Formation
  3. #    Version: 1.0.0
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: 2 February 2013
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #    
  9. #    This script allows you to lock an actor in their position in the party
  10. #   and prevents the player from moving the actor around. It can be useful
  11. #   for times when you want to ensure that a particular actor is in the active
  12. #   party, such as the main character.
  13. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  14. #  Instructions:
  15. #    
  16. #    Paste this script into its own slot in the Script Editor, above Main but
  17. #   below Materials.
  18. #
  19. #    An icon will show up on a locked actor's status to indicate that he or
  20. #   she is locked and cannot be moved through the Formation command. To specify
  21. #   which icon is shown and where, go to the editable region beginning at line
  22. #   68. If you don't want any icon shown, set the index to 0.
  23. #
  24. #    This script is operated through commands called through an evented Script
  25. #   command. The two operative codes are:
  26. #
  27. #        lock_actor_formation(actor_id)
  28. #        unlock_actor_formation(actor_id)
  29. #
  30. #   Where: actor_id is replaced with the ID of the Actor you want to lock.
  31. #   The lock command prevents the player from manually adjusting the position
  32. #   of the actor in the party, while the unlock command permits reverses that
  33. #   and once again allows the player to adjust the actor's position. Neither
  34. #   code works unless the actor is in the party.
  35. #
  36. #    Additionally, if you want to specify that the actor be moved to a
  37. #   particular index before locking him or her (for instance, to ensure that
  38. #   he or she is in the active party), you can do that by specifying the index
  39. #   you want him or her moved to right after the ID, like so:
  40. #
  41. #        lock_actor_formation(actor_id, index)
  42. #------------------------------------------------------------------------------
  43. #    EXAMPLES:
  44. #
  45. #        lock_actor_formation(4)
  46. #            # Actor 4 is locked in his or her current position in the party
  47. #
  48. #        lock_actor_formation(1, 0)
  49. #            # Actor 1 is locked in as leader of the party
  50. #
  51. #        unlock_actor_formation(9)
  52. #            # Actor 9 is unlocked
  53. #==============================================================================
  54.  
  55. $imported = {} unless $imported
  56. $imported[:MA_LockActorInFormation] = true
  57.  
  58. #==============================================================================
  59. # *** MALAF_Window_DrawFormIcon
  60. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  61. #  This module mixes in to Window_MenuStatus to draw a formation icon. It is
  62. # drawn this way to (hopefully) maximize compatibility with menu scripts that
  63. # change the menu status window. It will only work if the different status
  64. # window operates in substantially the same way, however.
  65. #==============================================================================
  66.  
  67. module MALAF_Window_DrawFormIcon
  68.   #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  69.   #    BEGIN Editable Region
  70.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  71.   LOCK_ICON_INDEX = 242 # Index of icon shown when actor is locked.
  72.   LOCK_ICON_X = 328     # Icon's X-coordinate - added to the item_rect's x
  73.   LOCK_ICON_Y = 0       # Icon's Y-coordinate - added to the item_rect's y
  74.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  75.   #    END Editable Region
  76.   #//////////////////////////////////////////////////////////////////////////
  77.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78.   # * Public Instance Variables
  79.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80.   attr_accessor :malaf_formation_select # Boolean checking whether formation
  81.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82.   # * Draw Item
  83.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  84.   def draw_item(index, *args)
  85.     super(index, *args)                              # Call original method
  86.     actor = $game_party.members[index]               # Get Actor
  87.     rect = item_rect(index)                          # Get Position
  88.     malaf_draw_formation_icon(actor, rect.x, rect.y) # Draw Formation Status
  89.   end
  90.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91.   # * Draw Formation Icon
  92.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93.   def malaf_draw_formation_icon(actor, x, y)
  94.     draw_icon(LOCK_ICON_INDEX, x + LOCK_ICON_X, y + LOCK_ICON_Y) if actor.formation_locked
  95.   end
  96.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97.   # * Current Item Enabled?
  98.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  99.   def current_item_enabled?(*args)
  100.     if @malaf_formation_select
  101.       actor = $game_party.members[index]
  102.       return false if actor && actor.formation_locked
  103.     end
  104.     super(*args)
  105.   end
  106. end
  107.  
  108. #==============================================================================
  109. # ** Game_Actor
  110. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  111. #  Summary of Changes:
  112. #    aliased method - setup
  113. #    new attr_accessor - formation_locked
  114. #==============================================================================
  115.  
  116. class Game_Actor
  117.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118.   # * Public Instance Variables
  119.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120.   attr_accessor :formation_locked # Boolean discerning whether actor locked
  121.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122.   # * Setup
  123.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124.   alias malaf_setup_4hn6 setup
  125.   def setup(*args, &block)
  126.     @formation_locked = false
  127.     malaf_setup_4hn6(*args, &block) # Call Original Method
  128.   end
  129. end
  130.  
  131. #==============================================================================
  132. # ** Game_Party
  133. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  134. #  Summary of Changes:
  135. #    new method - malaf_insert_actor
  136. #==============================================================================
  137.  
  138. class Game_Party
  139.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140.   # * Insert Actor in Formation
  141.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142.   def malaf_insert_actor(actor_id, new_index)
  143.     if @actors.include?(actor_id)
  144.       @actors.delete(actor_id)
  145.       new_index = @actors.size - 1 if new_index >= @actors.size
  146.       @actors.insert(new_index, actor_id)
  147.       $game_player.refresh
  148.     end
  149.   end
  150. end
  151.  
  152. #==============================================================================
  153. # ** Game_Interpreter
  154. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  155. #  Summary of Changes:
  156. #    new methods - lock_actor_formation; unlock_actor_formation
  157. #==============================================================================
  158.  
  159. class Game_Interpreter
  160.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161.   # * Formation Lock
  162.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163.   def lock_actor_formation(actor_id, index = nil)
  164.     $game_actors[actor_id].formation_locked = true
  165.     $game_party.malaf_insert_actor(actor_id, index) if index.is_a?(Integer)
  166.   end
  167.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168.   # * Formation Lock
  169.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170.   def unlock_actor_formation(actor_id, index = nil)
  171.     $game_actors[actor_id].formation_locked = false
  172.     $game_party.malaf_insert_actor(actor_id, index) if index.is_a?(Integer)
  173.   end
  174. end
  175.  
  176. #==============================================================================
  177. # ** Scene_Menu
  178. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  179. #  Summary of Changes:
  180. #    aliased method - on_formation_ok
  181. #==============================================================================
  182.  
  183. class Scene_Menu
  184.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185.   # * Create Status Window
  186.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  187.   alias malaf_creatstatswin_3mb5 create_status_window
  188.   def create_status_window(*args)
  189.     malaf_creatstatswin_3mb5(*args) # Call original method
  190.     if @status_window
  191.       @status_window.extend(MALAF_Window_DrawFormIcon) # Mix in module
  192.       @status_window.refresh
  193.     end
  194.   end
  195.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  196.   # * [Formation] Command
  197.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  198.   alias malaf_commndformt_5vc4 command_formation
  199.   def command_formation
  200.     @status_window.malaf_formation_select = true if @status_window
  201.     malaf_commndformt_5vc4
  202.   end
  203.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  204.   # * Cancel Formation Select
  205.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  206.   alias malaf_onfrmtncanc_8zz4 on_formation_cancel
  207.   def on_formation_cancel(*args)
  208.     malaf_onfrmtncanc_8zz4(*args) # Call original method
  209.     @status_window.malaf_formation_select = false if @status_window && @status_window.index == -1
  210.   end
  211. end
RAW Paste Data