Advertisement
MoltresRider

Untargetable State Script (broken)

Apr 8th, 2023
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. =begin
  2. #===============================================================================
  3. Title: Untargetable State
  4. Author: Hime
  5. Date: Sep 25, 2015
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. Sep 25, 2015
  9. - when selecting actors, the correct actor index needs to be provided
  10. Oct 17, 2013
  11. - compatiblity patch with yanfly's Ace Battle Engine
  12. Jun 7, 2013
  13. - bug fix: game crashes when there are no valid targets
  14. May 29, 2013
  15. - fixed bug where enemies that are hidden appear in the target window
  16. May 25, 2013
  17. - added support for untargetable actors
  18. - Initial release
  19. --------------------------------------------------------------------------------
  20. ** Terms of Use
  21. * Free to use in non-commercial projects
  22. * Contact me for commercial use
  23. * No real support. The script is provided as-is
  24. * Will do bug fixes, but no compatibility patches
  25. * Features may be requested but no guarantees, especially if it is non-trivial
  26. * Credits to Hime Works in your project
  27. * Preserve this header
  28. --------------------------------------------------------------------------------
  29. ** Description
  30.  
  31. This script allows you to create a state that prevents you from targeting
  32. a battler. When the state is applied, the battler cannot be targeted or
  33. affected by any skills or items.
  34.  
  35. --------------------------------------------------------------------------------
  36. ** Installation
  37.  
  38. Place this script below Materials and above Main
  39.  
  40. --------------------------------------------------------------------------------
  41. ** Usage
  42.  
  43. In the configuration below, enter the ID's of all states that should have the
  44. untargetable property
  45.  
  46. --------------------------------------------------------------------------------
  47. ** Compatibility
  48.  
  49. This script overwrites the following
  50.  
  51. Window_BattleEnemy
  52. item_max
  53. enemy
  54. draw_item
  55.  
  56. #===============================================================================
  57. =end
  58. $imported = {} if $imported.nil?
  59. $imported["TH_UntargetableState"] = true
  60. #===============================================================================
  61. # ** Configuration
  62. #===============================================================================
  63. module TH
  64. module Untargetable_State
  65.  
  66. # List of state ID's that will have untargetable effect
  67. States = [20]
  68. end
  69. end
  70. #===============================================================================
  71. # ** Rest of script
  72. #===============================================================================
  73. class Game_Action
  74.  
  75. alias :th_untargetable_state_make_targets :make_targets
  76. def make_targets
  77. th_untargetable_state_make_targets.select {|target| target && target.can_target? }
  78. end
  79. end
  80.  
  81. class Game_Battler < Game_BattlerBase
  82. def can_target?
  83. return false if untargetable_state?
  84. return false unless exist?
  85. return true
  86. end
  87.  
  88. #-----------------------------------------------------------------------------
  89. # Check if untargetable state is applied
  90. #-----------------------------------------------------------------------------
  91. def untargetable_state?
  92. !(@states & TH::Untargetable_State::States).empty?
  93. end
  94. end
  95.  
  96. class Game_Enemy < Game_Battler
  97.  
  98. #-----------------------------------------------------------------------------
  99. # Lots of hardcoded conditions based on default scripts
  100. #-----------------------------------------------------------------------------
  101. alias :th_untargetable_state_can_target? :can_target?
  102. def can_target?
  103. return false if dead?
  104. th_untargetable_state_can_target?
  105. end
  106. end
  107.  
  108. class Game_Unit
  109.  
  110. #-----------------------------------------------------------------------------
  111. # New. Return an array of battlers that can be targeted
  112. #-----------------------------------------------------------------------------
  113. def targetable_members
  114. members.select {|member| member.can_target? }
  115. end
  116. end
  117.  
  118. #-------------------------------------------------------------------------------
  119. # Updated to only draw enemies that can be selected.
  120. # Basically replaces everything
  121. #-------------------------------------------------------------------------------
  122. class Window_BattleEnemy < Window_Selectable
  123. def item_max
  124. $game_troop.targetable_members.size
  125. end
  126.  
  127. def enemy
  128. $game_troop.targetable_members[@index]
  129. end
  130.  
  131. def draw_item(index)
  132. change_color(normal_color)
  133. name = $game_troop.targetable_members[index].name
  134. draw_text(item_rect_for_text(index), name)
  135. end
  136.  
  137. alias :th_untargetable_state_current_item_enabled? :current_item_enabled?
  138. def current_item_enabled?
  139. return false if $game_troop.targetable_members[@index].nil?
  140. th_untargetable_state_current_item_enabled?
  141. end
  142. end
  143.  
  144. #-------------------------------------------------------------------------------
  145. # Updated to only draw actors that can be selected.
  146. # Basically replaces everything
  147. #-------------------------------------------------------------------------------
  148. class Window_BattleActor < Window_BattleStatus
  149.  
  150. def actor_index
  151. $game_party.targetable_members[@index].name
  152. end
  153.  
  154. def item_max
  155. $game_party.targetable_members.size
  156. end
  157.  
  158. def draw_item(index)
  159. actor = $game_party.targetable_members[index]
  160. draw_basic_area(basic_area_rect(index), actor)
  161. draw_gauge_area(gauge_area_rect(index), actor)
  162. end
  163.  
  164. alias :th_untargetable_state_current_item_enabled? :current_item_enabled?
  165. def current_item_enabled?
  166. return false if $game_party.targetable_members[index].nil?
  167. th_untargetable_state_current_item_enabled?
  168. end
  169. end
  170.  
  171.  
  172. class Scene_Battle < Scene_Base
  173.  
  174. # Overwrite. Need the proper index of the selected actor.
  175. def on_actor_ok
  176. BattleManager.actor.input.target_index = @actor_window.actor_index
  177. @actor_window.hide
  178. @skill_window.hide
  179. @item_window.hide
  180. next_command
  181. end
  182. end
  183.  
  184. if $imported["YEA-BattleEngine"]
  185. class Window_BattleActor < Window_BattleStatus
  186. def draw_item(index)
  187. return if index.nil?
  188. clear_item(index)
  189. actor = $game_party.targetable_members[index] ### changed this
  190. rect = item_rect(index)
  191. return if actor.nil?
  192. draw_actor_face(actor, rect.x+2, rect.y+2, actor.alive?)
  193. draw_actor_name(actor, rect.x, rect.y, rect.width-8)
  194. draw_actor_action(actor, rect.x, rect.y)
  195. draw_actor_icons(actor, rect.x, line_height*1, rect.width)
  196. gx = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS
  197. contents.font.size = YEA::BATTLE::BATTLESTATUS_TEXT_FONT_SIZE
  198. draw_actor_hp(actor, rect.x+2, line_height*2+gx, rect.width-4)
  199. if draw_tp?(actor) && draw_mp?(actor)
  200. dw = rect.width/2-2
  201. dw += 1 if $imported["YEA-CoreEngine"] && YEA::CORE::GAUGE_OUTLINE
  202. draw_actor_tp(actor, rect.x+2, line_height*3, dw)
  203. dw = rect.width - rect.width/2 - 2
  204. draw_actor_mp(actor, rect.x+rect.width/2, line_height*3, dw)
  205. elsif draw_tp?(actor) && !draw_mp?(actor)
  206. draw_actor_tp(actor, rect.x+2, line_height*3, rect.width-4)
  207. else
  208. draw_actor_mp(actor, rect.x+2, line_height*3, rect.width-4)
  209. end
  210. end
  211. end
  212. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement