Creating a Counterattack Item

NikkiKaji

Villager
Member
Joined
Jun 30, 2016
Messages
25
Reaction score
6
First Language
English
Primarily Uses
Hello, I'm back with another javascipt problem haha. I almost had this one solved, but I seem to be having a bit of trouble...
Currently, I am using yanfly's buffs and states core (http://www.yanfly.moe/wiki/Buffs_&_States_Core_(YEP)) to create an item that, when used, counters the next physical attack you take. It doesn't wear off unless you are either hit by a physical attack once, or the battle ends.

The problem is: I can't get the custom action effects to remove the state after the user is hit.

This is the first code I tried:
Code:
<Custom Deselect Effect>
if (this.isPhysical()){
target.removeState(28);
}
</Custom Deselect Effect>
Using that one did not remove the state at all, even after changing "target" to "user" just incase that's why it was messing up. Unfortunately, that did not fix it.

Then, I tried this one:
Code:
<Custom Conclude Effect>
if (this.Physical() && target.result().isHit()) {
  user.removeState(14);
}
</Custom Conclude Effect>
This one almost worked, since enemies would hit the user, get countered, and the state would be removed. However, the user affected with the state attacking an enemy removed the state as well, and that's not what I want.

Can anyone help me out on this? I saw a similar thread before, but that user had a similar problem as me where the state wasn't being removed. I've also tried disabling all other plugins incase it was a compatibility issue, but that didn't fix the problem either...
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
649
Reaction score
378
First Language
English
Primarily Uses
RMMV
The Custom Conclude Effect is going to trigger when the user does an attack- the reason it works defensively is because the user's counterattack triggers the removal condition.

For debugging purposes, I'd suggest putting the following tags in the counter state that's on the player:
Code:
<Custom Initiate Effect>
console.log("Initiate Effect runs");
</Custom Initiate Effect>

<Custom Select Effect>
console.log("Select Effect runs");
</Custom Select Effect>

<Custom Deselect Effect>
console.log("Deselect Effect runs");
</Custom Deselect Effect>

<Custom Conclude Effect>
console.log("Conclude Effect runs");
</Custom Conclude Effect>
Then, open up the debug console with F8, and see what happens when you test your counter state.
I would expect to see the following:
Select Effect runs
Deselect Effect runs
Initiate Effect runs
Conclude Effect runs
If you see a different output when your character is attacked and then counters, then you can investigate from there.
 

NikkiKaji

Villager
Member
Joined
Jun 30, 2016
Messages
25
Reaction score
6
First Language
English
Primarily Uses
The Custom Conclude Effect is going to trigger when the user does an attack- the reason it works defensively is because the user's counterattack triggers the removal condition.

For debugging purposes, I'd suggest putting the following tags in the counter state that's on the player:
Code:
<Custom Initiate Effect>
console.log("Initiate Effect runs");
</Custom Initiate Effect>

<Custom Select Effect>
console.log("Select Effect runs");
</Custom Select Effect>

<Custom Deselect Effect>
console.log("Deselect Effect runs");
</Custom Deselect Effect>

<Custom Conclude Effect>
console.log("Conclude Effect runs");
</Custom Conclude Effect>
Then, open up the debug console with F8, and see what happens when you test your counter state.
I would expect to see the following:


If you see a different output when your character is attacked and then counters, then you can investigate from there.
Yeah, but not only does the user's counterattack trigger the removal condition, but so does them initiating a physical attack normally. I know the very complicated way to fix this would be through giving every single physical attack a condition that removes that state, but honestly I feel like there's a better way to do it.

I tried testing with the console logs, and when the character is attacked, it only shows "initiate effect runs" and "conclude effect runs". When I selected an ally to use the actual item that gives the counterattack state, it showed "Deselect effect runs"

EDIT: Is there possibly a way to just force a counter attack from the custom initiate effect rather than the state parameters, so when the enemy initializes the attack, the user with the state just counters and then the state is removed?
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
649
Reaction score
378
First Language
English
Primarily Uses
RMMV
@NikkiKaji One more thing to try- if you remove the actual counterattack effect from the state, do you get Select and Deselect to show up?
 

NikkiKaji

Villager
Member
Joined
Jun 30, 2016
Messages
25
Reaction score
6
First Language
English
Primarily Uses
@NikkiKaji One more thing to try- if you remove the actual counterattack effect from the state, do you get Select and Deselect to show up?
When I use the item on myself, Deselect Effect runs, followed by conclude effect. When the enemy attacks, select effect runs, followed by deselect effect. That’s after I removed the counter effect.
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
649
Reaction score
378
First Language
English
Primarily Uses
RMMV
So, from that we can determine that with the default counterattack system, countering an attack will skip the select and deselect phases entirely, which seems like a pretty major roadblock for this.

Have you considered using Yanfly's Counter Control? It might improve compatibility, or at least let you try to manage the state's removal via a specific counterattack skill.
 

NikkiKaji

Villager
Member
Joined
Jun 30, 2016
Messages
25
Reaction score
6
First Language
English
Primarily Uses
So, from that we can determine that with the default counterattack system, countering an attack will skip the select and deselect phases entirely, which seems like a pretty major roadblock for this.

Have you considered using Yanfly's Counter Control? It might improve compatibility, or at least let you try to manage the state's removal via a specific counterattack skill.
Ive never tried using counter control before. Do you have any idea how it could be done for a consumable item to give the counter ability?
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Either I just had one of those dreams where you think you're awake, or I have time traveled. I woke up at 6:58am this morning, heard my father leaving for work, laid back down, now its 1:16am.
So the overhaul on my project has been going great, I like this version of the project a lot more. It's more contained and less overly ambitious for what I can achieve given my constraints on time, money, and skills in advanced programming. I'm going to wait till my project is mostly finished to begin working UI polish again. I'm going to learn how to use LUNA MV to polish the project.
last time i used this site i was a different gender.. wow rlly makes u think... anyway transing ur gender is pretty cool and theres hair growing on my feet now 10/10
I should have listened to RPGMAKER Meme thread. I should have backed up my data. The Orphan of Time, my WIP, is completely gone, all those hours of work are completely gone :(
God what was my life before smartphones (I had a grandma's phone before wednesday)

Forum statistics

Threads
93,381
Messages
911,847
Members
122,883
Latest member
TEKILAO
Top