Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Dark_Kyu09 on January 19, 2013, 08:43:09 pm

Title: [RESOLVED] [RMXP] Counterattack script
Post by: Dark_Kyu09 on January 19, 2013, 08:43:09 pm
Hello, everyone.
I'm looking for a particular script for the default battle system of the RPG Maker XP. You see, I'm trying to make an enemy who can counterattack.

How it would work



Scripts I'm using



Hope this is clear. So can anyone make the script here?
Title: Re: [RMXP] Counterattack script
Post by: KK20 on January 21, 2013, 12:41:36 am
I made a modification to this script I found through Google
Spoiler: ShowHide


#==========================================================================
# ** UL Counter Attack
#==========================================================================
# Uncle Lanzer
# Version 1
# 21.09.10
#==========================================================================
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# #  
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# #  
# #  You are free:
# #  
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# #  
# #  Under the following conditions:
# #  
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# #  
# #  Noncommercial. You may not use this work for commercial purposes.
# #  
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# #  
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# #  
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# #  
# #  - Nothing in this license impairs or restricts the author's moral rights.
# #  
# #----------------------------------------------------------------------------

#################
#               #  
# CONFIGURATION #
#               #
#################
# IT`S PRETTY SIMPLE........ JUST KILL THE BATMAN! <-- FORGET THAT -.-U
# MAKE A "(YOUR COUNTER NAME)" STATE
# UL_COUNTER_STATES = { A => [ B,C]}
# A = THE COUNTER STATE
# B = RATE OF SUCCESS
# C = STRENGHT OF COUNTER ( % OF A NORMAL ATTACK)
Scene_Battle::UL_Counter_States = { 20 => [100,100]} #ADD MORE BY THE SAME SYNTAX


# MESSAGGE WHEN COUNTER
Scene_Battle::UL_Counter_Messages = ['\m Counter!']

# CHECKING SCRIPT
if !@ul_counterattack_disabled

# START
class Game_Battler
   
 alias lanzer_counter_battler_atkeff attack_effect
 def attack_effect(attacker)
   lanzer_counter_battler_atkeff(attacker)
   if $scene.active_battler == attacker
     $scene.ul_atkcounter_test(self)
   end
 end
 
 alias counter_skill_attacks skill_effect
 def skill_effect(attacker, skill)
   counter_skill_attacks(attacker, skill)
   if $scene.active_battler == attacker and skill.power > 0
     $scene.ul_atkcounter_test(self)
   end
 end
 
end

class Scene_Battle
 attr_accessor :active_battler
 
 def ul_atkcounter_test(battler)
   # The actor is applied with a state that prevents movement. Stop counter.
   return unless battler.movable?
   
   ul_temp = UL_Counter_States.keys
   for i in 0...ul_temp.size
     if battler.state?(ul_temp[i])
       if UL_Counter_States[ul_temp[i]][0] > rand(99)
         @ul_counter = UL_Counter_States[ul_temp[i]][1]
         @ul_countertarget = battler
         return
       end
     end
   end
 end
 
 alias lanzer_counter_battle_up4s5 update_phase4_step5
 def update_phase4_step5
   lanzer_counter_battle_up4s5
   if @ul_countertarget != nil
     @phase4_step = 1337  # LEET
     @ul_atkcounter = 28
   end
 end
 
 def ul_counter_update
   if @ul_countertarget.dead? or @ul_atkcounter == 0 or !@ul_countertarget.movable?
     @ul_atkcounter = nil
     @ul_counter = nil
     @ul_countertarget = nil
     @phase4_step = 6
     return
   end
   @ul_atkcounter -= 1
   if @ul_atkcounter == 10
     @ul_countertarget.animation_id = @ul_countertarget.animation1_id
     @active_battler.animation_id = @ul_countertarget.animation2_id
     ul_temp = rand(UL_Counter_Messages.size)
     ul_temp = UL_Counter_Messages[ul_temp].clone
     ul_temp.gsub!(/\\[Mm]/) { @ul_countertarget.name }
     @help_window.set_text(ul_temp, 1)
     @active_battler.attack_effect(@ul_countertarget)
     if !@active_battler.damage.is_a?(String)
       @active_battler.hp += @active_battler.damage
       @active_battler.damage = @active_battler.damage * @ul_counter / 100
       @active_battler.hp -= @active_battler.damage
       @status_window.refresh
     end
     @active_battler.damage_pop = true
   end
 end
 
 alias lanzer_counter_battle_update update
 def update
   if @ul_atkcounter != nil
     ul_counter_update
   end
   lanzer_counter_battle_update
 end
end

#--------------------------------------------------------------------------#
end


Counters are made if applied with a counter state and are physically attacked or attacked with a skill that does damage (skill's power is greater than 0, so healing an ally won't trigger counter). If applied with a state with a restriction of Can't Move, counters cannot be made.
Title: Re: [RMXP] Counterattack script
Post by: Dark_Kyu09 on January 21, 2013, 01:58:13 am
Thanks for the script, but something's wrong here.

You see, I try it out in battle and when I use one of the party member's skill, it crashed. Then a message window pops out and said:

"Script "Full Reflection System" line 160: ArgumentError occurred.
wrong number of arguments (3 for 2)"

Is there anything that can be done?
Title: Re: [RMXP] Counterattack script
Post by: KK20 on January 21, 2013, 02:29:55 am
Try putting the counter script above the reflection script.

Edit: Worked for me.
Title: Re: [RESOLVED] [RMXP] Counterattack script
Post by: Dark_Kyu09 on January 26, 2013, 02:30:38 am
Thanks, KK20! It actually works :)
Title: Re: [RESOLVED] [RMXP] Counterattack script
Post by: finalholylight on February 02, 2013, 11:22:46 pm
Help me, error when I put it below RTAB system (by cogwheel)
"ArgumentError occurred. wrong number of arguments(1 or 0)"
in line (RTAB script):

    when 5
      update_phase4_step5(battler)

when I put above RTAB,it not working.
Title: Re: [RESOLVED] [RMXP] Counterattack script
Post by: KK20 on February 02, 2013, 11:33:20 pm
The script was designed with the default battle system in mind, as stated in the OP. Custom battle systems would most likely require edits. I think this should do it though.
Spoiler: ShowHide

#==========================================================================
# ** UL Counter Attack
#==========================================================================
# Uncle Lanzer
# Version 1
# 21.09.10
#==========================================================================
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------

#################
#               # 
# CONFIGURATION #
#               #
#################
# IT`S PRETTY SIMPLE........ JUST KILL THE BATMAN! <-- FORGET THAT -.-U
# MAKE A "(YOUR COUNTER NAME)" STATE
# UL_COUNTER_STATES = { A => [ B,C]}
# A = THE COUNTER STATE
# B = RATE OF SUCCESS
# C = STRENGHT OF COUNTER ( % OF A NORMAL ATTACK)
Scene_Battle::UL_Counter_States = { 20 => [100,100]} #ADD MORE BY THE SAME SYNTAX


# MESSAGGE WHEN COUNTER
Scene_Battle::UL_Counter_Messages = ['\m Counter!']

# CHECKING SCRIPT
if !@ul_counterattack_disabled

# START
class Game_Battler
   
  alias lanzer_counter_battler_atkeff attack_effect
  def attack_effect(attacker)
    lanzer_counter_battler_atkeff(attacker)
    if $scene.active_battler == attacker
      $scene.ul_atkcounter_test(self)
    end
  end
 
  alias counter_skill_attacks skill_effect
  def skill_effect(attacker, skill)
    counter_skill_attacks(attacker, skill)
    if $scene.active_battler == attacker and skill.power > 0
      $scene.ul_atkcounter_test(self)
    end
  end
 
end

class Scene_Battle
  attr_accessor :active_battler
 
  def ul_atkcounter_test(battler)
    # The actor is applied with a state that prevents movement. Stop counter.
    return unless battler.movable?
   
    ul_temp = UL_Counter_States.keys
    for i in 0...ul_temp.size
      if battler.state?(ul_temp[i])
        if UL_Counter_States[ul_temp[i]][0] > rand(99)
          @ul_counter = UL_Counter_States[ul_temp[i]][1]
          @ul_countertarget = battler
          return
        end
      end
    end
  end
 
  alias lanzer_counter_battle_up4s5 update_phase4_step5
  def update_phase4_step5(battler)
    lanzer_counter_battle_up4s5(battler)
    if @ul_countertarget != nil
      @phase4_step = 1337  # LEET
      @ul_atkcounter = 28
    end
  end
 
  def ul_counter_update
    if @ul_countertarget.dead? or @ul_atkcounter == 0 or !@ul_countertarget.movable?
      @ul_atkcounter = nil
      @ul_counter = nil
      @ul_countertarget = nil
      @phase4_step = 6
      return
    end
    @ul_atkcounter -= 1
    if @ul_atkcounter == 10
      @ul_countertarget.animation_id = @ul_countertarget.animation1_id
      @active_battler.animation_id = @ul_countertarget.animation2_id
      ul_temp = rand(UL_Counter_Messages.size)
      ul_temp = UL_Counter_Messages[ul_temp].clone
      ul_temp.gsub!(/\\[Mm]/) { @ul_countertarget.name }
      @help_window.set_text(ul_temp, 1)
      @active_battler.attack_effect(@ul_countertarget)
      if !@active_battler.damage.is_a?(String)
        @active_battler.hp += @active_battler.damage
        @active_battler.damage = @active_battler.damage * @ul_counter / 100
        @active_battler.hp -= @active_battler.damage
        @status_window.refresh
      end
      @active_battler.damage_pop = true
    end
  end
 
  alias lanzer_counter_battle_update update
  def update
    if @ul_atkcounter != nil
      ul_counter_update
    end
    lanzer_counter_battle_update
  end
end

#--------------------------------------------------------------------------#
end

Try putting this below your RTAB script.
Title: Re: [RESOLVED] [RMXP] Counterattack script
Post by: finalholylight on February 02, 2013, 11:56:38 pm
Sorry for disturb you again, it not working :(
Title: Re: [RESOLVED] [RMXP] Counterattack script
Post by: KK20 on February 03, 2013, 12:05:23 am
Well then clearly the two scripts are not compatible. And I can't work off of "it's not working"--I don't know what to address.