Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> 


———
Before you ask! Read! ;)

You must have 30+ Posts to create a topic here!

Thanks for reading!
———

 
Reply to this topicStart new topic
> Counter Attack Script
Deividdo
post Jan 22 2012, 01:04 AM
Post #1


Level 2
Group Icon

Group: Member
Posts: 15
Type: None
RM Skill: Beginner




Hello,

I am looking for a basic RPG Maker XP Counter Attack script. I'm not hoping for anything fancy, but simply to have a character counter with a normal attack after being attacked by an enemy. I have looked around and haven't found any functional scripts for XP, which I find surprising since I thought this would be a rather common request.

My current project is using the Tankentai system, but if I had a basic counter attack that worked with the default system I believe I could make that compatible.

Thank you.
Go to the top of the page
 
+Quote Post
   
Jens of Zanicuud
post Jan 22 2012, 04:17 AM
Post #2


Dark Jentleman
Group Icon

Group: Local Mod
Posts: 904
Type: Scripter
RM Skill: Skilled
Rev Points: 120




I could build it, but I need some additional info.

1. Counterattack is triggered by an equipped item? Or a status? Or maybe there's a character who counterattacks by default?
2. Enemies should counterattack too?

Jens

This post has been edited by Jens of Zanicuud: Jan 22 2012, 04:18 AM


__________________________
"Thorns are the rose's sweetest essence..."
-Jens of Zanicuud


Games I'm working on:
>

official website: TryAdIne eFfeCt

>

Games I worked on (mainly as a scripter):
>
(Warning: it's a 3rr3's project and it's in Italian!)


Awards

Go to the top of the page
 
+Quote Post
   
Jens of Zanicuud
post Jan 22 2012, 04:57 AM
Post #3


Dark Jentleman
Group Icon

Group: Local Mod
Posts: 904
Type: Scripter
RM Skill: Skilled
Rev Points: 120




Nevermind, here's the script.
I think it's not compatible with Tankentai, but I hope you can rearrange it...

CODE
#==============================================================================
#=#============================================================================
# #** Jens of Zanicuud counterattack script v 1.0
# #   -free use, just credit
# #   -free customization, however, posting on RRR the modified version is
# #    mandatory
# #   -you can find me on www.rpgrevoultion.com
#=#============================================================================
#==============================================================================

#==============================================================================
# ** Constants
#==============================================================================

COUNTERATTACK_ENEMY_ID   = []   #id of enemies counter attacking by default
COUNTERATTACK_WEAPON_ID  = []   #id of weapons triggering counters
COUNTERATTACK_ARMOR_ID   = []   #id of armors triggering counters
COUNTERATTACK_STATUS_ID  = []   #id of status triggering counters
COUNTERATTACK_HERO_ID    = []   #id of heroes counter attacking by default

#==============================================================================
# ** Game_BattleAction
#==============================================================================
class Game_BattleAction
  attr_accessor :counter
  #--------------------------------------------------------------------------
  # * aliases
  #--------------------------------------------------------------------------
  alias joz3_counterattack_initialize initialize
  alias joz3_counterattack_clear      clear
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  def initialize
    joz3_counterattack_initialize
    @counter = false
  end
  #--------------------------------------------------------------------------
  # * Clear
  #--------------------------------------------------------------------------
  def clear
    joz3_counterattack_clear
    @counter = false
  end
end

#==============================================================================
# ** Game_Battler
#==============================================================================
class Game_Battler
  #--------------------------------------------------------------------------
  # * Store_Action
  #--------------------------------------------------------------------------
  def store_action
    @backup_action = self.current_action
  end
  #--------------------------------------------------------------------------
  # * Restore_Action
  #--------------------------------------------------------------------------
  def restore_action
    if @backup_action != nil
    @current_action = @backup_action
    end
  end
  #--------------------------------------------------------------------------
  # * Prepare Counterattack
  #--------------------------------------------------------------------------
  def prepare_counterattack(index)
    store_action
    @current_action.kind         = 0
    @current_action.basic        = 0
    @current_action.target_index = index
    @current_action.counter      = true
  end
  #--------------------------------------------------------------------------
  # * Can_Counterattack?
  #--------------------------------------------------------------------------
  def can_counterattack?
    #hp check
    if self.hp0?
      return false
    end
    #input check
    if !self.inputable?
      return false
    end
    #status check
    for id in COUNTERATTACK_STATUS_ID
    if self.state?(id)
      return true
    end
    end
    return false
  end
end

#==============================================================================
# ** Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Can_Counterattack?
  #--------------------------------------------------------------------------
  def can_counterattack?
    #hero check
    if COUNTERATTACK_HERO_ID.include?(self.id)
      return true
    end
    #weapon check
    if COUNTERATTACK_WEAPON_ID.include?(@weapon_id)
      return true
    end
    #armor check
    if COUNTERATTACK_ARMOR_ID.include?(@armor1_id) or
       COUNTERATTACK_ARMOR_ID.include?(@armor2_id) or
       COUNTERATTACK_ARMOR_ID.include?(@armor3_id) or
       COUNTERATTACK_ARMOR_ID.include?(@armor4_id)
      return true
    end
    super
  end
end

#==============================================================================
# ** Game_Enemy
#==============================================================================
class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Can_Counterattack?
  #--------------------------------------------------------------------------
  def can_counterattack?
    #id check
    if COUNTERATTACK_ENEMY_ID.include?(self.id)
      return true
    end
    super
  end
end

#==============================================================================
# ** Scene_Battle (part 4)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================
class Scene_Battle

  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 3 : animation for action performer)
  #--------------------------------------------------------------------------
  def update_phase4_step3
    # Animation for action performer (if ID is 0, then white flash)
    if @active_battler.current_action.counter
      @help_window.set_text(@active_battler.name + ": Counter Attack!", 1)
    end
    if @animation1_id == 0
      @active_battler.white_flash = true
    else
      @active_battler.animation_id = @animation1_id
      @active_battler.animation_hit = true
    end
    # Shift to step 4
    @phase4_step = 4
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 4 : animation for target)
  #--------------------------------------------------------------------------
  def update_phase4_step4
    # Animation for target
    for target in @target_battlers
      target.animation_id = @animation2_id
      target.animation_hit = (target.damage != "Miss")
    end
    if @active_battler.current_action.kind == 0 and
      @active_battler.current_action.basic == 0 and
      @active_battler.current_action.counter == false
      target = @target_battlers[0]
      if target.can_counterattack?
        target.prepare_counterattack(@active_battler.index)
        @counterattack_flag = true
      end
    end
    # Animation has at least 8 frames, regardless of its length
    @wait_count = 8
    # Shift to step 5
    @phase4_step = 5
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 5 : damage display)
  #--------------------------------------------------------------------------
  def update_phase4_step5
    # Hide help window
    @help_window.visible = false
    # Refresh status window
    @status_window.refresh
    # Display damage
    for target in @target_battlers
      if target.damage != nil
        target.damage_pop = true
      end
    end
    # Shift to step 6
    @phase4_step = 6
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 6 : refresh)
  #--------------------------------------------------------------------------
  def update_phase4_step6
    # Clear battler being forced into action
    if @counterattack_flag
     counter_update
     return
    end
    if @active_battler.current_action.counter
     @active_battler.restore_action
     @active_battler.current_action.counter = false
    end
    $game_temp.forcing_battler = nil
    # If common event ID is valid
    if @common_event_id > 0
      # Set up event
      common_event = $data_common_events[@common_event_id]
      $game_system.battle_interpreter.setup(common_event.list, 0)
    end
    # Shift to step 1
    @phase4_step = 1
  end
  #--------------------------------------------------------------------------
  # * Counter Update
  #--------------------------------------------------------------------------
  def counter_update
    @counterattack_flag = false
    # Initialize animation ID and common event ID
    @animation1_id = 0
    @animation2_id = 0
    @common_event_id = 0
    # Shift from head of actionless battlers
    @active_battler = @target_battlers[0]
    # If already removed from battle
    # Natural removal of states
    @active_battler.remove_states_auto
    # Refresh status window
    @status_window.refresh
    # Shift to step 2
    @phase4_step = 2
  end
end


HOW TO USE:
Just set the constants...

e.g.

COUNTERATTACK_ENEMY_ID = [1,3,7] #id of enemies counter attacking by default
COUNTERATTACK_WEAPON_ID = [2,12] #id of weapons triggering counters
COUNTERATTACK_ARMOR_ID = [10,14] #id of armors triggering counters
COUNTERATTACK_STATUS_ID = [1,6] #id of status triggering counters
COUNTERATTACK_HERO_ID = [9] #id of heroes counter attacking by default

Ask for troubleshooting anytime.

Jens

This post has been edited by Jens of Zanicuud: Jan 22 2012, 04:59 AM


__________________________
"Thorns are the rose's sweetest essence..."
-Jens of Zanicuud


Games I'm working on:
>

official website: TryAdIne eFfeCt

>

Games I worked on (mainly as a scripter):
>
(Warning: it's a 3rr3's project and it's in Italian!)


Awards

Go to the top of the page
 
+Quote Post
   
Deividdo
post Jan 22 2012, 02:52 PM
Post #4


Level 2
Group Icon

Group: Member
Posts: 15
Type: None
RM Skill: Beginner




Thank you very much, Jens! ^_^ This works wonderfully and is just what I wanted.

As expected, it wasn't compatible with Atoa's XP Tankentai. So I added a portion of your code to the following Tankentai method to correct this allowing counterattacking to work.

CODE
  alias update_phase4_step6_n01 update_phase4_step6
  def update_phase4_step6
    #======================================================================
    #This is the code that was added for the Counter Attack.
    if @active_battler.current_action.counter
      @help_window.set_text(@active_battler.name + ": Counter Attack!", 1)
    end
    if @active_battler.current_action.kind == 0 and
      @active_battler.current_action.basic == 0 and
      @active_battler.current_action.counter == false
      target = @target_battlers[0]
      if target.can_counterattack?
        target.prepare_counterattack(@active_battler.index)
        @counterattack_flag = true
      end
    end    
    #======================================================================
    update_phase4_step6_n01
    @active_battler.active = false if @active_battler != nil
  end


My project is using the CTB extension, but I had to remove that in order to get counterattacking to work with the normal Tankentai. Once I figure out how to fix that I'll post that too for anyone who might be curious.
Go to the top of the page
 
+Quote Post
   
Wonderjosh
post Mar 9 2012, 02:10 PM
Post #5


Level 3
Group Icon

Group: Member
Posts: 33
Type: Artist
RM Skill: Undisclosed




Hopefully the topic's not too old to comment on, but I found that if a character is confused and attacks another character, the attacked character retaliates against an enemy rather than the attacking character. Any way to adjust this? Maybe just so the attacked party member doesn't retaliate against the attacking party member.

This post has been edited by Wonderjosh: Mar 9 2012, 03:02 PM
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Mar 12 2012, 05:55 AM
Post #6


Level 50
Group Icon

Group: +Gold Member
Posts: 1,523
Type: Scripter
RM Skill: Undisclosed




This script should make it so party member's cannot counterattack other party members

CODE
#==============================================================================
#=#============================================================================
# #**� Jens of Zanicuud counterattack script v 1.0
# #   -free use, just credit
# #   -free customization, however, posting on RRR the modified version is
# #    mandatory
# #   -you can find me on www.rpgrevoultion.com
#=#============================================================================
#==============================================================================

#==============================================================================
# ** Constants
#==============================================================================

COUNTERATTACK_ENEMY_ID   = []   #id of enemies counter attacking by default
COUNTERATTACK_WEAPON_ID  = []   #id of weapons triggering counters
COUNTERATTACK_ARMOR_ID   = []   #id of armors triggering counters
COUNTERATTACK_STATUS_ID  = []   #id of status triggering counters
COUNTERATTACK_HERO_ID    = []   #id of heroes counter attacking by default

#==============================================================================
# ** Game_BattleAction
#==============================================================================
class Game_BattleAction
  attr_accessor :counter
  #--------------------------------------------------------------------------
  # * aliases
  #--------------------------------------------------------------------------
  alias joz3_counterattack_initialize initialize
  alias joz3_counterattack_clear      clear
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  def initialize
    joz3_counterattack_initialize
    @counter = false
  end
  #--------------------------------------------------------------------------
  # * Clear
  #--------------------------------------------------------------------------
  def clear
    joz3_counterattack_clear
    @counter = false
  end
end

#==============================================================================
# ** Game_Battler
#==============================================================================
class Game_Battler
  #--------------------------------------------------------------------------
  # * Store_Action
  #--------------------------------------------------------------------------
  def store_action
    @backup_action = self.current_action
  end
  #--------------------------------------------------------------------------
  # * Restore_Action
  #--------------------------------------------------------------------------
  def restore_action
    if @backup_action != nil
    @current_action = @backup_action
    end
  end
  #--------------------------------------------------------------------------
  # * Prepare Counterattack
  #--------------------------------------------------------------------------
  def prepare_counterattack(index)
    store_action
    @current_action.kind         = 0
    @current_action.basic        = 0
    @current_action.target_index = index
    @current_action.counter      = true
  end
  #--------------------------------------------------------------------------
  # * Can_Counterattack?
  #--------------------------------------------------------------------------
  def can_counterattack?
    #hp check
    if self.hp0?
      return false
    end
    #input check
    if !self.inputable?
      return false
    end
    #status check
    for id in COUNTERATTACK_STATUS_ID
    if self.state?(id)
      return true
    end
    end
    return false
  end
end

#==============================================================================
# ** Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Can_Counterattack?
  #--------------------------------------------------------------------------
  def can_counterattack?
    #hero check
    if COUNTERATTACK_HERO_ID.include?(self.id)
      return true
    end
    #weapon check
    if COUNTERATTACK_WEAPON_ID.include?(@weapon_id)
      return true
    end
    #armor check
    if COUNTERATTACK_ARMOR_ID.include?(@armor1_id) or
       COUNTERATTACK_ARMOR_ID.include?(@armor2_id) or
       COUNTERATTACK_ARMOR_ID.include?(@armor3_id) or
       COUNTERATTACK_ARMOR_ID.include?(@armor4_id)
      return true
    end
    super
  end
end

#==============================================================================
# ** Game_Enemy
#==============================================================================
class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Can_Counterattack?
  #--------------------------------------------------------------------------
  def can_counterattack?
    #id check
    if COUNTERATTACK_ENEMY_ID.include?(self.id)
      return true
    end
    super
  end
end

#==============================================================================
# ** Scene_Battle (part 4)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================
class Scene_Battle

  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 3 : animation for action performer)
  #--------------------------------------------------------------------------
  def update_phase4_step3
    # Animation for action performer (if ID is 0, then white flash)
    if @active_battler.current_action.counter
      @help_window.set_text(@active_battler.name + ": Counter Attack!", 1)
    end
    if @animation1_id == 0
      @active_battler.white_flash = true
    else
      @active_battler.animation_id = @animation1_id
      @active_battler.animation_hit = true
    end
    # Shift to step 4
    @phase4_step = 4
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 4 : animation for target)
  #--------------------------------------------------------------------------
  def update_phase4_step4
    # Animation for target
    for target in @target_battlers
      target.animation_id = @animation2_id
      target.animation_hit = (target.damage != "Miss")
    end
    if @active_battler.current_action.kind == 0 and
      @active_battler.current_action.basic == 0 and
      @active_battler.current_action.counter == false
      target = @target_battlers[0]
      if target.can_counterattack?
        if not (@active_battler.is_a?(Game_Actor) and target.is_a?(Game_Actor))
          target.prepare_counterattack(@active_battler.index)
          @counterattack_flag = true
        end
      end
    end
    # Animation has at least 8 frames, regardless of its length
    @wait_count = 8
    # Shift to step 5
    @phase4_step = 5
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 5 : damage display)
  #--------------------------------------------------------------------------
  def update_phase4_step5
    # Hide help window
    @help_window.visible = false
    # Refresh status window
    @status_window.refresh
    # Display damage
    for target in @target_battlers
      if target.damage != nil
        target.damage_pop = true
      end
    end
    # Shift to step 6
    @phase4_step = 6
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 6 : refresh)
  #--------------------------------------------------------------------------
  def update_phase4_step6
    # Clear battler being forced into action
    if @counterattack_flag
     counter_update
     return
    end
    if @active_battler.current_action.counter
     @active_battler.restore_action
     @active_battler.current_action.counter = false
    end
    $game_temp.forcing_battler = nil
    # If common event ID is valid
    if @common_event_id > 0
      # Set up event
      common_event = $data_common_events[@common_event_id]
      $game_system.battle_interpreter.setup(common_event.list, 0)
    end
    # Shift to step 1
    @phase4_step = 1
  end
  #--------------------------------------------------------------------------
  # * Counter Update
  #--------------------------------------------------------------------------
  def counter_update
    @counterattack_flag = false
    # Initialize animation ID and common event ID
    @animation1_id = 0
    @animation2_id = 0
    @common_event_id = 0
    # Shift from head of actionless battlers
    @active_battler = @target_battlers[0]
    # If already removed from battle
    # Natural removal of states
    @active_battler.remove_states_auto
    # Refresh status window
    @status_window.refresh
    # Shift to step 2
    @phase4_step = 2
  end
end


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2013 - 02:26 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker