Maybe I'm overcomplicating things because I'm new to RPG Maker, but it seemed that the easiest way to do this would be to try and copy the Substitute skill and tweak it to my needs. Well... It's not working out so great. This is the mess I've got so far, that seems to do absolutely nothing. <_<
Spoiler
Code:
class Game_BattlerBase
attr_accessor :bar
alias initialize_barrier initialize
def initialize
initialize_barrier
@bar = 0
end
end
class Scene_Battle < Scene_Base
alias invoke_item_barrier invoke_item
def invoke_item(target, item)
if rand < target.item_cnt(@subject, item)
invoke_counter_attack(target, item)
elsif rand < target.item_mrf(@subject, item)
invoke_magic_reflection(target, item)
elsif target.item_bar(@subject, item) > 0
invoke_barrier(target, item)
else
apply_item_effects(apply_substitute(target, item), item)
end
@subject.last_target_index = target.index
end
def invoke_barrier(target, item)
#if target
@log_window.display_barrier_held(target, item)
apply_item_effects(target, item)
end
end
class Game_Battler < Game_BattlerBase
#The ID for the invisisble 'Protected' state
BARRIER_ID = 29
def item_bar(user, item)
#debug
print "\n" + user.name + "'s current hp: " + user.hp.to_s + "\n"
print "\n" + user.name + "'s current bar: " + user.bar.to_s + "\n\n\n"
return bar
end
alias make_damage_value_barrier make_damage_value
def make_damage_value(user, item)
value = item.damage.eval(user, self, $game_variables)
value = apply_variance(value, item.damage.variance)
#If you have a barrier, and damage isn't 0
if self.state?(BARRIER_ID) == true && value > 0
if value < self.bar
self.bar -= value / 3
value = 0
else
value -= self.bar
self.bar = 0
remove_state(BARRIER_ID)
end
#Standard functions
else
value = item.damage.eval(user, self, $game_variables)
value *= item_element_rate(user, item)
value *= pdr if item.physical?
value *= mdr if item.magical?
value *= rec if item.damage.recover?
value = apply_critical(value) if @result.critical
value = apply_variance(value, item.damage.variance)
value = apply_guard(value)
end
@result.make_damage(value.to_i, item)
end
alias i_e_a_s_n item_effect_add_state_normal
def item_effect_add_state_normal(user, item, effect)
i_e_a_s_n(user, item, effect)
if @result.success == true
case item.id
when 132 #Level 1 barrier skill ID.
self.bar = 500
#when 133 #Level 2 barrier skill ID.
# user.bar = 750
# when 134 #Level 3 barrier skill ID.
# user.bar = 1250
end
end
end
end
class Window_BattleLog < Window_Selectable
def display_barrier_held(target, item)
add_text(sprintf(Vocab::BarrierHeld, target.name))
wait
back_one
end
def display_barrier_shattered(target, item)
add_text(sprintf(Vocab::BarrierShattered, target.name))
wait
back_one
end
endEDIT:
Updated the code to a working version. ^_^ Doesn't seem to have any bugs to speak of, and it's working like a charm.
Topic can be locked or deleted, whatever the policy is on this website.