Advertisement
TheSixth

Follower Arranger by Sixth

Feb 10th, 2016
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 25.13 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Follower Arranger
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.0
  6. # * Updated: 11/02/2016
  7. # * Requires: --------
  8. #-------------------------------------------------------------------------------
  9. # * < Change Log >
  10. #-------------------------------------------------------------------------------
  11. # * Version 1.0 (11/02/2016)
  12. #   - Initial release.
  13. #-------------------------------------------------------------------------------
  14. # * < Description >
  15. #-------------------------------------------------------------------------------
  16. # * This script will let you change how many followers are shown, which ones,
  17. #   and in what order they appear on the map. These changes are purely for the
  18. #   visuals of the map, the battle formation itself will NOT change!
  19. # * Various follower order sorting methods are possible to do too.
  20. # * You can change the follower settings anytime during the game also!
  21. #-------------------------------------------------------------------------------
  22. # * < Script Calls >
  23. #-------------------------------------------------------------------------------
  24. # * To hide, show, or toggle a follower, or to set a specific order for them,
  25. #   you can use the following script call:
  26. #
  27. #     set_follower_visibility(index,state,sort,reverse)
  28. #
  29. #   The index is the party member's index. Note that from now on, the party
  30. #   member indexes and follower indexes are NOT the same!
  31. #   The index can be any number between 1 and the maximum size of your party
  32. #   minus 1! So, if your party got 5 members, the index can be any integer
  33. #   number between 1 and 4. These numbers represent the member's index in the
  34. #   party (so NOT the index of a follower visible on the screen!).
  35. #
  36. #   The state can be one of the following:
  37. #   :show = Shows the selected party member's follower graphic on the map.
  38. #   :hide = Hides the selected party member's follower graphic on the map.
  39. #   :toggle = Toggles the selected party member's follower graphic on the map.
  40. #             If the follower is shown, it will be hidden, and if it is hidden,
  41. #             it will be shown.
  42. #   :set = If this is used, the index argument (explained above) must be an
  43. #          array instead of an integer number. That array must contain all
  44. #          party member indexes you want to show on the map with a follower
  45. #          graphic. If a party member's index is not in the array, it will be
  46. #          hidden, and if it is in the array, it will be shown after the script
  47. #          call, regardless of the current state of the follower graphic.
  48. #          In short, this can set the shown members directly and with your
  49. #          specific order.
  50. #
  51. #   The sort argument is used if you want to sort your followers shown on the
  52. #   map in a specific order. It is an optional argument!
  53. #   The sort argument can be one of the following:
  54. #   :sort = Sorts the follower graphics based on actor ID.
  55. #   :reverse = Reverses the current order.
  56. #   :level = Sorts the follower graphics based on their actor's level.
  57. #            The lowest leveled will be the 1st follower, followed by higher
  58. #            leveled actors.
  59. #   It can also be set to an integer number between 0 and 7. In this case,
  60. #   the follower graphics will be sorted based on their actor's specified param
  61. #   values. The one with the lowest param value will be the 1st follower,
  62. #   followed by the ones with higher params in order.
  63. #   0 = HP, 1 = MP, 2 = ATK, 3 = DEF, 4 = MAT, 5 = MDF, 6 = AGI, 7 = LUK
  64. #
  65. #   The reverse argument is an optional one too. It will reverse the follower
  66. #   graphics' order immediately after the change you made with the script call.
  67. #   It happens after the sorting process (if you used a sort argument) or after
  68. #   the change of visibility for the follower.
  69. #   If you want to use this feature, just set it to true in your script calls,
  70. #   if not, you can omit it entirely.
  71. #
  72. #   NOTE:
  73. #   If you enter a higher number than the number of party members in your party
  74. #   minus one for the index argument, the script call will be diregarded, and
  75. #   no changes will be made at all!
  76. #
  77. #   Some examples are shown at the end of this section. I wanted to make an
  78. #   example with real party setups, so that it is understood easier.
  79. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  80. # * To sort the order of follower graphics on the map based on different
  81. #   factors, you can use the following script call:
  82. #
  83. #     order_followers(type,reverse)
  84. #
  85. #   The type can be one of the following:
  86. #   :sort, :reverse, :level, and any integer number between 0 and 7 (params).
  87. #   It works the same way as the optional sort argument in the previous script
  88. #   call, so check the details there!
  89. #
  90. #   The reverse argument is optional here as well.
  91. #   If used, it will reverse the order of followers immediately after the
  92. #   sorting. Set this to true if you want to use it, otherwise, you can omit it.
  93. #
  94. #   Some examples are shown at the end of this section. I wanted to make an
  95. #   example with real party setups, so that it is understood easier.
  96. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  97. # * You can also show, hide and toggle follower graphics based on their actor's
  98. #   ID if you want. Use this script call for that:
  99. #  
  100. #     set_followers_by_actor(id,state,sort,reverse)
  101. #
  102. #   So, instead of using party member indexes, you can use actor IDs directly
  103. #   to, for example, hide the follower graphic of Ernest on the map, regardless
  104. #   of Ernest's party member index.
  105. #
  106. #   Every argument here is the same as in the first script call, but instead of
  107. #   entering party member indexes, you enter actor IDs here for the 1st
  108. #   argument.
  109. #
  110. #   NOTE:
  111. #   If the actor is not currently in the party, no change will be made!
  112. #
  113. #   Some examples are shown at the end of this section. I wanted to make an
  114. #   example with real party setups, so that it is understood easier.
  115. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  116. # * And finally, you can show, hide or toggle the visibility of all of the
  117. #   follower graphics at once with the following script call:
  118. #
  119. #     set_all_followers(state,type,sort,reverse)
  120. #
  121. #   The state argument can be:
  122. #   :show, :hide, :toggle
  123. #   It works the same way as the other state arguments mentioned in other script
  124. #   calls above.
  125. #
  126. #   The type argument decides if you only want the script call to change your
  127. #   battle members' follower graphics or your entire party (including non-battle
  128. #   members). It can be:
  129. #   :battle, :all
  130. #   Should be obvious what they do.
  131. #   You can omit this argument, in which case it will default to :battle.
  132. #
  133. #   The sort and reverse arguments are optional as well, and they do the same
  134. #   as in every other script call above.
  135. #
  136. #   Some examples are shown at the end of this section. I wanted to make an
  137. #   example with real party setups, so that it is understood easier.
  138. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  139. # * Let's see some examples with the following initial party:
  140. #
  141. #    Member |   Member   | Actor  | Member | Follower | In Battle |   Follower  |
  142. #    Index  |    Name    |   ID   |  Level |  Index   |   Party?  |  Visibility |
  143. #   ---------------------------------------------------------------------------
  144. #       0   |    Eric    |   1    |   88   |    0     |    Yes    | Always shown!
  145. #   ---------------------------------------------------------------------------
  146. #       1   |   Natalie  |   2    |   15   |    1     |    Yes    | Shown
  147. #   ---------------------------------------------------------------------------
  148. #       2   |   Terence  |   3    |   34   |    2     |    Yes    | Shown
  149. #   ---------------------------------------------------------------------------
  150. #       3   |   Earnest  |   4    |   96   |    3     |    Yes    | Shown
  151. #   ---------------------------------------------------------------------------
  152. #       4   |    Ryoma   |   5    |   75   |    -     |    No     | Hidden
  153. #   ---------------------------------------------------------------------------
  154. #       5   |   Brenda   |   6    |   12   |    -     |    No     | Hidden
  155. #   ---------------------------------------------------------------------------
  156. #
  157. #   This initial party is a completely normal party, can be done with the
  158. #   default engine too. Note that hidden followers do not have a follower index!
  159. #   But let's see what happens when you use some clever script calls!
  160. #
  161. #     set_follower_visibility(2,:hide)
  162. #   This would hide Terence's follower graphic.
  163. #   After this script call, the following party members would be shown on the
  164. #   map (in the order listed here):
  165. #   Eric -> Natalie -> Earnest
  166. #
  167. #   The table now looks like this:
  168. #
  169. #    Member |   Member   | Actor  | Member | Follower | In Battle |   Follower  |
  170. #    Index  |    Name    |   ID   |  Level |  Index   |   Party?  |  Visibility |
  171. #   ---------------------------------------------------------------------------
  172. #       0   |    Eric    |   1    |   88   |    0     |    Yes    | Always shown!
  173. #   ---------------------------------------------------------------------------
  174. #       1   |   Natalie  |   2    |   15   |    1     |    Yes    | Shown
  175. #   ---------------------------------------------------------------------------
  176. #       2   |   Terence  |   3    |   34   |    -     |    Yes    | Hidden
  177. #   ---------------------------------------------------------------------------
  178. #       3   |   Earnest  |   4    |   96   |    2     |    Yes    | Shown
  179. #   ---------------------------------------------------------------------------
  180. #       4   |    Ryoma   |   5    |   75   |    -     |    No     | Hidden
  181. #   ---------------------------------------------------------------------------
  182. #       5   |   Brenda   |   6    |   12   |    -     |    No     | Hidden
  183. #   ---------------------------------------------------------------------------
  184. #
  185. #   Let's use another script call!
  186. #
  187. #     set_followers_by_actor(5,:toggle,:level)
  188. #   This will show Ryoma's follower graphic, because he was hidden before,
  189. #   regardless of his member index in the party, and regardless if he is in the
  190. #   battle party or not.
  191. #   Now, the shown followers are:
  192. #   Eric -> Natalie -> Earnest -> Ryoma
  193. #   But because we also added a sort argument (:level), the follower graphics
  194. #   will be sorted by their actor's level, from the lowest to the highest.
  195. #   This means, we will get this order:
  196. #   Eric -> Natalie -> Ryoma -> Earnest
  197. #
  198. #   The table now looks this way:
  199. #
  200. #    Member |   Member   | Actor  | Member | Follower | In Battle |   Follower  |
  201. #    Index  |    Name    |   ID   |  Level |  Index   |   Party?  |  Visibility |
  202. #   ---------------------------------------------------------------------------
  203. #       0   |    Eric    |   1    |   88   |    0     |    Yes    | Always shown!
  204. #   ---------------------------------------------------------------------------
  205. #       1   |   Natalie  |   2    |   15   |    1     |    Yes    | Shown
  206. #   ---------------------------------------------------------------------------
  207. #       2   |   Terence  |   3    |   34   |    -     |    Yes    | Hidden
  208. #   ---------------------------------------------------------------------------
  209. #       3   |   Earnest  |   4    |   96   |    3     |    Yes    | Shown
  210. #   ---------------------------------------------------------------------------
  211. #       4   |    Ryoma   |   5    |   75   |    2     |    No     | Shown
  212. #   ---------------------------------------------------------------------------
  213. #       5   |   Brenda   |   6    |   12   |    -     |    No     | Hidden
  214. #   ---------------------------------------------------------------------------
  215. #
  216. #   And now let's use yet another script call:
  217. #
  218. #     set_all_followers(:toggle)
  219. #   This will toggle the visibility of all of the battle members in the party.
  220. #   That means, the follower graphics show will be these (in this order):
  221. #   Eric -> Ryoma -> Terence
  222. #   So, Natalie and Earnest were shown before the script call, that is why they
  223. #   are hidden now, and Terence were hidden before, so he will be shown now.
  224. #   Because Ryoma is not in the battle party, his follower visibility state will
  225. #   remain whatever it was before, so he will still show up.
  226. #   And because Ryoma was shown already before Terence appeared, Terence will be
  227. #   put at the end of the follower graphics.
  228. #
  229. #   The table now is:
  230. #
  231. #    Member |   Member   | Actor  | Member | Follower | In Battle |   Follower  |
  232. #    Index  |    Name    |   ID   |  Level |  Index   |   Party?  |  Visibility |
  233. #   ---------------------------------------------------------------------------
  234. #       0   |    Eric    |   1    |   88   |    0     |    Yes    | Always shown!
  235. #   ---------------------------------------------------------------------------
  236. #       1   |   Natalie  |   2    |   15   |    -     |    Yes    | Hidden
  237. #   ---------------------------------------------------------------------------
  238. #       2   |   Terence  |   3    |   34   |    2     |    Yes    | Shown
  239. #   ---------------------------------------------------------------------------
  240. #       3   |   Earnest  |   4    |   96   |    -     |    Yes    | Hidden
  241. #   ---------------------------------------------------------------------------
  242. #       4   |    Ryoma   |   5    |   75   |    1     |    No     | Shown
  243. #   ---------------------------------------------------------------------------
  244. #       5   |   Brenda   |   6    |   12   |    -     |    No     | Hidden
  245. #   ---------------------------------------------------------------------------
  246. #  
  247. #   And a last script call!
  248. #
  249. #     order_followers(:sort)
  250. #   This will sort the follower graphics based on their actor's ID.
  251. #   The followers now are (in this order):
  252. #   Eric -> Terence -> Ryoma
  253. #
  254. #   The table looks like thsi now:
  255. #
  256. #    Member |   Member   | Actor  | Member | Follower | In Battle |   Follower  |
  257. #    Index  |    Name    |   ID   |  Level |  Index   |   Party?  |  Visibility |
  258. #   ---------------------------------------------------------------------------
  259. #       0   |    Eric    |   1    |   88   |    0     |    Yes    | Always shown!
  260. #   ---------------------------------------------------------------------------
  261. #       1   |   Natalie  |   2    |   15   |    -     |    Yes    | Hidden
  262. #   ---------------------------------------------------------------------------
  263. #       2   |   Terence  |   3    |   34   |    1     |    Yes    | Shown
  264. #   ---------------------------------------------------------------------------
  265. #       3   |   Earnest  |   4    |   96   |    -     |    Yes    | Hidden
  266. #   ---------------------------------------------------------------------------
  267. #       4   |    Ryoma   |   5    |   75   |    2     |    No     | Shown
  268. #   ---------------------------------------------------------------------------
  269. #       5   |   Brenda   |   6    |   12   |    -     |    No     | Hidden
  270. #   ---------------------------------------------------------------------------
  271. #
  272. #   Alright, enough of the script calls, right?
  273. #   Lets try something else...
  274. #  
  275. #   We will change the party formatiion in the menu.
  276. #   Terence will be exchanged by Brenda, and Earnest will take Natalie's place.
  277. #   The followers shown now are (in this order):
  278. #   Eric -> Brenda -> Ryoma
  279. #   You see, while follower graphic changes do NOT affect the party formation,
  280. #   the opposite is NOT true. If you change the party formation in the menu,
  281. #   that will be reflected in the shown follower graphics.
  282. #   Neither Earnest or Natalie were shown as a follower before the change, so
  283. #   exchanging their position won't change anything in the follower graphics.
  284. #   But because Terence was shown, and because we exchanged him with Brenda,
  285. #   Terence will exchange the follower visibility state with Brenda as well, so
  286. #   Terence will be hidden, and Brenda will be shown.
  287. #
  288. #   The table after the formation change:
  289. #
  290. #    Member |   Member   | Actor  | Member | Follower | In Battle |   Follower  |
  291. #    Index  |    Name    |   ID   |  Level |  Index   |   Party?  |  Visibility |
  292. #   ---------------------------------------------------------------------------
  293. #       0   |    Eric    |   1    |   88   |    0     |    Yes    | Always shown!
  294. #   ---------------------------------------------------------------------------
  295. #       1   |   Earnest  |   4    |   96   |    -     |    Yes    | Hidden
  296. #   ---------------------------------------------------------------------------
  297. #       2   |   Brenda   |   6    |   12   |    1     |    Yes    | Shown
  298. #   ---------------------------------------------------------------------------
  299. #       3   |   Natalie  |   2    |   15   |    -     |    Yes    | Hidden
  300. #   ---------------------------------------------------------------------------
  301. #       4   |    Ryoma   |   5    |   75   |    2     |    No     | Shown
  302. #   ---------------------------------------------------------------------------
  303. #       5   |   Terence  |   3    |   34   |    -     |    No     | Hidden
  304. #   ---------------------------------------------------------------------------
  305. #
  306. #   And this concludes the long series of examples, phew!
  307. #
  308. #   Final note:
  309. #   Every time you change follower graphics, the followers will be re-spawn at
  310. #   the same position the player is. They will NOT stay at the same position
  311. #   as the previous followers were before the change!
  312. #-------------------------------------------------------------------------------
  313. # * < Installation >
  314. #-------------------------------------------------------------------------------
  315. # * Place this script below Materials but above Main!
  316. #-------------------------------------------------------------------------------
  317. # * < Compatibility Info >
  318. #-------------------------------------------------------------------------------
  319. # * No known incompatibilities.
  320. #-------------------------------------------------------------------------------
  321. # * < Known Issues >
  322. #-------------------------------------------------------------------------------
  323. # * No known issues.
  324. #-------------------------------------------------------------------------------
  325. # * < Terms of Use >
  326. #-------------------------------------------------------------------------------
  327. # * Free to use for whatever purposes you want.
  328. # * Credit me (Sixth) in your game, pretty please! :P
  329. # * Posting modified versions of this script is allowed as long as you notice me
  330. #   about it with a link to it!
  331. #===============================================================================
  332. $imported = {} if $imported.nil?
  333. $imported["SixthFollowerArranger"] = true
  334. #===============================================================================
  335. # Settings:
  336. #===============================================================================
  337. module FollowerArranger
  338.   #-----------------------------------------------------------------------------
  339.   # Initial Follower Settings
  340.   #-----------------------------------------------------------------------------
  341.   # Initial follower setting.
  342.   # Shows 3 followers after the player.
  343.   # The numbers in the array are the indexes of the party members.
  344.   # 1 means the 2nd party member, 2 means the 3rd party member, and so on.
  345.   # The 1st party member is always the player itself, and the visibility of
  346.   # the player can NOT be modified by this script! You can do that easily with
  347.   # the default event commands anyway.
  348.   #
  349.   # This also sets the initial order of appearance for the followers.
  350.   # If you remove 1 from the array, for example, the second party member will
  351.   # not show up as a follower, but the 3rd and 4th party member will.
  352.   # Now, if you put the 1 at the end of the array, the 3 party members would
  353.   # show up in the same order as in the array, so the 3rd party member would be
  354.   # the 1st follower, the 4th member would be the 2nd follower and the
  355.   # 2nd member would be the 3rd follower on the screen.
  356.   #
  357.   # Note that the order of followers is NOT related to the real party member
  358.   # order! Every battle and menu related order stays unchanged, meaning these
  359.   # changes to the followers only affect the visuals on the map scene!
  360.   #-----------------------------------------------------------------------------
  361.   Initial = [1,2,3] # Default: [1,2,3]
  362.  
  363. end
  364. #===============================================================================
  365. # End of settings! Editing anything below may lead to... you know it, right? o.o
  366. #===============================================================================
  367.  
  368. class Game_Interpreter
  369.  
  370.   def order_followers(type=:sort,reverse=false,upd=true)
  371.     case type
  372.     when Integer
  373.       $game_system.visible_followers.sort_by! {|i| $game_party.members[i].param(type)}
  374.       $game_player.followers.need_refresh = true if upd && !reverse
  375.     when Array
  376.       $game_system.visible_followers = type
  377.       $game_player.followers.need_refresh = true if upd && !reverse
  378.     when :sort
  379.       $game_system.visible_followers.sort!
  380.       $game_player.followers.need_refresh = true if upd && !reverse
  381.     when :reverse
  382.       $game_system.visible_followers.reverse!
  383.       $game_player.followers.need_refresh = true if upd && !reverse
  384.     when :level
  385.       $game_system.visible_followers.sort_by! {|i| $game_party.members[i].level}
  386.       $game_player.followers.need_refresh = true if upd && !reverse
  387.     end
  388.     $game_system.visible_followers.reverse! if reverse
  389.     $game_player.followers.need_refresh = true if upd && reverse
  390.   end
  391.  
  392.   def set_follower_visibility(index,state,sort=nil,reverse=false,upd=true)
  393.     return if index > $game_party.all_members.size - 1
  394.     case state
  395.     when :show
  396.       return if $game_system.visible_followers.include?(index)
  397.       $game_system.visible_followers << index
  398.       order_followers(sort,reverse,false) if sort
  399.       $game_player.followers.need_refresh = true if upd
  400.     when :hide
  401.       $game_system.visible_followers.delete(index)
  402.       order_followers(sort,reverse,false) if sort
  403.       $game_player.followers.need_refresh = true if upd
  404.     when :toggle
  405.       if $game_system.visible_followers.include?(index)
  406.         $game_system.visible_followers.delete(index)
  407.         order_followers(sort,reverse,false) if sort
  408.         $game_player.followers.need_refresh = true if upd
  409.       else
  410.         $game_system.visible_followers << index
  411.         order_followers(sort,reverse,false) if sort
  412.         $game_player.followers.need_refresh = true if upd
  413.       end
  414.     when :set
  415.       $game_system.visible_followers = index
  416.       $game_player.followers.need_refresh = true if upd
  417.     end
  418.   end
  419.  
  420.   def set_followers_by_actor(id,state,sort=nil,reverse=false)
  421.     return if id == 0
  422.     index = $game_actors[id].index
  423.     return if index.nil? || index == 0
  424.     set_follower_visibility(index,state,sort,reverse)
  425.   end
  426.    
  427.   def set_all_followers(state,type=:battle,sort=nil,reverse=false)
  428.     case type
  429.     when :battle
  430.       m = $game_party.max_battle_members
  431.     when :all
  432.       m = $game_party.all_members.size
  433.     end
  434.     (1...m).each do |i|
  435.       set_follower_visibility(i,state,sort,reverse,false)
  436.     end
  437.     $game_player.followers.need_refresh = true
  438.   end
  439.  
  440. end
  441.  
  442. class Game_System
  443.  
  444.   def visible_followers
  445.     @visible_followers = FollowerArranger::Initial if @visible_followers.nil?
  446.     return @visible_followers
  447.   end
  448.  
  449. end
  450.  
  451. class Game_Player < Game_Character
  452.  
  453.   def reset_followers
  454.     @followers = Game_Followers.new(self)
  455.     @followers.each {|f| f.moveto(@x, @y); f.refresh; f.update}
  456.   end
  457.  
  458. end
  459.  
  460. class Game_Follower < Game_Character
  461.  
  462.   def actor
  463.     return nil if @member_index.nil?
  464.     $game_party.all_members[@member_index]
  465.   end
  466.  
  467. end
  468.  
  469. class Game_Followers
  470.  
  471.   attr_accessor :need_refresh
  472.  
  473.   def initialize(leader)
  474.     @visible = $data_system.opt_followers
  475.     @gathering = false
  476.     @data = []
  477.     first_f = $game_system.visible_followers[0]
  478.     @data.push(Game_Follower.new(first_f, leader))
  479.     $game_system.visible_followers.each_with_index do |index,i|
  480.       next if i == 0
  481.       @data.push(Game_Follower.new(index, @data[-1]))
  482.     end
  483.   end
  484.    
  485. end
  486.  
  487. class Spriteset_Map
  488.  
  489.   alias add_fref7632 update
  490.   def update
  491.     add_fref7632
  492.     if $game_player.followers.need_refresh
  493.       @character_sprites.each_with_index do |char,i|
  494.         if char.character.is_a?(Game_Follower) || char.character.is_a?(Game_Player)
  495.           @character_sprites[i].dispose
  496.           @character_sprites[i] = nil
  497.         end
  498.       end
  499.       @character_sprites.compact!
  500.       $game_player.reset_followers
  501.       $game_player.followers.reverse_each do |follower|
  502.         @character_sprites.push(Sprite_Character.new(@viewport1, follower))
  503.       end
  504.       @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
  505.       $game_player.followers.need_refresh = false
  506.     end
  507.   end
  508.  
  509. end
  510. #==============================================================================
  511. # !!END OF SCRIPT - OHH, NOES!!
  512. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement