Need help editing Threat System script (XP)

So I am working on integrating Fanatist's Threat System script into my game and I've come across a minor snag.

My goal is to move the threat gauge down so it's below the HP counter. I'd also like add the letters EF (Enemy Focus) to the left of the threat number.

My first and biggest problem is that while I have been able to move the Threat counter, it only moves to the correct spot for the first player character. The other two move down but are too far to the left.

My second problem is that I just don't know how to pop the desired "EF" in there. I can do without this if I need to, but I'd like to have it there.
Image

If anyone with more experience might be up for taking a gander at the script (below) I'd appreciate the help.

The portion I edited
  1. #==============================================================================
  2. # ** Window_BattleStatus
  3. #------------------------------------------------------------------------------
  4. #  Modded to show threat beside actor's name.
  5. #==============================================================================
  6.  
  7. class Window_BattleStatus
  8.   #--------------------------------------------------------------------------
  9.   # * Refresh
  10.   #--------------------------------------------------------------------------
  11.   alias threat_display_refresh refresh
  12.   def refresh
  13.     threat_display_refresh
  14.     for i in 0...$game_party.actors.size
  15.       actor = $game_party.actors[i]
  16.       next if actor.threat == 0
  17.       actor_x = i * 160 + 4
  18.       actor_x += self.contents.text_size(actor.name).width + 4
  19.       self.contents.draw_text(actor_x, 0, 160, 170, "(#{actor.threat})")
  20.     end
  21.   end
  22. end
  23. end
  24.  
  25. if ThreatConfig::THREAT_WINDOW
  26. #==============================================================================
  27. # ** Window_Threat
  28. #------------------------------------------------------------------------------
  29. #  This window displays the threats of actors in the party.
  30. #==============================================================================
  31.  
  32. class Window_Threat < Window_Base
  33.   H = 18
  34.   #--------------------------------------------------------------------------
  35.   # * Object Initialization
  36.   #--------------------------------------------------------------------------
  37.   def initialize
  38.     a = ThreatConfig::THREAT_WINDOW
  39.     if a.is_a?(Array)
  40.       x, y, w = a[0], a[1], a[2]
  41.     else
  42.       x, y, w = 0, 64, 160
  43.     end
  44.     super(x, y, w, 32 + H + $game_party.actors.size * H)
  45.     @threats = []
  46.     $game_party.actors.each {|a| @threats.push(a.threat)}
  47.     self.contents = Bitmap.new(w-32, self.height-32)
  48.     self.contents.font.size = H
  49.     self.contents.font.bold = H <= 22
  50.     self.opacity = 160
  51.     refresh
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * Refresh
  55.   #--------------------------------------------------------------------------
  56.   def refresh
  57.     self.contents.clear
  58.     self.contents.draw_text(0, 0, self.width-32, H, 'Threats', 1)
  59.     $game_party.actors.each_with_index {|a, i| y_off = H
  60.     self.contents.draw_text(0, y_off + i*H, self.width-32, H, a.name)
  61.     self.contents.draw_text(0, y_off + i*H, self.width-32, H, @threats[i].to_s, 2)}
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # * Update
  65.   #--------------------------------------------------------------------------
  66.   def update
  67.     flag = false
  68.     $game_party.actors.each_with_index {|a, i|
  69.     @threats[i] = a.threat if a.threat != @threats[i]
  70.     flag = true}
  71.     refresh if flag
  72.   end
  73. end
Expand to see the code.


The full script
  1. #==============================================================================
  2. # ** Threat System
  3. #------------------------------------------------------------------------------
  4. # by Fantasist
  5. # Version: 1.2
  6. # Date: 23-Oct-2011
  7. #------------------------------------------------------------------------------
  8. # Version History:
  9. #
  10. #   1.0 - First version (13-July-2009)
  11. #   1.1 - Fixed Force Action bug and added enemy-specific threat ignore (21-Oct-2011)
  12. #   1.2 - Added disable by switch, threat by damage, fixed a display bug
  13. #------------------------------------------------------------------------------
  14. # Description:
  15. #
  16. #     During battle, enemies will choose their targets based on their "threat"
  17. #   rather than randomly. The threat for an actor changes depending on what they
  18. #   do. For example, attacking raises threat and defending decreases threat.
  19. #------------------------------------------------------------------------------
  20. # Compatibility:
  21. #
  22. #   Might be incompatible with other battle systems or battle addons.
  23. #------------------------------------------------------------------------------
  24. # Instructions:
  25. #
  26. #    Place this script anywhere above "Main" and below "Scene_Debug".
  27. #------------------------------------------------------------------------------
  28. # Configuration:
  29. #
  30. #     Scroll down a bit and you'll see the configuration.
  31. #
  32. #    ATTACK_THREAT: Threat to increase when actor attacks
  33. #    DEFEND_THREAT: Threat to decrease when actor defends (read THREAT_BY_DAMAGE)
  34. #    THREAT_CHANCE: The chance of enemies attacking based on threat
  35. #    THREAT_SWITCH: Turn this ON to temporarily disable the threat system
  36. # THREAT_BY_DAMAGE: When "true", an actor's threat increases by the damage
  37. #                   caused to enemies. Enabling this ignores ATTACK_THREAT.
  38. #                   When defending, actor's threat is divided by DEFEND_THREAT.
  39. #   THREAT_DISPLAY: Display players' threats besides their name
  40. #    THREAT_WINDOW: Whether to enable or disable threat window
  41. #                   To enable it, set it to "true". If you want to set it's
  42. #                   position and width, you can also set it to an array with
  43. #                   it's X position, Y position and width (eg: [0, 64, 160]).
  44. #     ENEMY_IGNORE: List of enemy IDs which ignore the threat system
  45. #
  46. #   Skill Threat Configuration:
  47. #
  48. #     Look for "SKILL THREAT CONFIG BEGIN" and follow the example.
  49. #     In the given example:
  50. #
  51. #               when 57 then [10, -2]
  52. #
  53. #     the skill 57 (Cross Cut) increases user's threat by 10 and decreases the
  54. #     rest of the party's threat by 2.
  55. #
  56. #   Item Threat Configuration:
  57. #
  58. #     Works exactly the same as skill threat configuration.
  59. #------------------------------------------------------------------------------
  60. # Credits:
  61. #
  62. #   Fantasist, for making this script
  63. #   KCMike20, for requesting this script
  64. #
  65. # Thanks:
  66. #
  67. #   Blizzard, for helping me
  68. #   winkio, for helping me
  69. #   Jackolas, for pointing out a bug
  70. #   yuhikaru, for fixing force action bug
  71. #   Fenriswolf, for requesting enemy ignore list
  72. #   Kagutsuchi, for requesting threat-by-damage feature
  73. #------------------------------------------------------------------------------
  74. # Notes:
  75. #
  76. #   If you have any problems, suggestions or comments, you can find me at:
  77. #
  78. #     forum.chaos-project.com
  79. #
  80. #   Enjoy ^_^
  81. #==============================================================================
  82.  
  83. #==============================================================================
  84. # ** ThreatConfig module
  85. #------------------------------------------------------------------------------
  86. #  Module for settings and configuration of the Threat system.
  87. #==============================================================================
  88.  
  89. module ThreatConfig
  90.   #--------------------------------------------------------------------------
  91.   # * Config
  92.   #--------------------------------------------------------------------------
  93.   ATTACK_THREAT = 10 # Threat to increase when actor attacks
  94.   DEFEND_THREAT = 10 # Threat to decrease when actor defends
  95.   THREAT_CHANCE = 100 # The chance of enemies attacking based on threat
  96.   THREAT_SWITCH = 25 # ID of switch which disables threat system when ON
  97.   THREAT_BY_DAMAGE = true # Threat is increased based on damage caused
  98.   THREAT_DISPLAY = true # Display player's threat besides their name
  99.   THREAT_WINDOW = false # Whether to enable or disable threat window
  100.   ENEMY_IGNORE = [] # List of enemy IDs which ignore the threat system
  101.   #--------------------------------------------------------------------------
  102.   # * Configure skill threats
  103.   #--------------------------------------------------------------------------
  104.   def self.get_skill_threat(skill_id)
  105.     threat = case skill_id
  106.     #========================================================================
  107.     # SKILL THREAT CONFIG BEGIN
  108.     #========================================================================
  109.     when 57 then [5, -1] # Cross Cut
  110.     when 61 then [5, -1] # Leg Sweep
  111.     when 7 then [5, 0]   # Fire
  112.     # when skill_ID then [ user_threat, party_threat ]
  113.     #========================================================================
  114.     # SKILL THREAT CONFIG END
  115.     #========================================================================
  116.     else false
  117.     end
  118.     return threat
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # * Configure item threats
  122.   #--------------------------------------------------------------------------
  123.   def self.get_item_threat(item_id)
  124.     threat = case item_id
  125.     #========================================================================
  126.     # ITEM THREAT CONFIG BEGIN
  127.     #========================================================================
  128.     when 1 then [2, -5] # Potion
  129.     # when item_ID then [ user_threat, party_threat ]
  130.     #========================================================================
  131.     # ITEM THREAT CONFIG END
  132.     #========================================================================
  133.     else false
  134.     end
  135.     return threat
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # * Configure enemy ignore IDs
  139.   #--------------------------------------------------------------------------
  140.  
  141. end
  142.  
  143. #==============================================================================
  144. # ** Game_Actor
  145. #------------------------------------------------------------------------------
  146. #  Added the threat attribute.
  147. #==============================================================================
  148.  
  149. class Game_Actor
  150.   #--------------------------------------------------------------------------
  151.   # * Initialize threat attribute
  152.   #--------------------------------------------------------------------------
  153.   alias game_actor_threat_setup setup
  154.   def setup(actor_id)
  155.     @threat = 0
  156.     game_actor_threat_setup(actor_id)
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # * Get the threat attribute
  160.   #--------------------------------------------------------------------------
  161.   attr_reader :threat
  162.   #--------------------------------------------------------------------------
  163.   # * Set the threat attribute
  164.   #--------------------------------------------------------------------------
  165.   def threat=(val)
  166.     val = 0 if val < 0
  167.     @threat = val
  168.   end
  169. end
  170.  
  171. #==============================================================================
  172. # ** Game_Party
  173. #------------------------------------------------------------------------------
  174. #  Modified random actor selection to select by threat.
  175. #==============================================================================
  176.  
  177. class Game_Party
  178.   #--------------------------------------------------------------------------
  179.   # * Choose actor by threat
  180.   #--------------------------------------------------------------------------
  181.   alias choose_actor_threat_orig random_target_actor
  182.   def random_target_actor(hp0 = false)
  183.     if $game_switches[ThreatConfig::THREAT_SWITCH]
  184.       return choose_actor_threat_orig(hp0)
  185.     end
  186.     if $scene.active_battler.is_a?(Game_Enemy) &&
  187.       ThreatConfig::ENEMY_IGNORE.include?($scene.active_battler.id)
  188.       return choose_actor_threat_orig(hp0)
  189.     end
  190.     if rand(100) >= ThreatConfig::THREAT_CHANCE
  191.       return choose_actor_threat_orig(hp0)
  192.     else
  193.       return threat_target_actor(hp0)
  194.     end
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # * Calculate threat and choose actor
  198.   #--------------------------------------------------------------------------
  199.   def threat_target_actor(hp0=false)
  200.     # Collect valid actors
  201.     targets = []
  202.     for actor in @actors
  203.       next unless (!hp0 && actor.exist?) || (hp0 && actor.hp0?)
  204.       targets.push(actor)
  205.     end
  206.     # Get actors with maximum threat
  207.     targets.sort! {|a, b| b.threat - a.threat}
  208.     targets = targets.find_all {|a| a.threat == targets[0].threat}
  209.     # Choose random
  210.     target = targets[rand(targets.size)]
  211.     return target
  212.   end
  213. end
  214.  
  215. #==============================================================================
  216. # ** Game_Battler
  217. #------------------------------------------------------------------------------
  218. #  Added attack and skill threat handling.
  219. #==============================================================================
  220.  
  221. class Game_Battler
  222.   #--------------------------------------------------------------------------
  223.   # * Attack Threat
  224.   #--------------------------------------------------------------------------
  225.   alias attack_effect_threat attack_effect
  226.   def attack_effect(attacker)
  227.     result = attack_effect_threat(attacker)
  228.     if attacker.is_a?(Game_Actor) && self.damage.is_a?(Numeric) && self.damage > 0
  229.       if ThreatConfig::THREAT_BY_DAMAGE
  230.         attacker.threat += self.damage
  231.       else
  232.         attacker.threat += ThreatConfig::ATTACK_THREAT
  233.       end
  234.     end
  235.     return result
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # * Skill Threat
  239.   #--------------------------------------------------------------------------
  240.   alias skill_effect_threat skill_effect
  241.   def skill_effect(user, skill)
  242.     result = skill_effect_threat(user, skill)
  243.     threat = user.is_a?(Game_Actor) && ThreatConfig.get_skill_threat(skill.id)
  244.     if threat && self.damage.is_a?(Numeric) && self.damage > 0
  245.       user_threat, party_threat = threat[0], threat[1]
  246.       for actor in $game_party.actors
  247.         threat_plus = actor.id == user.id ? user_threat : party_threat
  248.         actor.threat += threat_plus
  249.       end
  250.       if ThreatConfig::THREAT_BY_DAMAGE
  251.         user.threat -= user_threat
  252.         user.threat += self.damage
  253.       end
  254.     end
  255.     return result
  256.   end
  257. end
  258.  
  259. #==============================================================================
  260. # ** Scene_Battle
  261. #------------------------------------------------------------------------------
  262. #  Added defend and item threat handling and realtime target selection.
  263. #==============================================================================
  264.  
  265. class Scene_Battle
  266.   attr_reader :active_battler
  267.   #--------------------------------------------------------------------------
  268.   # * Defend Threat
  269.   #--------------------------------------------------------------------------
  270.   alias basic_action_threat_result make_basic_action_result
  271.   def make_basic_action_result
  272.     if @active_battler.current_action.basic == 1 && @active_battler.is_a?(Game_Actor)
  273.       if ThreatConfig::THREAT_BY_DAMAGE
  274.         @active_battler.threat /= ThreatConfig::DEFEND_THREAT
  275.       else
  276.         @active_battler.threat -= ThreatConfig::DEFEND_THREAT
  277.       end
  278.     end
  279.     basic_action_threat_result
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # * Item Threat
  283.   #--------------------------------------------------------------------------
  284.   alias item_action_threat_result make_item_action_result
  285.   def make_item_action_result
  286.     item_action_threat_result
  287.     threat = @active_battler.is_a?(Game_Actor) && ThreatConfig.get_item_threat(@item.id)
  288.     if threat
  289.       user_threat, party_threat = threat[0], threat[1]
  290.       for actor in $game_party.actors
  291.         threat_plus = actor.id == @active_battler.id ? user_threat : party_threat
  292.         actor.threat += threat_plus
  293.       end
  294.     end
  295.   end
  296.   #--------------------------------------------------------------------------
  297.   # * Choose target actor in realtime
  298.   #--------------------------------------------------------------------------
  299.   alias update_phase4_step2_choose_actor_realtime update_phase4_step2
  300.   def update_phase4_step2
  301.     # Fore action fix by yuhikaru
  302.     # If there is no force action this turn
  303.     if $game_temp.forcing_battler == nil
  304.       @active_battler.make_action if @active_battler.is_a?(Game_Enemy)
  305.     end
  306.     update_phase4_step2_choose_actor_realtime
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # * Clear threats before battle
  310.   #--------------------------------------------------------------------------
  311.   alias clear_threats_battle_main main
  312.   def main
  313.     $game_party.actors.each {|actor| actor.threat = 0}
  314.     clear_threats_battle_main
  315.   end
  316. end
  317.  
  318. if ThreatConfig::THREAT_DISPLAY
  319. #==============================================================================
  320. # ** Window_BattleStatus
  321. #------------------------------------------------------------------------------
  322. #  Modded to show threat beside actor's name.
  323. #==============================================================================
  324.  
  325. class Window_BattleStatus
  326.   #--------------------------------------------------------------------------
  327.   # * Refresh
  328.   #--------------------------------------------------------------------------
  329.   alias threat_display_refresh refresh
  330.   def refresh
  331.     threat_display_refresh
  332.     for i in 0...$game_party.actors.size
  333.       actor = $game_party.actors[i]
  334.       next if actor.threat == 0
  335.       actor_x = i * 160 + 4
  336.       actor_x += self.contents.text_size(actor.name).width + 4
  337.       self.contents.draw_text(actor_x, 0, 160, 170, "(#{actor.threat})")
  338.     end
  339.   end
  340. end
  341. end
  342.  
  343. if ThreatConfig::THREAT_WINDOW
  344. #==============================================================================
  345. # ** Window_Threat
  346. #------------------------------------------------------------------------------
  347. #  This window displays the threats of actors in the party.
  348. #==============================================================================
  349.  
  350. class Window_Threat < Window_Base
  351.   H = 18
  352.   #--------------------------------------------------------------------------
  353.   # * Object Initialization
  354.   #--------------------------------------------------------------------------
  355.   def initialize
  356.     a = ThreatConfig::THREAT_WINDOW
  357.     if a.is_a?(Array)
  358.       x, y, w = a[0], a[1], a[2]
  359.     else
  360.       x, y, w = 0, 64, 160
  361.     end
  362.     super(x, y, w, 32 + H + $game_party.actors.size * H)
  363.     @threats = []
  364.     $game_party.actors.each {|a| @threats.push(a.threat)}
  365.     self.contents = Bitmap.new(w-32, self.height-32)
  366.     self.contents.font.size = H
  367.     self.contents.font.bold = H <= 22
  368.     self.opacity = 160
  369.     refresh
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   # * Refresh
  373.   #--------------------------------------------------------------------------
  374.   def refresh
  375.     self.contents.clear
  376.     self.contents.draw_text(0, 0, self.width-32, H, 'Threats', 1)
  377.     $game_party.actors.each_with_index {|a, i| y_off = H
  378.     self.contents.draw_text(0, y_off + i*H, self.width-32, H, a.name)
  379.     self.contents.draw_text(0, y_off + i*H, self.width-32, H, @threats[i].to_s, 2)}
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   # * Update
  383.   #--------------------------------------------------------------------------
  384.   def update
  385.     flag = false
  386.     $game_party.actors.each_with_index {|a, i|
  387.     @threats[i] = a.threat if a.threat != @threats[i]
  388.     flag = true}
  389.     refresh if flag
  390.   end
  391. end
  392.  
  393. #==============================================================================
  394. # ** Scene_Battle
  395. #------------------------------------------------------------------------------
  396. #  Modded to handle threat window.
  397. #==============================================================================
  398.  
  399. class Scene_Battle
  400.   #--------------------------------------------------------------------------
  401.   # * Main Processing
  402.   #--------------------------------------------------------------------------
  403.   alias threat_win_init main
  404.   def main
  405.     @threat_win = Window_Threat.new
  406.     threat_win_init
  407.     @threat_win.dispose
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # * Update
  411.   #--------------------------------------------------------------------------
  412.   alias threat_win_upd update
  413.   def update
  414.     @threat_win.update
  415.     threat_win_upd
  416.   end
  417. end
  418. end
Expand to see the code.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=77104