State that alters character image in battle

I am using a picture to display my character in front-view battles. I would like the picture to change to an "off-balance" variant whenever it is affected by the state "off-balance". I thought to use a common event tied to the state like I would with a skill for example but it seems like I cannot use a common event for "states". For now, I've been using this work-around in a battle event page with the Conditions: Turn end and Span: Turn

JavaScript:
◆If:Player is affected by off-balance
  ◆Erase Picture:#1
  ◆Show Picture:#2, player_off_balance
  ◆
:Else
  ◆Erase Picture:#2
  ◆Show Picture:#1, player_normal
  ◆
:End

It seems to work as intended except when the "off-balance" state wears off, the picture change to "player_normal" is being delayed towards the turn end, due to the condition trigger. So the question is how do I make the picture change as soon as the state is removed, or even taking one step back, is there a better way to make this whole "state affects player picture so long as state is active" thing to work properly?
You would use a plugin that executes code when the state is added and removed.

My Eval Tags can do that, linked in my signature; or if you're already using VisuStella plugins, their Skills and States Core has notetags for that.
You would use a plugin that executes code when the state is added and removed.

My Eval Tags can do that, linked in my signature; or if you're already using VisuStella plugins, their Skills and States Core has notetags for that.
Alright, thanks. I am using the mentioned VisuStella plugin and I've heard about notetags but I have no clue as to what I need to write into it to achieve desired effect. I am aware of the plugin's help section but I don't know how to navigate through it either since it is alot of written text that I would have to go through manually. What exactly am I looking for? Thanks in advance
I recommend using the Web documentation:

The table of contents has links directly to the state notetags you're looking for.

Then you go to the Script Call list and look up the code for Show Picture and Erase Picture.
I recommend using the Web documentation:

The table of contents has links directly to the state notetags you're looking for.

Then you go to the Script Call list and look up the code for Show Picture and Erase Picture.
Thank you very much! I found the script call page just a few minutes prior to your answer but wasn't sure if that is what I need for the notetags.

The script calls Show Picture and Erase Picture are working properly. But I am still missing the conditional branch If:Player(x) is affected by off-balance as I have two players on screen (forgot to mention). So I would need a conditional branch or something similar, otherwise the player picture for a specific character changes no matter who is afflicted by the off-balance state. Currently, Player1's picture changes although it is Player2 who got the off-balance state.

Edit: The problem is I can't find the script call for Conditional Branch or rather there is no script call for it on the spreadsheet (?)
But I am still missing the conditional branch If:Player(x) is affected by off-balance as I have two players on screen
The notetag instructions should say you're provided with a user variable to represent the battler getting (or losing) the state.

So to check which actor ID is being affected, you do this inside the notetag:
Code:
if (user.actorId() == 2)
{
// script call to erase actor ID 2's picture
// script call to draw actor ID 2's off-balance picture
}
else
{
// script call to erase the other actor's picture
// script call to draw the other actor's off-balance picture
}

Then the notetag for when the state is removed, obviously you just reverse which pictures are being erased and drawn.
It doesn't seem work as it doesn't change the picture at all now. I assume it's because I have problems understanding the (user.actorId() == 2) part of the code.
First of all, I don't understand where user.actorId() is coming from as I can't ctrl+F this in neither the notetag instructions nor the script call spreadsheet. What does ==2 mean in this context? How do I learn about this stuff? Is it all just general JavaScript knowledge? Either way I assume I have to put in the ID corresponding to my (second) Actor? Since just using (user.actorId() == 2) in the notetag didn't do anything. But (user.actorId(2) == 2) didn't work either so I am confused as what to do with it now. Here is how I implemented it into the notes anyway.
Screenshot 2024-07-16 022849.png
As a tip, if you want someone specific to reply to you, you should either @tag their name or Reply or Quote their post (which will then do it automatically) so they get a notification from the thread.

I have problems understanding the (user.actorId() == 2) part of the code.
I put the instructions right in my previous post.

What does ==2 mean in this context?
Code:
if (user.actorId() == 2)
// script call to erase actor ID 2's picture
// script call to draw actor ID 2's off-balance picture
I thought it was pretty clear with my repeated reference to actor ID 2 that if you were not trying to refer to actor ID 2, you would change that number.

You have also left out half of the code I gave you, which is why nothing at all is happening - I'm not sure why you made that choice.

How do I learn about this stuff? Is it all just general JavaScript knowledge?
Yes.

If you still can't get it to work, please show the entire thing - your picture above is missing half the code provided, and has the script call for the picture cut off so we can't see the entire thing.

Why change the Picture ID from 1 to 2?
I thought it was pretty clear with my repeated reference to actor ID 2 that if you were not trying to refer to actor ID 2, you would change that number.
Yes I understood that in the beginning but since it didn't work I thought I must be misunderstanding the code.
You have also left out half of the code I gave you, which is why nothing at all is happening - I'm not sure why you made that choice.
Because I wanted to test if the code on Actor2 works first before essentially copy/pasting the same for Actor1 into the "else" branch. Since that is not the case, I don't understand how including the "else" branch of the code would change anything. Previously, the picture of Actor2 would alter correctly, the issue was that it would also alter whenever Actor1 is affected by the state. After including the if (user.actorId() == 2) in the code, it stops working completely. But it should still at the very least alter Actor2's picture anyway, no?
Here is the code now with the other half of your code included. Still not working unfortunately.
Code:
<JS On Add State>
if (user.actorId() == 2)
{
$gameScreen.erasePicture(1);
$gameScreen.showPicture(1, 'Mel_KnockedOver', 0, 248, 456, 100, 100, 255, 0);
}
else
{
$gameScreen.erasePicture(2);
$gameScreen.showPicture(2, 'Nat_KnockedOver', 0, 200, 521, 100, 100, 255, 0);
}
<JS On Add State>
Why change the Picture ID from 1 to 2?
Too long to explain, the short of it is that I am dumb.

Edit: In case this is of any relevance. The state is applied on Actor from an enemy attack

Edit: Tried out (target.actorId() == 2) instead of (user.actorId() == 2) since in the notetag instructions using "target" instead of "user" made more sense to me logically and the code actually works now. Thanks for your patience up until now btw and have a nice day 🙂
You're not closing the notetag correctly.

It should have a slash, </JS On Add State>
You're not closing the notetag correctly.

It should have a slash, </JS On Add State>
Yes, you're right. It is written the right way inside the notetag of the state, I just mistyped in the thread.
Okay. It's best to copy and paste directly - if that can happen, then you could also have a typo in the code which is accidentally corrected when you type it into the thread.

Presuming everything else matches but the notetag is formatted correctly, you should be seeing something happen. So:
- When you get the state in battle, press F8, go to the Console tab, and post a screenshot of that window.

- Show a screenshot of the state in your database, the skill applying it, and the two actors in the battle.
Not sure if you saw my edits of my previous post or not so I am just gonna quote it here.
Edit: Tried out (target.actorId() == 2) instead of (user.actorId() == 2) since in the notetag instructions using "target" instead of "user" made more sense to me logically and the code actually works now. Thanks for your patience up until now btw and have a nice day 🙂
I wasn't sure if I should post it as a separate message as I've seen mods mentioning in other threads that "double posting" is against the rules and you should edit your previous post instead.
- When you get the state in battle, press F8, go to the Console tab, and post a screenshot of that window.
Otherwise if you would like me to do that anyway then let me know and I can submit the screenshot later 🙂
Ah, it looks like you were editing it while I was typing my reply.

That is pretty confusing, since in the equivalent plugin for MV user and target are the same thing in that notetag.

But I'm glad you got it working!
@ATT_Turan Sorry to bother you again but I have decided to add another condition into my notetag, which is a switch that must be turned on before the picture changes are applied.

Code:
<JS On Add State>
if (target.actorId() == 2 && $gameSwitches.setValue(6, true));
{
$gameScreen.erasePicture(1);
$gameScreen.showPicture(1, 'Mel_KnockedDown', 0, 248, 456, 100, 100, 255, 0);
}
</JS On Add State>
I think I am using the wrong script call as it only just "sets" the switch to on/off but I couldn't find any other script call that is actually "checking" a switch.

I have seen however, in another post for the RGSS engine, that someone used if $Game_Switches[103] == true but to no surprise this did not work in MZ.
I think I am using the wrong script call as it only just "sets" the switch to on/off
yes

where did you find that function if the one you wanted wasnt directly next to that? its $gameSwitches.value(id) to get the value of a switch. if you cant find a particular script call, theres a list of them pinned here in this section of the forums

1721257371625.png
its $gameSwitches.value(id) to get the value of a switch.
Because that is actually the other script call that I've tried already. Should have mentioned that in my previous post, my bad. This is how I implemented it.
Code:
if (target.actorId() == 2 && $gameSwitches.value(6) == true);
To make sure that this switch isn't actually ON before the code checks, I removed the only event that controls the switch and even forced the switch to be off with an event command to be extra safe. It still changes the picture with the switch being off.

EDIT: Even with if ($gameSwitches.value(6) == true); being the only condition for the picture to change, it still does. Even going so far as to use a switchID that I haven't used before, the picture still changes.
You added a semicolon at the end of the if (stuff) line.

That's incorrect, and you'll notice it wasn't there before.

Semicolons go at the end of a command. So by placing it there, you are saying the one command that gets done after the if is evaluated is nothing. Then the next lines of code are just there, they're not inside the if.
You added a semicolon at the end of the if (stuff) line.

That's incorrect, and you'll notice it wasn't there before.

Semicolons go at the end of a command. So by placing it there, you are saying the one command that gets done after the if is evaluated is nothing. Then the next lines of code are just there, they're not inside the if.
You are right, this fixed it. I was going crazy as to why it wouldn't "just" work. Thank you once again.

Original thread: https://forums.rpgmakerweb.com/threads/state-that-alters-character-image-in-battle.170323/