Counterattack after receiving damage (W/O Scripts or Plugins)

StatiZkyZ

Villager
Member
Joined
Oct 25, 2019
Messages
7
Reaction score
0
First Language
Indonesian
Primarily Uses
RMVXA
Hello, first of all, I'm sorry if a thread like this already exist and I'm unaware of it...

I'm trying to make a skill that acts like a counterattack, but it happens after the user got hit by an enemy attack. To simplify, the fight will go:

-) User uses a skill that allows them to counterattack
-) Enemy attacks User
-) User receives damage from enemy attack
-) User will immediately counterattack the enemy that attacks them

To this, I have made the following:

-) Created a 'Shield' skill to give the user a 'Shielded' state.
-) Created a battle event with the conditional branch "If user state = 'Shielded', then it'll force action user to use 'Counter' at the enemy that attacks him the most recent.
-) Set the battle event's span to 'moment' so the 'Counter' skill will be used each time an enemy attacks the user.
-) I've made a second battle event that forces the user to use the 'Shield' spell at the beginning of the battle, at turn 0

But, things really don't go well. Instead of getting what I want, these happened instead. With the 'Don't Run' condition in the first battle event, it never worked. I tried to set the condition 'If user have less then 99% HP', but what I got is the user using the 'Counter' skill ENDLESSLY on the enemy at the first index, even though I choose 'last target' at the force action (The enemy at the second index is the first one that damages the user)

I guess my first question is, what is the optimal trigger I should put in the first battle event? Second, how do you make the user only use the skill only once? And third, how do you make sure that the 'Counter' skill get used on the enemy that attacks the user most recently?

I'm hoping I can do it without having to resort to scripts or plugins, since I have ZERO experience with it and have no idea how to use them.

Thank you for reading my wall of text, I hope someone can help me~
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
Afraid this requires a plugin as the default counterattack attacks before you are hit and your hit never hits so you'll need to override them.

Now if you dont use cnt for counterattack then there might be a workaround but if you do use cnt for it then a script is needed
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
I didn't make this, but i found it somewhere. The second counter type doesn't work, but the third is what your looking for and works

# 1224Deko - Hamedo miniscript v1.00
#
# This script overrides Scene_Battle and def invoke_item in it.
# No credits needed.
# Inspired from this thread:
# http://www.rpgmakervxace.net/topic/16995-taking-damage-when-counterattacking/
# So it would be nice if you credit xShinryu and P Bevans.
#
# Setup:
# Each State must have Ex. Param. CNT +100% in Features to Working.
# Exchange ID States in module Hamedo to your owns.
#
# Add 3 ways of counter-attack mechanism
#
# Evade and Counter: Default mechanism. Probably no-needed. Add only for priority.
# Hamedo: Character Deals damage before taking damage.
# Counter Attack: Both deals damage.
#
# If you use only another ID state with CNT ratio, will be working like default mechanism.


$imported = {} if $imported.nil?
$imported["HamedoState"] = true


module Hamedo

# Setup Evade and Counter state ID
EAC = 74

# Setup Hamedo state ID
HAMEDO_STATE = 75

# Setup Counter Attack State ID - Damage taken before Countering
CNT_ATK = 73

end

class Scene_Battle < Scene_Base
def invoke_item(target, item)
# Evade and Counter damage
if rand < target.item_cnt(@subject, item) && target.state?(Hamedo::EAC)
# apply_item_effects(apply_substitute(target, item), item)
if target.hp > 0
invoke_counter_attack(target, item)
end
# Hamedo Status
elsif rand < target.item_cnt(@subject, item) && target.state?(Hamedo::HAMEDO_STATE)
# apply_item_effects(apply_substitute(target, item), item)
if target.hp > 0
invoke_counter_attack(target, item)
end
if subject.hp > 0
apply_item_effects(apply_substitute(target, item), item)
end
# Counter Attack section
elsif rand < target.item_cnt(@subject, item) && target.state?(Hamedo::CNT_ATK)
apply_item_effects(apply_substitute(target, item), item)
if target.hp > 0
invoke_counter_attack(target, item)
end
# Original Counter-Attack Mechanism
# Original invoke_item
elsif rand < target.item_cnt(@subject, item)
invoke_counter_attack(target, item)
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
 

StatiZkyZ

Villager
Member
Joined
Oct 25, 2019
Messages
7
Reaction score
0
First Language
Indonesian
Primarily Uses
RMVXA
Now if you dont use cnt for counterattack then there might be a workaround but if you do use cnt for it then a script is needed
I do plan to use the battle event to work around the CNT, but so far no luck. I made the 'Counterattack' skill as a separate skill.

Though, might be off topic, but is there a 'how to use plugins for dummies?'. As much as I want to use plugins, I don't know how to 'activate' it o_O
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
If you want to not use plugins, thats an easy one. Create a dummy state where all it does is wear off after a time, nothing else is needed in the state except an icon. Next, have a common event attached to all the enemy attack skills that checks if that charecter has the state. if they do, force action attack. If you want it to only happen after the charecter is attacked. You'll want to set a variable to the charecters HP, and have it check if it's less. I reccomend attaching a common event to the charecters skills and make damage over time effects happen when there making an action, but before they make it. And boom! Counter after hit with only events
 

StatiZkyZ

Villager
Member
Joined
Oct 25, 2019
Messages
7
Reaction score
0
First Language
Indonesian
Primarily Uses
RMVXA
If you want to not use plugins, thats an easy one. Create a dummy state where all it does is wear off after a time, nothing else is needed in the state except an icon. Next, have a common event attached to all the enemy attack skills that checks if that charecter has the state. if they do, force action attack. If you want it to only happen after the charecter is attacked. You'll want to set a variable to the charecters HP, and have it check if it's less. I reccomend attaching a common event to the charecters skills and make damage over time effects happen when there making an action, but before they make it. And boom! Counter after hit with only events
Ok, I've tried something to that effect So, what I did were:
-) Created two variables. The first is 'HP check', set to a constant with the same number as the character's max HP. The second one is the character's HP itself set via the game data. Both are controlled in the Battle event in the Troops section of the database, and is done in Turn 0
-) Created the 'dummy' state, which will wear off after a set of turns. Note that it will be inflicted to the character if they use the 'Shield' skill.
-) Created a common event, where I put two conditional branches. If 'HP check' is greater or equal to the character's HP, and if the character is inflicted with the 'dummy' state, it will be forced to use the 'Counterattack'. Trigger is currently set to 'None'

When I test the battle, the character will use the 'Shield' spell on turn 0, but will immediately use the 'Counterattack' on Index 1. After that, they never use the 'Counterattack' anymore, only that one time. I guess it solves the endless looping counterattack~

My next batch of questions would be, do I have to set the common event's trigger? If so, what is it, and what is the condition switch? And what do you mean by "attaching a common event to the charecters skills and make damage over time effects happen when there making an action, but before they make it."?

Thank you for bearing with me, I'm such a beginner :confused:
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
Connect the common event to enemies damaging skills

Have the common event check if the state is applied through a conditinal branch

If it is applied, have it check if current HP is LOWER than previous HP

If it is lower, have the common event connected to the enemies skill have the charecter with the state use "attack"

Connect another common event to the charecters skills that sets the HP

Make all damage over time effects happen at the beginning of the actors turn. So they don't trigger the counter if the actor isn't attacked
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
@Oddball : How would that though work in context of the default behavior, which is if the CNT roll is made, the one being attacked attacks the attacker, attacker never gets a turn. Even force action will still run into the default behavior, and might result in an odd combo of CNT chains.
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
The common events won't connect to the regular attack. Am i the only one that gives enemies there own attacks and never give them "attack"?
 

StatiZkyZ

Villager
Member
Joined
Oct 25, 2019
Messages
7
Reaction score
0
First Language
Indonesian
Primarily Uses
RMVXA
Connect the common event to enemies damaging skills

Have the common event check if the state is applied through a conditinal branch

If it is applied, have it check if current HP is LOWER than previous HP

If it is lower, have the common event connected to the enemies skill have the charecter with the state use "attack"

Connect another common event to the charecters skills that sets the HP

Make all damage over time effects happen at the beginning of the actors turn. So they don't trigger the counter if the actor isn't attacked
I already make the 'Counterattack' skill (The one that damages whoever attacks the character) call the common event. Do I need to make the 'Shield' spell (The one that gives the character the 'counter' state) the same?

By previous HP, do you mean Max HP, or do I have to make more variables to sub the HP? (If so, I'm not sure how). Also, I don't think it effects anything, but I check if the character have the 'counter' state before I check the HP.

I might need an example for the last two steps, as I'm not sure how to do it :v
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
The issue is force action attack still goes through the counterattack loop, as ANY physical skill goes through that loop, not just the default attack. Plus I'm not sure if common events even run if you trigger the counterattack loop.
 
Last edited:

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
It worked for me. Here. I'll give a simple example of what i'm talking about. It doesn't loop for me, sense i don't connect the common event to "Attack"

Edit: Once you get this part working, i'll go through the next steps

counter common event.png Counter enemy.png Counter skill.png
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
That's because you use magical attack. If you want to use physical attack you can't avoid it. But you do need physical attack if you want to use evade and to hit, unless you want to manually calculate all of those too.

BTW, by using magical attack, you can be reflected via the magic reflection state. Give someone 100% magic reflection and see what happens.
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
I just made Acid spray a physical attack and tested it. It still works. This method is ignoring the CNT parameter completley

Edit: the Gaurd2 state is empty
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
That is impossible with the code, sorry. The code directly runs when physical attack is set, so you have to have it disabled somehow.

Edit: Here is the default code for how CNT is counted:

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

As you can see it clearly returns it on physical attack. Also skills are treated as items in the database.

And here's the code for when you invoke anything in the game (skills or spells)

def invoke_item(target, item)
if rand < target.item_cnt(@subject, item)
invoke_counter_attack(target, item) #This is the key line that is not avoided on physical attacks, unless you change how CNT works or is computed.
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

That uses that result from the previous code to decide what to do. Force action just adds the skill into the system and executes it as a skill though so it won't ignore all of this, unless you already changed the default code some.

FYI: I myself use force action to simulate a boss acting 2x so as to give me better control on what it uses on action 2, and have both counterattacked them, reflected and dodged that 2nd attack so it isn't ignoring the code, at least unless you changed it somehow.
 
Last edited:

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
Ugh. This is what i mean

As you can see. CNT is not even being used. I'm suggesting he ignore the CNT parameter completley and just do it with eventing

Guard2.png
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,261
First Language
English
Primarily Uses
RMVXA
Now that makes sense. See what I was saying is IF you want to use CNT then the code will have problems (I believe I said that a few posts ago somewhere). If you don't then your method will work perfectly.

Same with magical reflect though too, FYI.
 

StatiZkyZ

Villager
Member
Joined
Oct 25, 2019
Messages
7
Reaction score
0
First Language
Indonesian
Primarily Uses
RMVXA
Okay, I followed what you showed me so far, and the attack worked at least. The character immediately uses it once since I created a battle event that gives them the 'empty state'.

I have to say it again, thank you for being so patient with me :smile:

Edit: To avoid some confusion that seems to be going on, I'm not using the CNT state.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,454
Members
137,821
Latest member
Capterson
Top