Adding A Barrier

● ARCHIVED · READ-ONLY
Started by ChaosBeing 3 posts View original ↗
  1. I've been trying for a little while now to create a new skill similar to the Substitute skill that interupts an attack, called Barrier. The Barrier skill as I'd imagined it does exactly what it sounds like it should: Protects the caster from harm. Now of course there are a number of ways you could do this by simply giving the caster a huge DEF buff or the like, but then they're still open to status ailments and a few other things, so it's importan that the attack never connects in the first place.

    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
    
    end
    If someone could give me a nudge in the right direction - Or, better yet, if you know of an easier way to do this through scripting, eventing or anything else - I'd be very grateful.

    EDIT:

    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.
  2. Why not just set Evasion and Magic evasion at 100%, with whatever state you're creating?

    If you have any "guaranteed hit" skills that are neither physical nor magical, then give the skill perfect resistance against any relevant elements as well.
  3. State resist: every state = 100% would take care of the ailments problem.