Advertisement
roninator2

Non Combat Actor

Dec 11th, 2024 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.24 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Non Combat Actor                       ║  Version: 1.12     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║ Specify actors to never be in combat          ║    03 Jul 2021     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: nil                                                      ║
  11. # ║                                                                    ║
  12. # ╚════════════════════════════════════════════════════════════════════╝
  13. # ╔════════════════════════════════════════════════════════════════════╗
  14. # ║ Brief Description:                                                 ║
  15. # ║       Have Actors that do not fight                                ║
  16. # ╚════════════════════════════════════════════════════════════════════╝
  17. # ╔════════════════════════════════════════════════════════════════════╗
  18. # ║ Instructions:                                                      ║
  19. # ║   Place note tag on actor note box. <non combat>                   ║
  20. # ║   Change number below to Max battle members                        ║
  21. # ║ Known Bug: adding actors already in party breaks this script       ║
  22. # ╚════════════════════════════════════════════════════════════════════╝
  23. # ╔════════════════════════════════════════════════════════════════════╗
  24. # ║ Updates:                                                           ║
  25. # ║ 1.00 - 03 Jul 2021 - Script finished                               ║
  26. # ║ 1.01 - 04 Jul 2021 - updated                                       ║
  27. # ║ 1.02 - 02 Jan 2025 - fixed a bug, allow having non members visible ║
  28. # ║ 1.03 - 03 Jan 2025 - finally fixed the display order               ║
  29. # ║ 1.04 - 03 Jan 2025 - Added Support to have non combat not gain exp ║
  30. # ║ 1.05 - 03 Jan 2025 - Added Support hidden followers                ║
  31. # ║ 1.06 - 03 Jan 2025 - Cleaned up unneeded code                      ║
  32. # ║ 1.07 - 03 Jan 2025 - Fixed gaining exp for non battle actors       ║
  33. # ║ 1.08 - 03 Jan 2025 - Attempt to fix issues reported                ║
  34. # ║ 1.09 - 04 Jan 2025 - Made changes                                  ║
  35. # ║ 1.10 - 08 Jan 2025 - Had to account for adding actors later        ║
  36. # ║ 1.11 - 09 Jan 2025 - Issue with large parties                      ║
  37. # ║ 1.12 - 10 Jan 2025 - Fixed duplicating actors                      ║
  38. # ╚════════════════════════════════════════════════════════════════════╝
  39. # ╔════════════════════════════════════════════════════════════════════╗
  40. # ║ Credits and Thanks:                                                ║
  41. # ║   Roninator2                                                       ║
  42. # ║                                                                    ║
  43. # ╚════════════════════════════════════════════════════════════════════╝
  44. # ╔════════════════════════════════════════════════════════════════════╗
  45. # ║ Terms of use:                                                      ║
  46. # ║  Follow the original Authors terms of use where applicable         ║
  47. # ║    - When not made by me (Roninator2)                              ║
  48. # ║  Free for all uses in RPG Maker except nudity                      ║
  49. # ║  Anyone using this script in their project before these terms      ║
  50. # ║  were changed are allowed to use this script even if it conflicts  ║
  51. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  52. # ║  No part of this code can be used with AI programs or tools        ║
  53. # ║  Credit must be given                                              ║
  54. # ╚════════════════════════════════════════════════════════════════════╝
  55.  
  56. module R2_Max_Battle_Members
  57.   MAX = 4
  58.   SHOW_NON_COMBAT = true
  59.   GAIN_EXP_NON_COMBAT = true
  60.   EXP_RATE = 1.0
  61. end
  62.  
  63. # ╔══════════════════════════════════════════════════════════╗
  64. # ║      No more editing                                     ║
  65. # ╚══════════════════════════════════════════════════════════╝
  66.  
  67. class Game_Follower < Game_Character
  68.   attr_reader :member_index
  69.   def set_character(character_name, character_index)
  70.     @character_name = character_name
  71.     @character_index = character_index
  72.   end
  73.   def actor
  74.     $game_party.members[@member_index]
  75.   end
  76. end
  77.  
  78. class Game_Followers
  79.   attr_reader :data
  80.   def initialize(leader)
  81.     @visible = $data_system.opt_followers
  82.     @gathering = false
  83.     @data = []
  84.     @data.push(Game_Follower.new(1, leader))
  85.     (2...$game_party.max_battle_members.size).each do |index|
  86.       @data.push(Game_Follower.new(index, @data[-1]))
  87.     end
  88.   end
  89.   def setup_non_battle_members
  90.     return unless R2_Max_Battle_Members::SHOW_NON_COMBAT
  91.     return if $game_party.non_battle_members == []
  92.     $game_party.non_battle_members.each do |i|
  93.       @data.push(Game_Follower.new(@data.size, @data[-1]))
  94.       new = @data[-1]
  95.       new.moveto($game_player.x, $game_player.y)
  96.     end
  97.   end
  98.   def add_non_follower(index)
  99.     found = false
  100.     @data.each { |fol|
  101.       if fol.member_index == index
  102.         found = true
  103.       end
  104.     }
  105.     if found == false
  106.       @data.push(Game_Follower.new(index, @data[-1]))
  107.       new = @data[-1]
  108.       old = @data[-2]
  109.       new.moveto(old.x, old.y)
  110.     end
  111.   end
  112. end
  113.  
  114. class Game_Party < Game_Unit
  115.   attr_reader :non_battle_members
  116.  
  117.   alias :r2_game_party_initialize_na :initialize
  118.   def initialize
  119.     r2_game_party_initialize_na
  120.     @non_battle_members = nil
  121.   end
  122.  
  123.   def battle_members
  124.     array = []
  125.     for act in @actors
  126.       nonact = $data_actors[act]
  127.       next if nonact.note =~ /<non combat>/i
  128.       actor = $game_actors[act]
  129.       next if !actor.exist?
  130.       next if array.size >= R2_Max_Battle_Members::MAX
  131.       array << actor
  132.     end
  133.     return array
  134.   end
  135.  
  136.   def not_battle_members
  137.     @non_battle_members = []
  138.     for act in @actors
  139.       nonact = $data_actors[act]
  140.       if nonact.note =~ /<non combat>/i
  141.         actor = $game_actors[act]
  142.         next if !actor.exist?
  143.         @non_battle_members << actor
  144.       end
  145.     end
  146.     return @non_battle_members
  147.   end
  148.  
  149.   def max_battle_members
  150.     in_battle ? battle_members.size : battle_members.size + not_battle_members.size
  151.   end
  152.  
  153.   alias :r2_setup_starting_members_nb :setup_starting_members
  154.   def setup_starting_members
  155.     r2_setup_starting_members_nb
  156.     not_battle_members
  157.     $game_player.followers.setup_non_battle_members
  158.   end
  159.  
  160.   alias :r2_swap_order_non_combat :swap_order
  161.   def swap_order(index1, index2)
  162.     r2_swap_order_non_combat(index1, index2)
  163.     $game_player.refresh
  164.   end
  165.  
  166.   alias :r2_add_actor_non_combat  :add_actor
  167.   def add_actor(actor_id)
  168.     list = []
  169.     $game_party.members.each { |mem|  list.push(mem.clone) }
  170.     r2_add_actor_non_combat(actor_id)
  171.     not_battle_members
  172.     nonact = $data_actors[actor_id]
  173.     if nonact.note =~ /<non combat>/i
  174.       $game_player.followers.add_non_follower(actor_id) unless
  175.         list.include?($game_actors[actor_id])
  176.     end
  177.     SceneManager.scene.instance_variable_get(:@spriteset).refresh_characters
  178.   end
  179.  
  180.   alias :r2_remove_actor_non_combat  :remove_actor
  181.   def remove_actor(actor_id)
  182.     r2_remove_actor_non_combat(actor_id)
  183.     $game_player.refresh
  184.     $game_map.need_refresh = true
  185.   end
  186. end
  187.  
  188. class Scene_Map < Scene_Base
  189.   alias :r2_not_battle_member_update :update
  190.   def update
  191.     r2_not_battle_member_update
  192.     call_not_battle_member_graphic if $game_player.followers.visible_folloers
  193.   end
  194.  
  195.   def call_not_battle_member_graphic
  196.     return if R2_Max_Battle_Members::SHOW_NON_COMBAT == false
  197.     pos = 0
  198.     cnt = 0
  199.     $game_party.all_members.each_with_index do |actor, index|
  200.       next if actor == nil
  201.       next if index == 0
  202.       nonact = $data_actors[actor.id]
  203.       if nonact.note =~ /<non combat>/i
  204.         follower = $game_player.followers[index - 1 - pos]
  205.         next unless follower
  206.         follower.set_character(actor.character_name, actor.character_index)
  207.       else
  208.         if cnt < $game_party.battle_members.size - 1
  209.           follower = $game_player.followers[index - 1 - pos]
  210.           next unless follower
  211.           follower.set_character(actor.character_name, actor.character_index)
  212.           cnt += 1
  213.         else
  214.           pos += 1
  215.         end
  216.       end
  217.     end
  218.   end
  219. end
  220.  
  221. class Game_Actor < Game_Battler
  222.   def reserve_members_exp_rate
  223.     if $game_party.non_battle_members.include?(self) &&
  224.       R2_Max_Battle_Members::GAIN_EXP_NON_COMBAT
  225.         return R2_Max_Battle_Members::EXP_RATE
  226.     else
  227.       $data_system.opt_extra_exp ? 1 : 0
  228.     end
  229.   end
  230. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement