MZ Checking the state of one specific enemy in a troop?

Greetings!

I am currently starting to on a RPGmaker game that has been floating around my head for a few weeks now and I have come across some issues when trying to make one specific mechanic work.

The concept behind the skill: I am trying to make a mechanic where one off my characters has the ability to "call out" an opponents next move. The way that it would work is the character would use up his turn to predict that one specific enemy would use either a physical attack or a magical attack. During that enemy's turn if they attack and the character called out the correct damage type he will punish them with a hard hitting attack that also generates a large amount off TP. If they do not perform the correct the attack then nothing would happen and the character essentially wasted his turn...

The way I have gone about creating this is that the character will have two abilities titled "call: magic" and "call: physical". Both off these skills would inflict a state called "Called: magic" and "Called: Physical" respectively. I would then have every single enemy skill in the game run a common event (one for the magic skills and one for the physical skills) where the game would check if the enemy using the skill has the appropriate state and if they do, use a ForceAction to have the player character use their punishing attack.

The problem: I have been unable to find a way to have the common event Properly check the state off the enemy using a skill during their turn. The event manager itself has offered no way to do this so I have been trying to utilise a script to handle it.

Knipsel.PNG


This is a test event i created to test the script out. Unfortunatetely this script causes the game to crash with "ReferenceError
gameTroop is not defined" each time the event is run.

I have tried various other ideas too... With no luck. I understand the issue may be that $gameTroop.members() returns every enemy in the troop and not a specific one... However I am simply not expirienced enough with RPGmaker MZ or javascript as a whole to fix this myself.

Any help is much appreciated!!!
Does this work better?
JavaScript:
$gameTroop.members()[$gameTemp.lastActionData(3)].isStateAffected(40);
(gameTroop is undefined, $gameTroop is not.)

Edit - if not then here's a different one you could try:
JavaScript:
BattleManager._subject.isStateAffected(40);
Does this work better?
JavaScript:
$gameTroop.members()[$gameTemp.lastActionData(3)].isStateAffected(40);
(gameTroop is undefined, $gameTroop is not.)

Edit - if not then here's a different one you could try:
JavaScript:
BattleManager._subject.isStateAffected(40);
Thank you for responding.

Unfortunately neither solution worked. Your first solution seems to always return a no and it seems to cause a crash on the second enemy action.

Your second solution also causes a crash with the message "TypeError Cannot read property 'isStateAffected' of null". I did not see anything myself but maybe there could be a mistake in the code you wrote there?

Once again thank you for responding!
Oh, I just remembered that the "last enemy index" values are stored as 1 + the real value! E.g. the troop leader is actually index 0, but the value stored for Last Subject/Target Enemy Index would be 1.

So you could try:
JavaScript:
$gameTroop.members()[$gameTemp.lastActionData(3) - 1].isStateAffected()
Otherwise, if no-one has any other ideas, I might play around a bit to figure out what's going on.

(This mechanic of yours might be much easier to do with a plugin, e.g. maybe ATT_Turan's Eval Tags or VisuStella Battle Core, since these offer tags to run scripts when certain things happen.)
Oh, I just remembered that the "last enemy index" values are stored as 1 + the real value! E.g. the troop leader is actually index 0, but the value stored for Last Subject/Target Enemy Index would be 1.

So you could try:
JavaScript:
$gameTroop.members()[$gameTemp.lastActionData(3) - 1].isStateAffected()
Otherwise, if no-one has any other ideas, I might play around a bit to figure out what's going on.

(This mechanic of yours might be much easier to do with a plugin, e.g. maybe ATT_Turan's Eval Tags or VisuStella Battle Core, since these offer tags to run scripts when certain things happen.)
Hello again

This solution seems to work it seems! Thank you a lot!

It does seem that i need to have the debuff last for two turns instead off one as it seems to dissapear before the script triggers otherwise, however I doubt that should be an issue.

I tried using ATT_Turan's Eval Tags plugin before to make it work however i ran into a very annoying syntax error that i simply could not resolve. Hence why i tried this common event solution.


Again thank you so much for your assistance, i should be able to continue like this!
I tried using ATT_Turan's Eval Tags plugin before to make it work however i ran into a very annoying syntax error that i simply could not resolve. Hence why i tried this common event solution.
Did you ask for any help? Trying to do this with a common event you have to figure out code for anyway, then attach to every skill, seems like a harder way to go about it.

For reference, putting this into your Call: Physical state should do what you're asking.

Code:
<Action Damaged Eval>
// Is it a Physical Hit? Actor 5 is alive?
if (skill.isDamage() && skill.isPhysical() && $gameActors.actor(5).isAlive())
{
// Use skill 12 against this enemy
    $gameActors.actor(5).forceAction(12, user.index());
    BattleManager.forceAction($gameActors.actor(5));
}
</Action Damaged Eval>

You'd change the IDs for the actor and skill as appropriate. Then you'd duplicate it for your Call: Magic and replace isPhysical() with isMagical() and change the skill ID if it's a different punishing attack.
It does seem that i need to have the debuff last for two turns instead off one as it seems to dissapear before the script triggers otherwise, however I doubt that should be an issue.
Probably because 1 turn tends to always mean "current turn" - are you by chance using a VisuMZ battle system plugin?
Did you ask for any help? Trying to do this with a common event you have to figure out code for anyway, then attach to every skill, seems like a harder way to go about it.

For reference, putting this into your Call: Physical state should do what you're asking.

Code:
<Action Damaged Eval>
// Is it a Physical Hit? Actor 5 is alive?
if (skill.isDamage() && skill.isPhysical() && $gameActors.actor(5).isAlive())
{
// Use skill 12 against this enemy
    $gameActors.actor(5).forceAction(12, user.index());
    BattleManager.forceAction($gameActors.actor(5));
}
</Action Damaged Eval>

You'd change the IDs for the actor and skill as appropriate. Then you'd duplicate it for your Call: Magic and replace isPhysical() with isMagical() and change the skill ID if it's a different punishing attack.

Hello, thank you for responding.

I had not asked for help on the issue yet as frankly the entire plugin system is still completely alien to me and I wanted to figure out if I could create what i want to using purely events and some mild scripting... Unfortunately I doubt that will be the case for some mechanics moving forward so i am going to look more into plugins in the future.

As for the code you wrote I understand this would be part off the state itself correct? If so where should I actually put the code? I typically use the scripts option but that one is not available for states.

Probably because 1 turn tends to always mean "current turn" - are you by chance using a VisuMZ battle system plugin?
I figured that was the reason why yes. And no I am not using any kind off plugin yet.
As for the code you wrote I understand this would be part off the state itself correct? If so where should I actually put the code?
Notetags go into the Notes field of the appropriate database object.

There are several basic guides on plugins available to you:



As far as the state turns, it's exactly what it says. Counters go down at the end of each turn, so if a state is applied during that turn, and its duration is only 1 turn, it will go down at the end of that turn and be removed.
Notetags go into the Notes field of the appropriate database object.

There are several basic guides on plugins available to you:



As far as the state turns, it's exactly what it says. Counters go down at the end of each turn, so if a state is applied during that turn, and its duration is only 1 turn, it will go down at the end of that turn and be removed.
Thanks a lot! I think that unless a problem arises I will keep the current method... But I will give this a look aswell to see if it works out better.

Original thread: https://forums.rpgmakerweb.com/threads/checking-the-state-of-one-specific-enemy-in-a-troop.180122/