Hello!
I have a script that I'm trying to modify that creats a Threat System, so the enemies will focus their attacks on the party member with most threat. During the battle a window appears showing the threat level of each party member. Here is a screen shot:
https://i.imgur.com/m4POIOv.png
What I'm trying to do is removing this window and showing an image next to the party member with most threat. I made a fast edition to show how it would look:
https://i.imgur.com/sGXo6p0.png
Can somoene help me with what I should do to make an image appear and change positions depending on who have the highest threat value? All i know is that removing the end of the code removes the window.
Here is the code:
Thanks for the attention!
Edit: The images weren't loading for some reason, so I removed them and added a link instead
I have a script that I'm trying to modify that creats a Threat System, so the enemies will focus their attacks on the party member with most threat. During the battle a window appears showing the threat level of each party member. Here is a screen shot:
https://i.imgur.com/m4POIOv.png
What I'm trying to do is removing this window and showing an image next to the party member with most threat. I made a fast edition to show how it would look:
https://i.imgur.com/sGXo6p0.png
Can somoene help me with what I should do to make an image appear and change positions depending on who have the highest threat value? All i know is that removing the end of the code removes the window.
Here is the code:
Code:
module ThreatConfig
#--------------------------------------------------------------------------
# * Config
#--------------------------------------------------------------------------
ThreatChance = 80 # The chance of enemies attacking based on threat
#--------------------------------------------------------------------------
# * Get the threat attribute
#--------------------------------------------------------------------------
attr_reader :threat
def self.get_skill_threat(skill_id)
threat = case skill_id
# when skill_ID then [ user_threat, party_threat ]
when 97 then [6, 0]
else false
end
return threat
end
#--------------------------------------------------------------------------
# * Get the threat attribute
#--------------------------------------------------------------------------
attr_reader :threat
def self.get_item_threat(item_id)
threat = case item_id
# when item_ID then [ user_threat, party_threat ]
when 33 then [10, -20]
else false
end
return threat
end
#:::::::::::::: Don't touch these yet ::::::::::::::
MaxThreat = 100
MinThreat = 0
AutoDetect = false # Automatically determine if a skill or item is dangerous
end
#==============================================================================
# ** Game_Actor
#==============================================================================
class Game_Actor
#--------------------------------------------------------------------------
# * Initialize threat attribute
#--------------------------------------------------------------------------
alias game_actor_threat_setup setup
def setup(actor_id)
@threat = 0
game_actor_threat_setup(actor_id)
end
#--------------------------------------------------------------------------
# * Get the threat attribute
#--------------------------------------------------------------------------
attr_reader :threat
#--------------------------------------------------------------------------
# * Set the threat attribute
#--------------------------------------------------------------------------
def threat=(val)
max = ThreatConfig::MaxThreat
min = ThreatConfig::MinThreat
val = max if val > max
val = min if val < min
@threat = val
end
#--------------------------------------------------------------------------
# * Threat at battle start
#--------------------------------------------------------------------------
def start_threat
actor_id = self.id
threat = case actor_id
when 2 then 5
when 3 then 5
when 4 then 5
when 5 then 5
else 0
end
return threat
end
end
#==============================================================================
# ** Game_Party
#==============================================================================
class Game_Party
#--------------------------------------------------------------------------
# * Choose actor by threat
#--------------------------------------------------------------------------
alias choose_actor_by_threat random_target_actor
def random_target_actor(hp0 = false)
if rand(100) >= ThreatConfig::ThreatChance
return choose_actor_by_threat(hp0)
end
# Collect valid actors
targets = []
for actor in @actors
next unless (!hp0 && actor.exist?) || (hp0 && actor.hp0?)
targets.push(actor)
end
# Get actors with maximum threat
targets.sort! {|a, b| b.threat - a.threat}
targets = targets.find_all {|a| a.threat == targets[0].threat}
# Choose random
target = targets[rand(targets.size)]
return target
end
end
#==============================================================================
# ** Game_Battler
#==============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# * Attack Threat
#--------------------------------------------------------------------------
alias attack_effect_threat attack_effect
def attack_effect(attacker)
attacker.threat += 1 if attacker.is_a?(Game_Actor)
attack_effect_threat(attacker)
end
#--------------------------------------------------------------------------
# * Skill Threat
#--------------------------------------------------------------------------
alias skill_effect_threat skill_effect
def skill_effect(user, skill)
threat = user.is_a?(Game_Actor) && ThreatConfig.get_skill_threat(skill.id)
if threat
user_threat, party_threat = threat[0], threat[1]
for actor in $game_party.actors
threat_plus = actor.id == user.id ? user_threat : party_threat
actor.threat += threat_plus
end
end
skill_effect_threat(user, skill)
end
end
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Defend Threat
#--------------------------------------------------------------------------
alias basic_action_threat_result make_basic_action_result
def make_basic_action_result
if @active_battler.current_action.basic == 1 &&
@active_battler.is_a?(Game_Actor)
@active_battler.threat -= 1
end
basic_action_threat_result
end
#--------------------------------------------------------------------------
# * Item Threat
#--------------------------------------------------------------------------
alias item_action_threat_result make_item_action_result
def make_item_action_result
item_action_threat_result
threat = @active_battler.is_a?(Game_Actor) && ThreatConfig.get_item_threat(@item.id)
if threat
user_threat, party_threat = threat[0], threat[1]
for actor in $game_party.actors
threat_plus = actor.id == @active_battler.id ? user_threat : party_threat
actor.threat += threat_plus
end
end
end
#--------------------------------------------------------------------------
# * Clear threats before battle
#--------------------------------------------------------------------------
alias clear_threats_start_phase1 start_phase1
def start_phase1
clear_threats_start_phase1
$game_party.actors.each {|actor| actor.threat = actor.start_threat}
end
end
class Window_Threat < Window_Base
H = 20
def initialize(x, y, w)
super(x, y, w, 32 + actors.size * H)
@threats = []
actors.each {|a| @threats.push(a.threat)}
self.contents = Bitmap.new(w-32, self.height-32)
self.contents.font.size = H
self.contents.font.bold = H <= 22
refresh
end
def refresh
self.contents.clear
actors.each_with_index {|a, i|
self.contents.draw_text(0, i*H, self.width-32, H, a.name)
self.contents.draw_text(0, i*H, self.width-32, H, @threats[i].to_s, 2)
}
end
def update
flag = false
actors.each_with_index {|a, i|
@threats[i] = a.threat if a.threat != @threats[i]
flag = true}
refresh if flag
end
def actors
return $game_party.actors
end
end
class Scene_Battle
alias threat_win_init main
def main
@threat_win = Window_Threat.new(458, 135, 160) #(458,64,160)
threat_win_init
@threat_win.dispose
end
alias threat_win_upd update
def update
@threat_win.update
threat_win_upd
end
end
Thanks for the attention!
Edit: The images weren't loading for some reason, so I removed them and added a link instead