Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Battle Interruption.

Juuhou

Sponsor

I've seen this in Trickster's RTAB and I am currently using cogwheel's RTAB and would like to know if it could be integrated somehow. What this does is that whenever a person gets attacked, their turn would be canceled out and their ATB bar would have to fill up again. Being in conjunction with the skill time system which would cancel out their turn in their duration of casting the skill.

Code:
#==============================================================================
# ●● Action Timer
#------------------------------------------------------------------------------
# Trickster (tricksterguy@hotmail.com)
# Version 1.1
# Date 5/30/07
# Goto rmxp.org for updates/support/bug reports
#------------------------------------------------------------------------------
# This script is an addon for the CTB, ATB, or my RTAB script. It improves the
# Built-In Version of Action Timer and allows actions to be interrupted when
# Attacked. (Note you need the most recent version of either CTB ATB or RTAB for
# this script to function correctly)
#==============================================================================

#--------------------------------------------------------------------------
# Begin SDK Log
#--------------------------------------------------------------------------
SDK.log('Action Timer', 'Trickster', 1.1, '5/30/07')

#--------------------------------------------------------------------------
# Begin SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.0, [1, 2, 3, 4])

#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Action Timer')
  
module Action_Timer
  #--------------------------------------------------------------------------
  # * Interruption
  #   - What is an Interruption?
  #   - Example 
  #      proc {|battler, damage| damage > 0} means any damage > 0
  #      Will cause an interruption.
  #   - Syntax A Proc Object
  #--------------------------------------------------------------------------
  Interruption = proc {|battler, damage| damage > 0}
  #--------------------------------------------------------------------------
  # * Interruption Effect
  #   - Effect of Interruption
  #   - 0: no loss of at 1: lose action at 2: lose all at
  #   - Note use -1 if not using a Timer Battle System
  #--------------------------------------------------------------------------
  Effect = 2
  #--------------------------------------------------------------------------
  # * Interruption Weapons
  #   - Can be interrupted when using a weapon?
  #   - Syntax weapon_id => true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Weapons = {}
  #--------------------------------------------------------------------------
  # * Interruption Weapons Default
  #   - Syntax true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Weapons.default = true
  #--------------------------------------------------------------------------
  # * Interruption Enemies
  #   - Can a enemies attack be interrupted?
  #   - Syntax enemy_id => true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Enemies = {}
  #--------------------------------------------------------------------------
  # * Interruption Enemies Default
  #   - Syntax true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Enemies.default = true
  #--------------------------------------------------------------------------
  # * Interruption Skills
  #   - Can be interrupted when using a skill?
  #   - Syntax skill_id => true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Skills = {}
  #--------------------------------------------------------------------------
  # * Interruption Skills Default
  #   - Syntax true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Skills.default = true
  #--------------------------------------------------------------------------
  # * Interruption Items
  #   - Can be interrupted when using a item?
  #   - Syntax item_id => true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Items = {}
  #--------------------------------------------------------------------------
  # * Interruption Items Default
  #   - Syntax true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Items.default = true
  #--------------------------------------------------------------------------
  # * Interruption Defend
  #   - Can be interrupted when defending?
  #   - Syntax true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Defend = true
  #--------------------------------------------------------------------------
  # * Interruption Escape
  #   - Can be interrupted when escaping?
  #   - Syntax true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Escape = true
  #--------------------------------------------------------------------------
  # * Interruption Other
  #   - Can be interrupted when ????
  #   - Syntax true: can be interrupted false: otherwise
  #--------------------------------------------------------------------------
  Other = true
end

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :active_battler
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 5 : damage display)
  #--------------------------------------------------------------------------
  alias_method :trick_timer_battle_update_phase4_step5, :update_phase4_step5
  def update_phase4_step5
    # The Usual
    trick_timer_battle_update_phase4_step5
    # Run Through Target Battlers
    @target_battlers.each do |battler|
      # Get Battler Damage
      damage = battler.damage.to_i
      # Get Interrupted Flag
      interrupted = Action_Timer::Interruption.call(battler, damage)
      # If Damage is not a number set to false
      interrupted = false unless battler.damage.is_a?(Numeric)
      # Skip if not interrupted
      next unless interrupted
      # Setup reset flag
      reset = true
      # If Attacking
      if battler.current_action.is_a_attack?
        # If Battler is a Game Actor
        if battler.is_a?(Game_Actor)
          # Run Through All Weapon Ids
          battler.weapon_ids.each do |weapon_id|
            # And Reset Flag from Weapon
            reset &&= Action_Timer::Weapons[weapon_id]
          end
        # Else it is an Enemy
        else
          # Get Reset Flag
          reset = Action_Timer::Enemies[battler.id]
        end
      # If Using a Skill
      elsif battler.current_action.is_a_skill?
        # Get Skill Id
        skill_id = @active_battler.current_action.skill_id
        # Get Reset Flag
        reset = Action_Timer::Skills[skill_id]
      # If Defending
      elsif battler.current_action.is_a_defend?
        # Get Reset Flag
        reset = Action_Timer::Defend
      # If Using an Item
      elsif battler.current_action.is_a_item?
        # Get Item Id
        item_id = @active_battler.current_action.item_id
        # Get Reset Flag
        reset = Action_Timer::Items[item_id]
      # If Attempt to Escape
      elsif battler.current_action.is_a_escape?
        # Get Reset Flag
        reset = Action_Timer::Escape
      # If ????
      else
        # Get Reset Flag
        reset = Action_Timer::Other
      end
      # Skip Unless Resetting
      next unless reset
      # Clear Action
      battler.current_action.clear
      # Branch by Effect
      case Action_Timer::Effect
      when 0 # No loss of At
        # Set Wait to 0
        battler.wait = 0
        # Reinitialize At Values
        initialize_at
      when 1 # Lose Action At
        # Run Action Cost
        phase4_action_cost(battler)
        # Set Wait to 0
        battler.wait = 0
        # Reinitialize At Values
        initialize_at
      when 2 # Lose All
        # Reset At
        battler.reset_at
        # Reinitialize At Values
        initialize_at
      end
    end
  end
end
#--------------------------------------------------------------------------
# End SDK Enabled Check
#--------------------------------------------------------------------------
end
 
Sort of like going into the Game_Battler class's.....
def attack_effect

and if self.damage >= 0
Set the self.atb = 0
and self.rt = 0 (for the spell delay system)
and then... end

You'll have to add similar code into skill_effect and item_effect as well.

Just off the top of my head. :D
 

Juuhou

Sponsor

Will try that. Expect to see an edit from me soon. >_0

Well...just tried that and got a ton load of errors. Do I HAVE to put them in skill_effect and item_effect if I were to just test it for the regular attack? Because I tried just that but I ended up getting alot of errors. Then I was fixing them until it pointed to a line with an alias and that lost me.
 
Testing with just attacks... only the attack_effect routine need be edited.

Wait here...

look for this bit of script in RTAB... (around #2759)
Code:
      # From HP damage subtraction
      # State change
      @state_changed = false
      states_plus(attacker, attacker.plus_state_set)
      states_minus(attacker, attacker.minus_state_set)
    # In case of miss
    else
and change it to this
Code:
      # From HP damage subtraction
      # State change
      @state_changed = false
      states_plus(attacker, attacker.plus_state_set)
      states_minus(attacker, attacker.minus_state_set)
      # Reset the AT gauge
      self.at = 0
    # In case of miss
    else
or even this (if you want only ACTORS to suffer)...
Code:
      # From HP damage subtraction
      # State change
      @state_changed = false
      states_plus(attacker, attacker.plus_state_set)
      states_minus(attacker, attacker.minus_state_set)
      # Reset the AT gauge for Actors Only
      if self.is_a?(Game_Actor)
        self.at = 0
      end
    # In case of miss
    else

How's that? For Skills and Items, you may want to check an ensure that the damage IS damage and not a healing effect (damage in reverse ;) ).

A little research into the 'delay' variable for the Skill Delay script will need be done, but it's close now.

Enjoy.

Enjoy.
 

Juuhou

Sponsor

So if I added the self.rt in there, it wouldnt work correctly?

Then for the skills and items I just find a similar location and place the self.at = 0 and it would accomplish this? It worked great with the attack, Im gonna test out the skill timer and see if it resets that too.

Ahh I see...if I added self.rt, it would just reset itself and keep trying to do the skill.

Hmm.
 

Juuhou

Sponsor

So if I added the self.rt in there, it wouldnt work correctly?

Then for the skills and items I just find a similar location and place the self.at = 0 and it would accomplish this? It worked great with the attack, Im gonna test out the skill timer and see if it resets that too.

Ahh I see...if I added self.rt, it would just reset itself and keep trying to do the skill.

Hmm.

EDIT: Well Im in an interesing bind here. I tried looking for teh skills and items and its just as you said. About the healing stuff which would cancel out the turn as well. Could I implement an if statement somewhere declaring only if it did damage and not heal? Damn it, I need to learn some more ruby. Then also for the skill delay, the script itself isnt really editable...I take it that the RTAB is doing all the work. T_T Crap...

Also is this considered a bump? I kinda abused mah power. Sorry if it is. Won t do it again. >_0
 
Well, you got my attention, right?

To check for 'damage' values and not healing, just have it check to see if the damage is in the positive values and not 0 or less. That's what I did for Limit Break damages. Heh... KGC never thought about Item damage (grenades n such) like I did. ;)

Yeah, the Skill Delay script doesn't have much to edit (almost nothing), so you have to find which values to turn OFF or set to nil. Stuff like forcing_Battler n such. But I'm sure you gotta reset one of those values too. Maybe the rt value AND forcing_battler combined???

Well, it'll take some doing.
 

Juuhou

Sponsor

Yeah, I tried setting self.rt to nil but then ended up getting an error because I guess it had nothing to get nil from. =/

And about the items and skills, I was looking in the script but I couldnt see where to get the damage at. It had the hp and sp subtracting or adding all in one swoop like this:

Code:
      # The fluctuation decision of HP
      last_hp = [[self.hp - self.damage[user], self.maxhp].min, 0].max      # Effective decision
      effective |= self.hp != last_hp

So I put it under there and obviously, it didnt work since healing would reset it as well as the attacking skills. Then I put it in testing places around:

Code:
        # Setting the null line to the damage
        self.damage[user] = ""     
        # When there is no change in the state,
        unless @state_changed
          # Setting "Miss" to the damage
          self.damage[user] = "Miss"
        end
      end 
    # In case of miss
    else
      # Setting "Miss" to the damage
      self.damage[user] = "Miss"
    end
    # When it is not in the midst of fighting,
    unless $game_temp.in_battle
      # Setting nil to the damage
      self.damage[user] = nil
    end

But that just ended up not working...meh I think my logic is flawed when I saw self.damage. >_<
 
Looking at the Skills routine, they don't have a direct...

If...
else...
show 'Miss'
end


....routine. They have an extra 'if skill power is 0' inside, so I offer this for around like 2865:

Code:
      # When power 0 is,
      if skill.power == 0
        # Setting the null line to the damage
        self.damage[user] = ""
        # When there is no change in the state,
        unless @state_changed
          # Setting "Miss" to the damage
          self.damage[user] = "Miss"
        end
[B]      else
        self.at = 0
[/B]      end

Looks like the Item Damage code is a little more complex as you gotta see where physical damage (not SP damage or HP healing) is applied and tuck that li'l fella in there.
 

Juuhou

Sponsor

Yeah, I pretty much did what you did for the skills getting the else thing in there and it didnt work. T_T. but Im still at a loss of how to do the self.rt and as you said, the items damage is much more complicated. Although, I dont really mind as I probably won't be including item damage as a huge part of the game although figuring this out would still be good if others like what this is for. Meh, Ill keep looking.

EDIT: I tried the code you did which was different from what I did, and it still resets on a healing spell.

Oh wow, I found an error through all this too. If you have your bar full, and you get attacked...your at bar will reset but you can still select commands and stuff. Hmm...>_< Alot more complicated than it seemed. Ill experiment and see if I come up with anything.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top