I was looking for a script for CNT state that changes what skills can be countered. Right now, all that can be countered is "Attack", but I have made enemies have abilities such as "Attack +" or "Sneak Attack" which I also want the player to be able to counter. But, I haven't found a script that will let me do that. Anyone know what I can do?
Counter Attack script for which skills can be countered
RGSS3 Script RequestsThe Scripts forum is where you post scripts you have written and which you want to share with others.
Moved to: RGSS3 Script Requests
Moved to: RGSS3 Script Requests
Hm, Attack is a physical skill by default. Marking a skill as physical or magical will alter damage through the appropriate resistance or accuracy, plus whatever states and features alter them. For a physical attack, they are affected by CNT as shown below:
As you can see, it will return the counterattack rate, but only if the attack is physical and if the self.opposite?(user of skill) is not one of your allies, so you shouldn't have to worry about countering a confused target.
Now, I'm assuming your Attack + is not physical at the moment, but in case it is, or if you only want the Attack group to counter and not Physical Sword Dances, here's an example of what you can do:
You could use return 0 unless item.id == 1 or item.id == 100 or item. id == 101 but I figured an array would be more organized.
Code:
class Game_Battler < Game_BattlerBase
def item_cnt(user, item)
return 0 unless item.physical? # Hit type is not physical
return 0 unless opposite?(user) # No counterattack on allies
return cnt # Return counterattack rate
end
end
As you can see, it will return the counterattack rate, but only if the attack is physical and if the self.opposite?(user of skill) is not one of your allies, so you shouldn't have to worry about countering a confused target.
Now, I'm assuming your Attack + is not physical at the moment, but in case it is, or if you only want the Attack group to counter and not Physical Sword Dances, here's an example of what you can do:
Code:
class Game_Battler < Game_BattlerBase
def item_cnt(user, item)
skills_to_counter = [1, 100, 101] # ID of skills to be countered. You can change this
return 0 unless skills_to_counter.include? item.id #Only skills from above array will be considered for countering.
return 0 unless opposite?(user) # No counterattack on allies
return cnt # Return counterattack rate
end
end
@Harosata
Thanks for the script but I must not be using it right, because the skills I put in the array are not being countered. I even changed them to Physical like you said. Not sure what is up.
Thanks for the script but I must not be using it right, because the skills I put in the array are not being countered. I even changed them to Physical like you said. Not sure what is up.
class Game_Battler < Game BattlerBase
def item_cnt(user, item)
skills_to_counter = [1, 154, 155, 156, 160, 161] # ID of skills to be countered. You can change this
return 0 unless skills_to_counter.include? item.id #Only skills from above array will be considered for countering.
return 0 unless opposite?(user) # No counterattack on allies
return cnt # Return counterattack rate
end
end
def item_cnt(user, item)
skills_to_counter = [1, 154, 155, 156, 160, 161] # ID of skills to be countered. You can change this
return 0 unless skills_to_counter.include? item.id #Only skills from above array will be considered for countering.
return 0 unless opposite?(user) # No counterattack on allies
return cnt # Return counterattack rate
end
end
@Rokazulu
Not to insult your intelligence, but you have given the battler that should be countering a counterattack chance trait, right?
Not to insult your intelligence, but you have given the battler that should be countering a counterattack chance trait, right?
I want the players to counter the battler's attack. What chance trait do you mean? I may have missed something.
A battler won't counterattack unless it's been given the trait "Counter Attack" in Ex-Parameters and it's set to a percentage higher than 0.
The skills I created are for the battler that I want the actor or character players to be able to counter-attack. I don't need the battler to counterattack anything.
Okay, but you've made the actor/characters able to counterattack with a trait, yes? Or am I misunderstanding what you're trying to do here?
Okay, let's clarify a few things:
CNT for any battler by default is at 0. What I scripted earlier assumes you have given a character, armor or state some value of CNT. However, it seems that you have a few more conditions that I was not aware of...
Here's the modified item_cnt to take this into account:
This is what I read and got: The battler/enemy will not counter. If the skill's id is among what's in the array, it will always counter. And for everything else, it will not be countered. Once you're done testing, you can change the 1.0 to anything between that and 0 to simulate chance. Alternatively, you can just forget the array and and list the attacks like
return 0.8 if item.id == 1
return 0.5 if item.id == 154
if you want Attack to have 80% of counterattacking and that other attack to have 50% chance of countering.
CNT for any battler by default is at 0. What I scripted earlier assumes you have given a character, armor or state some value of CNT. However, it seems that you have a few more conditions that I was not aware of...
Here's the modified item_cnt to take this into account:
Code:
class Game_Battler < Game_BattlerBase
def item_cnt(user, item)
skills_to_counter = [1, 100, 101]
return 0 if self.enemy?
return 0 unless opposite?(user)
return cnt if skills_to_counter.include? item.id
return 0
end
end
This is what I read and got: The battler/enemy will not counter. If the skill's id is among what's in the array, it will always counter. And for everything else, it will not be countered. Once you're done testing, you can change the 1.0 to anything between that and 0 to simulate chance. Alternatively, you can just forget the array and and list the attacks like
return 0.8 if item.id == 1
return 0.5 if item.id == 154
if you want Attack to have 80% of counterattacking and that other attack to have 50% chance of countering.
Not sure what is up but I tried your new script and it is still not working.
I am indeed applying the counterattack state to the actors (players) via a skill. And then letting the battler (enemy) attack with an attack which is located within the array, but it isn't being countered.
I am indeed applying the counterattack state to the actors (players) via a skill. And then letting the battler (enemy) attack with an attack which is located within the array, but it isn't being countered.
I just tested my script and this was what I got:
-Player attacks enemy, enemy does not counter.
-Enemy attacks player, player counters and deals damage.
-My script uses 1.0 in place of cnt, so it should always return a counter.
-Skills not in the array like Firebreath are not countered.
I tested this script in two separate games with different amounts of scripts...and I think I know what the problem might be. It's because I forgot the underscore in Game_BattlerBase. This is corrected now.
However, if you caught that mistake already and still can't counter, the only other issue I can think of is that there is another script you have that is altering how item_cnt is accessed. Anyway, the posts here have been edited to include the underscore, so let's see if it was just my error.
Also, this is my first time Countering, so now I notice that Counter means that the player doesn't get damage but instead attacks the enemy back.
-Player attacks enemy, enemy does not counter.
-Enemy attacks player, player counters and deals damage.
-My script uses 1.0 in place of cnt, so it should always return a counter.
-Skills not in the array like Firebreath are not countered.
I tested this script in two separate games with different amounts of scripts...and I think I know what the problem might be. It's because I forgot the underscore in Game_BattlerBase. This is corrected now.
However, if you caught that mistake already and still can't counter, the only other issue I can think of is that there is another script you have that is altering how item_cnt is accessed. Anyway, the posts here have been edited to include the underscore, so let's see if it was just my error.
Also, this is my first time Countering, so now I notice that Counter means that the player doesn't get damage but instead attacks the enemy back.
Yeah, I already had the class at Game_BattlerBase because that was already within the code. (I put your code in the Game_Battler area of the script under Game Objects).
Yeah, counter "reflects" the damage basically. Also, when I use the magic reflect skill, for example, it works perfectly because any magic attack is reflected no matter what. For whatever reason every physical attack is not countered with the counter attack skill :rsad:.
However, counterattack works perfectly IF, and only IF the enemy uses the basic "attack". Which is 1 on the array in your code. I'm toodling around with it, but can't find an answer so I appreciate your help.
This code is in my AceBattleEngine. Will this affect your code?
Yeah, counter "reflects" the damage basically. Also, when I use the magic reflect skill, for example, it works perfectly because any magic attack is reflected no matter what. For whatever reason every physical attack is not countered with the counter attack skill :rsad:.
However, counterattack works perfectly IF, and only IF the enemy uses the basic "attack". Which is 1 on the array in your code. I'm toodling around with it, but can't find an answer so I appreciate your help.
This code is in my AceBattleEngine. Will this affect your code?
#overwite method: invoke_counter_attack
def invoke_counter_attack(target, item)
@log_window.display_counter(target, item)
attack_skill = $data_skills[target.attack_skill_id]
@subject.item_apply(target, attack_skill) status_redraw_target(@subject) status_redraw_target(target) unless target == @subject @log_window.display_action_results(@subject, attack_skill) perform_collapse_check(target) perform_collapse_check(@subject) end "]
def invoke_counter_attack(target, item)
@log_window.display_counter(target, item)
attack_skill = $data_skills[target.attack_skill_id]
@subject.item_apply(target, attack_skill) status_redraw_target(@subject) status_redraw_target(target) unless target == @subject @log_window.display_action_results(@subject, attack_skill) perform_collapse_check(target) perform_collapse_check(@subject) end "]
invoke_item is coded by default to invoke a counterattack, magic reflection, or apply the skill. Note how counterattack doesn't automatically include applying the skill. If it was a default battle system, I can place
so that skills can hit and will counter unless you were killed.
---
I tried my code again to be sure, using Attack and Fireball's id. Those two skills get countered while a skill not in the list is not countered.
No. item_cnt is only used in invoke_item to determine if the player counterattacks using invoke_counter_attack. I checked Ace Battle Engine and invoke_item uses an alias, so it doesn't overwrite anything related to cnt. I just placed Ace Battle Engine in an empty project to be sure and placed my script before and after the Engine.
(This is assuming that what you posted is sorted like the Engine I downloaded and not a copy-paste "autocorrect").
---
Hm...I know the code works as it should be (and my code doesn't need the "physical" Hit Type to work). However, I notice you said you placed my code inside the Game_Battler UNDER the Game Objects. It's an unspoken rule to place user-created scripts under Materials and pretty much avoid making changes to the default Game Objects and Scenes. When the code is executed, the later versions of the methods are executed (unless they use an alias). For example, if I have an item_cnt scriptlet under Materials that only makes a chicken dance, the chicken will dance because the default item_cnt in the Game Objects/Game_Battler was overwritten.
I can only think of two scenarios that my item_cnt doesn't work. The first is placing the script before another item_cnt, so please tell me you didn't place that on TOP of the Game_Battler script and kept the original (if you don't have any other custom item_cnt scripts) The second scenario is if you have an item_invoke that wrote out item_cnt; Ace Battle Engine uses an alias for this so it doesn't write out that part.
---
...Just to clarify what you mean by countering, do you mean:
-Enemy hits player with Attack+ or Sneak Attack, player counters with Attack
or
-Enemy hits player with any physical skill, player counters with Attack+ or Sneak Attack
Because I assumed you meant "skills that trigger a counterattack". If you were actually talking about the second, that is more of "counterattacking using those skills". If it is the second, you would want to change some parts in invoke_counter_attack, namely attack_skill = $data_skills[target.attack_skill_id] and replace target.attack_skill_id with the id of the desired skill or a random id from an array like [1, 100, 101].sample
Code:
class Scene_Battle < Scene_Base
def invoke_item(target, item)
if rand < target.item_cnt(@subject, item)
apply_item_effects(apply_substitute(target, item), item)
invoke_counter_attack(target, item) if target.alive?
elsif rand < target.item_mrf(@subject, item)
invoke_magic_reflection(target, item)
else
apply_item_effects(apply_substitute(target, item), item)
end
@subject.last_target_index = target.index
end
end
so that skills can hit and will counter unless you were killed.
---
I tried my code again to be sure, using Attack and Fireball's id. Those two skills get countered while a skill not in the list is not countered.
No. item_cnt is only used in invoke_item to determine if the player counterattacks using invoke_counter_attack. I checked Ace Battle Engine and invoke_item uses an alias, so it doesn't overwrite anything related to cnt. I just placed Ace Battle Engine in an empty project to be sure and placed my script before and after the Engine.
(This is assuming that what you posted is sorted like the Engine I downloaded and not a copy-paste "autocorrect").
---
Hm...I know the code works as it should be (and my code doesn't need the "physical" Hit Type to work). However, I notice you said you placed my code inside the Game_Battler UNDER the Game Objects. It's an unspoken rule to place user-created scripts under Materials and pretty much avoid making changes to the default Game Objects and Scenes. When the code is executed, the later versions of the methods are executed (unless they use an alias). For example, if I have an item_cnt scriptlet under Materials that only makes a chicken dance, the chicken will dance because the default item_cnt in the Game Objects/Game_Battler was overwritten.
I can only think of two scenarios that my item_cnt doesn't work. The first is placing the script before another item_cnt, so please tell me you didn't place that on TOP of the Game_Battler script and kept the original (if you don't have any other custom item_cnt scripts) The second scenario is if you have an item_invoke that wrote out item_cnt; Ace Battle Engine uses an alias for this so it doesn't write out that part.
---
...Just to clarify what you mean by countering, do you mean:
-Enemy hits player with Attack+ or Sneak Attack, player counters with Attack
or
-Enemy hits player with any physical skill, player counters with Attack+ or Sneak Attack
Because I assumed you meant "skills that trigger a counterattack". If you were actually talking about the second, that is more of "counterattacking using those skills". If it is the second, you would want to change some parts in invoke_counter_attack, namely attack_skill = $data_skills[target.attack_skill_id] and replace target.attack_skill_id with the id of the desired skill or a random id from an array like [1, 100, 101].sample
Hold on, I got the counter-attack to work for the skills but now they counter attack even if the CNT state isn't applied onto the player characters.
All I did was add your code under the materials section.
All I did was add your code under the materials section.
Okay, now that the script works, we can get around to working on the script itself. The script used 1.0 for 100% cnt, so you can replace that number with cnt if you want to use the number from the state.
Just to check again, this is the script you want, or did I misread it?
Just to check again, this is the script you want, or did I misread it?
Yeah it's working how it should be except for what I mentioned before.
I replaced the 1.0 with cnt and it is still responding the same way, countering every skill within the array despite the actor having the CNT state applied.
I replaced the 1.0 with cnt and it is still responding the same way, countering every skill within the array despite the actor having the CNT state applied.
I assume your current problem is that the skills in the array are ALWAYS being countered regardless of the cnt percent.
Tested the script after replacing 1.0 with cnt and also lowered Counterattack state's cnt to 10%. Having the cnt not at 100% shows that it is possible for the skill in the array NOT to counterattack.
The only thing I can think of that could make the code act like 1.0 and not cnt is that you haven't saved the project. VX Ace sometimes needs to be saved to update the scripts, though there are some projects that need to be quit and loaded up. I also added return 0 unless opposite?(user) because I just realized that without this, the counterattack can activate if a player character hits a member of their team due to confusion. Anyway, I hope the issue was just rushing things.
Tested the script after replacing 1.0 with cnt and also lowered Counterattack state's cnt to 10%. Having the cnt not at 100% shows that it is possible for the skill in the array NOT to counterattack.
The only thing I can think of that could make the code act like 1.0 and not cnt is that you haven't saved the project. VX Ace sometimes needs to be saved to update the scripts, though there are some projects that need to be quit and loaded up. I also added return 0 unless opposite?(user) because I just realized that without this, the counterattack can activate if a player character hits a member of their team due to confusion. Anyway, I hope the issue was just rushing things.
Yep, that was it. Just didn't save.
Now it seems to be working perfectly. Thanks for the help @Harosata !
Now it seems to be working perfectly. Thanks for the help @Harosata !
Original thread: https://forums.rpgmakerweb.com/threads/counter-attack-script-for-which-skills-can-be-countered.75485/