MV Temporary Actor Face Image Change (Hit & Attack) During Battle

Hello,

I am looking for some help in implementing code that will temporarily change an actor's image when they are "hit" or when they are "attacking."

I am able to make an actor's face image change (e.g., when hit, or HP = 0) and even change back after turn end, but the issue is nothing I've tried has been able to make the image change fast (i.e., 1000 - 1500ms).

Currently, what I am doing is using Yanfly's Skill Core (in the skill tags) to implement the face image change before the enemy uses a skill and attempting to change the image back to default after (i.e., post-damage) the skill is complete.

JavaScript:
<Before Eval>
  target._baseFace = [target._faceName, target._faceIndex];
  target.setFaceImage("Battle_icons_test_DM", 2); //make this more dynamic with more actors
</Before Eval>

<Post-Damage Eval>
  target.setFaceImage(target._baseFace[0], target._baseFace[1]);
  delete target._baseFace;
</Post-Damage Eval>

If I comment out the target.setFaceImage in the post damage eval then I can get the "hit" face change with application of the skill from the enemy. When not commented out, the image remains static. Though my console successfully logs that the faceIndex is changing.

hit_state_doesnt_stay.png


I have read through a large number of different threads on this topic and have tried
WAY_CustomFaceImageEval.js in several configurations to make this work, but haven't been successful. I currently find it hard to justify using dummy states, common events, and timers, if there is a more direct route. I suspect the issue may lie in how RMMV "refreshes" actors and other objects during battle, and that the time between skill beginning and end is insufficient for an image change, but I can't say for certain.

I would be grateful if anyone had insight on how to solve this issue. I know this has been asked before but, like I said, the solutions have not fixed my issue. I am quite familiar with a variety of codes, but new to RPG maker, so there may be another Yanfly lunatic code out there that would time the face change exactly as I want it.

Again, many thanks in advance for a suggestion! Please let me know if I missed any code/information that would be helpful.
It would help if you linked to some threads of what you tried and described how it didn't work, because I recall people using waynee95's Custom Face Image Eval to do exactly this.

I also believe (not positive) that MogHunter's battle HUD or something has this built in.

So having a starting point would be useful.
You bet.

Some threads I've tried to apply:
  • https://forums.rpgmakerweb.com/index.php?threads/need-help-with-way_customfaceimageeval.99012/
    • It's easy enough to implement Waynee96's code in the Actor notes. For hits, it was suggested that one applies a "dummy state" (within the skill of the enemy applying the hit state). This thread is where the suggestion to put window.setTimeout(() => b.removeState(X), Y) in the damage formula comes from. I have also seen suggestions to check off the "Remove by Damage" parameter at 100%. Implementing any combination of these has not been successful. Here's what I used in my character code:
JavaScript:
<Custom Face Image Eval>
if (user.isStateAffected(4)) {
    //Hurt
    faceName = 'Battle_icons_test_DM';
    faceIndex = 2;
} else if (user.isStateAffected(5)) {
    //Attack
    faceName = 'Battle_icons_test_DM';
    faceIndex = 1;
} else if (user.hp <= 0) {
    //Dead
    faceName = 'Battle_icons_test_DM';
    faceIndex = 3;
} else {
    //Normal
    faceName = 'Battle_icons_test_DM';
    faceIndex = 0;
}
</Custom Face Image Eval>

dummy_hit.png


  • https://forums.rpgmakerweb.com/inde...ace-change-when-getting-hit-in-battle.142352/
    • I tried implementing Yanfly action sequences to remove the "dummy hit" state and no dice. I could successfully remove the state (i.e., the console suggested the faceindex variable was updating as expected), but the face image wouldn't actually change. If I remember correctly, the image would change back, but not until a while later.
    • I was also playing around with states and buffs core, alongside Waynee95's FaceImageEval code with a passive state (I even tried common events too for more flexibility). That code looked different to what I currently have in skillcore; though, I believe my current configuration bypasses the need to add a state and/or use Waynee's plugin altogether. And unfortunately, I don't have the code for that anymore.
  • https://forums.rpgmakerweb.com/inde...ey-get-hit-during-battle.167631/#post-1436404
    • Kind of the same things I've tried.
My understanding is MogHunter's battle HUD is incompatible with SRD's Battle Status Customizer? I prefer the look of the latter, but I could try it if I can't manage to solve this. I guess if people are successfully using Waynee's plugin to do this job, I haven't figured out how yet.

Does this help? I'm happy to provide more information.
The potential trick with states is there are safeties built into the code to prevent states from getting added and removed at the same time, that kind of thing.

So I think I would go a little simpler with just adding a property to the battler.

Try this. Give your actor a passive state with these notetags:
Code:
<Custom React Effect>
if (value > 0)
    target.gotHit = true;
</Custom React Effect>

<Custom Deselect Effect>
if (target.gotHit)
    delete target.gotHit;
</Custom Deselect Effect>

Then your face eval notetags, instead of referencing user.isStateAffected will reference user.gotHit
Okay, I've given this a shot, and unless I've incorrectly implemented something, it's still not working.

So I put the following code into a dummy state:
JavaScript:
<Custom React Effect>
    if (value > 0)
    target.gotHit = true;
    console.log("Custom React");
</Custom React Effect>

<Custom Deselect Effect>
    if (target.gotHit)
    delete target.gotHit;
    console.log("Custom Deselect");
</Custom Deselect Effect>

BuffsandStatesCore.js is on and functioning. I've added nothing else to the dummy state. The skill implemented by the monster has the effect of adding this dummy hit to the actor. And I have the following code in the actor's notetags:

JavaScript:
<Custom Face Image Eval>
if (user.gotHit) {
    //Hurt
    faceName = 'Battle_icons_test_DM';
    faceIndex = 2;
    console.log("user.gotHit = ", user.gotHit);
} 
</Custom Face Image Eval>

Waynee's FaceImageEval is working because if I remove the deselect effect, I get the hit state image (but only after two hits, weirdly?). And when the deselect effect is present--like much of the code I've implemented--the "hit" state is briefly acknowledged by the program, the image change just can't seem to keep up. Here's a link to some gifs that show these effects; image_change shows what happens when I comment out the deselect effect and no_image_change shows the full, suggested code.

Thanks for all your help on this. Any suggestions on what to try next?
bump
Looks like the face eval notetags are evaluated when the battler refreshes. So you could include a call to refresh() in the state notetags, but if you're going through all that you could just cut out the face eval entirely.

Code:
<Custom React Effect>
if (value > 0)
{
    target.oldFace = target.faceName();
   target.oldFaceIndex = target.faceIndex();
// Change info beneath if necessary
    target.setFaceImage(target.faceName() + "_hit", 0);
}
</Custom React Effect>

<Custom Deselect Effect>
if (target.oldFace)
{
    target.setFaceImage(target.oldFace, target.oldFaceIndex);
    delete target.oldFace;
    delete target.oldFaceIndex;
}
</Custom Deselect Effect>

That will work automatically if you set up your actor images so that they have a name and a name_hit file. For example, Harold and Harold_hit.

If you want something different, you can change the setFaceImage() arguments, e.g. setFaceImage("somerandomfilename", 0)

Give that a go, if that doesn't work it might be an issue of refreshing where the face is drawn on the battle status window.

And as a tip, if you want to let someone specific know you have a response, you should tag them by quoting or replying to their post, or @tagging their name.
Yeah, I'm still running into the same issue. That is, if I don't add the code within the Deselect tags, I can see the "hit" face pretty quickly after the enemy attacks (but it sticks around), if I keep the Deselect code in, then nothing changes. The result of these State notetags exactly match the gifs I added in the drive folder. I can update that with gifs of that most recent code, though, if thats helpful. Also I've been running into this issue where the notetags do not run on the first "hit" only on subsequent "hits."

Overall, all these different code configurations are indeed able to change the actor image (e.g., whether using state tags, or Waynee's plugin etc.); setFaceImage() is functioning in that sense. It's the fast removal of the state that is likely causing issues, which I suspect, like you, is due to the refreshing of the battler.

I'm not sure where to go from here. I'm kind of stumped because it doesn't seem like many others have encountered this issue with timing, and have, in fact, successfully implemented a rapid hit state. I'll have to look further into how RPG maker MV refreshes its battler images, and whether there are notetag functions or plugins I can implement as a workaround--although there may be a simpler solution I'm not seeing!

Thanks again for the help, I'm very grateful.
I'm sorry if this is a bother @ATT_Turan but I would love some insight.
You can try this. I don't love it because I don't like doing stuff outside of the game engine loop, but it's something like this or a custom plugin.

Code:
<Custom React Effect>
if (value > 0)
{
    target.oldFace = target.faceName();
   target.oldFaceIndex = target.faceIndex();
// Change info beneath if necessary
    target.setFaceImage(target.faceName() + "_hit", 0);

    window.myInterval = setInterval(function () 
    {
        target.setFaceImage(target.oldFace, target.oldFaceIndex);
        delete target.oldFace;
        delete target.oldFaceIndex;
        clearInterval(window.myInterval);
    }, 1000);
}
</Custom React Effect>

This should make it wait one second (the 1000 at the bottom is 1,000 milliseconds) and change the face back.
Thank you! I have implemented this code and have run into further issues.

First, I am using Yanfly's STB battle type--this seems to produce the issue that the face image will change to the hit state, but does not change back to the default, even with an internal timer. It only changes back if another player gets hit. With the default battle type, however, the hit image will appear and will only change back to default the next time the enemy attacks, no matter who the target is (so, a shorter, more reliable length of time, but kinda too long). Also, in the stage of battle where the player is selecting their next attack, the hit state remains for however long that action takes, and appears to resume after selection. I am happy to add video of these scenarios if my description is not clear enough.

Additionally, these scenarios also depend on the length the timer is set to. If the internal time is less than 500 ms, the image does not appear at all. Anything above 500ms has the above effects. This is again likely because the battler refreshes face images the end of each turn.

Second, when calling the image change from a state, there was an issue where on first hit, nothing would happen, but the face image would change on subsequent hits. This is because the first execution of the <React> tags is within the state itself, thus the state has not technically been applied (and will not execute). But it has been applied on subsequent hits. My solution was to move the same code back to the skill notes (it's working in <Pre-Damage Eval> tags), which does apply the face image change on the first hit.

I think what I need is a way to "refresh" the battler image while actions are still occurring--and not at turn end, which I think that Yanfly's battle core or SRD's Battle Status Customizer is doing. I will spend some time digging through this code for a possible explanation.

Thanks again, @ATT_Turan
when calling the image change from a state, there was an issue where on first hit, nothing would happen, but the face image would change on subsequent hits. This is because the first execution of the <React> tags is within the state itself, thus the state has not technically been applied (and will not execute).
This sounds like you are not setting it up properly.

Going all the way back to my first advice in post #4,
Try this. Give your actor a passive state with these notetags:

The notetags should be in a passive state (using Yanfly's Auto Passive States) that is always on the actor. You shouldn't be applying it during the game from an attack or anything.

If the rest of it using the JavaScript window timer doesn't work, then I can only suggest you're into the realm of commissioning a plugin. Someone else may have a different idea.
Yeah, I'm still encountering the same issue where the image will change to the hit state (above 500ms, below 500ms the image doesn't change at all), but then won't change back to the default unless a different actor is hit. While using a passive state helped by making the first hit actually hit, it doesn't tackle the heart of the issue. Guess I'll have to look at developing a plugin or see if anyone is interested in developing one.

Thanks again!
I have solved this issue: I needed to use Yanfly's Battle Status window either on its own, or alongside SRDs Battle Status Customizer.

I'm going to attempt to explain what the difference between the two plugins is:
  • In looking through SRDs Battle Status Customizer, the code does not appear to update the actors' window upon setting a new face image; it instead appears to only draw faces when they are loaded, and does not automatically trigger an update to the combat UI to reflect the new face image. This is likely why I was not seeing dynamic face changes with the above code that @ATT_Turan suggested.
  • In comparison, Yanfly's Battle Status Window does call a refresh function at the time of setting the face image. That is, it provides a direct hook to update the face image dynamically based on game events (including notetags).
To make this all come together, I need the above two plugins, alongside Yanfly's AutoPassiveStates and BuffsStatesCore. My modified code includes the following:

1) Actor tags: <Passive State: 4, 5>

2) State 4 (hit) tags:
JavaScript:
<Custom React Effect>
if (value > 0 && target.hp - value > 0) {
   target.setFaceImage(target.faceName(), 1);
   window.myInterval = setInterval(function () {
        target.setFaceImage(target.faceName(), 0);
        clearInterval(window.myInterval);
    }, 700);
}
</Custom React Effect>

3) State 5 (attack) tags:
JavaScript:
<Custom Initiate Effect>
   user.setFaceImage(user.faceName(), 2);   
   window.myInterval = setInterval(function () {
        user.setFaceImage(user.faceName(), 0);
        clearInterval(window.myInterval);
    }, 700);
</Custom Initiate Effect>

4) State 1 (death) tags:
JavaScript:
<Custom Apply Effect>
   user.setFaceImage(user.faceName(), 3);
</Custom Apply Effect>

To see everything in action, watch this video called image_change_success. It obviously needs some adjustments, and there are a number of other elements I want to add, but I'm happy with how its turned out.
If the problem is just the status window not refreshing, you probably don't need all that. If you don't want to be using Yanfly's Battle Status at the same time (which seems ripe for conflicts), just refresh the status window inside the notetag.

Change the image, then do
Code:
BattleManager.refreshStatus()[/icode]

But if what you have works for you, it's likely not worth changing stuff around.
Here's some examples:
dunmesh_combat1_1.gif
dunmesh_combat2_1.gif
dunmesh_combat3_2.gif
If the problem is just the status window not refreshing, you probably don't need all that. If you don't want to be using Yanfly's Battle Status at the same time (which seems ripe for conflicts), just refresh the status window inside the notetag.

Change the image, then do
Code:
BattleManager.refreshStatus()[/icode]

But if what you have works for you, it's likely not worth changing stuff around.
If anything, the easiest solution would be to only use Yanfly's Battle Status Window--and adjust appearance from there. I'm not sure what SRDs Battle Status Customizer offers that Battle Status Window does not.

Original thread: https://forums.rpgmakerweb.com/threads/temporary-actor-face-image-change-hit-attack-during-battle.169851/