Making an actor invisible in battle?

Hey everyone! First post here. I'm super super new at MV and I'm trying as hard as I can to understand what I'm doing and I've hit a brick wall on this one particular thing:

When one of my characters gains the "Invisible" state in battle, I want to completely hide their sprite, and then for it to come back once the state has been removed. I'm absolutely at my wits' end with this. I've tried using Yanfly's transformation script to change the image, nothing happens at all when I use it so I must be using it wrong, I've tried using a switch but I'm not sure how to tie common events into battle yet so lord only knows if I even did that partially right, I've tried using another plugin to make them transparent, nothing happened when I used it.

Essentially I'm trying to do it as a monster attack. If a monster attacks the character and applies the "Invisible" state to them, I want their sprite hidden. When the state is removed, I want the sprite to come back. All the tutorials I've found are how to have a character make themselves invisible as a self skill, coded so that the skill itself turns them invisible by replacing their own images specifically. The thing is, I want it to be an enemy skill that affects the actors so I can't just set it to change actor 1's battle sprite, it has to be able to change the actor that was hit by the attack.

I managed to get it once to make the sprite disappear when the status is applied using a battle event with span battle, but I can't for the life of me figure out how to turn it back when it's removed. I tried using a conditional battle event with span moment so if they have the state to change the sprite, else change it to the original sprite, but it just changes it and then freezes the battle.

This feels like it should be such a simple thing but absolutely nothing I do is getting these sprites to change back and forth. Can anyone help me figure out what I'm doing wrong? This is driving me absolutely insane.
It would be helpful if you posted what you had tried that wasn't working. And linked to what you saw that you thought was similar.

This should be as straightforward as giving the battler's sprite 0 opacity. But, then, it should have worked for you to transform to another actor that had no sprite, so you should show us what didn't work.
If you don't mind using a plugin for this, Caethyril has the perfect one for this.

It's the Battle Opacity plugin, under the spoiler for 'General' plugins. Works perfectly, at least for me.
This would be a direct way that you could do it:

JavaScript:
(() => {
const invisibleStateId = 11; // the database id of your invisibility state
const update = Sprite_Battler.prototype.updateVisibility;
Sprite_Battler.prototype.updateVisibility = function() {
    update.apply(this);
    if (this._battler) {
        const battler = this._battler;
        if (this.opacity && battler.isStateAffected(invisibleStateId)) {
            this.opacity = 0;
        } else if (!this.opacity && !battler.isStateAffected(invisibleStateId)) {
            this.opacity = 255;
        }
    }
}
})();

Edit: @Sword_of_Dusk's suggestion is more nuanced and includes conditions I didn't initially think of, so I suggest you try that.
If you don't mind using a plugin for this, Caethyril has the perfect one for this.

It's the Battle Opacity plugin, under the spoiler for 'General' plugins. Works perfectly, at least for me.
Hmm I tried that and unfortunately... once again nothing happens. It seemed pretty straightforward to put it in and I can tell it is applying the state because the icon's showing up but there's no change. Am I doing something wrong?
captured.PNG


This would be a direct way that you could do it:

JavaScript:
(() => {
const invisibleStateId = 11; // the database id of your invisibility state
const update = Sprite_Battler.prototype.updateVisibility;
Sprite_Battler.prototype.updateVisibility = function() {
    update.apply(this);
    if (this._battler) {
        const battler = this._battler;
        if (this.opacity && battler.isStateAffected(invisibleStateId)) {
            this.opacity = 0;
        } else if (!this.opacity && !battler.isStateAffected(invisibleStateId)) {
            this.opacity = 255;
        }
    }
}
})();

Edit: @Sword_of_Dusk's suggestion is more nuanced and includes conditions I didn't initially think of, so I suggest you try that.
I'm so sorry this is probably incredibly dumb to ask but if I were to try that javascript where do I input it? So far most of what I've worked with has been in the state notes, does it go there or somewhere else?

Edit: I have 2 replies that say they're currently awaiting moderator approval but this one looks like it's gone straight through? Sorry if this comes in a wonky order, I promise I'm not ignoring what ya'll have said already!

---

Maybe I should just detail out what I'm trying to do in full to see if this is even possible rather than this one small component or I'm just going to be asking a billion separate questions.

So this is my perfect world scenario if everything can be done exactly the way that I want it:

I would like my game to work off a permanent capture mechanic. This would make it so party members' hp cannot be dropped below 1 by damage. However, all enemies will have the Capture attack that can be used once an actor is at 1 hp. Then, the party will have 3 turns to rescue the character by damaging the enemy (I think this is best handled by transforming the enemy into another form with set hp, think a soldier with a bag over their shoulder then turning back to normal once they've taken the appropriate amount of damage). If they do not rescue the ally before the 3 turns run out, the ally's hp drops to 0 and they will be removed at the end of the battle using a permadeath plugin I've also downloaded. However if they can transform the enemy back in time, the party member will be returned at 1 hp. While the party member is captured I'd like them to be invisible, and of course if they are ko'd.

What I've got so far:
I have a passive state that stops your characters from dropping below 1 hp (Thanks to ATT_Turan in a past thread!)
I have the skill that gives the ally the captured state and transforms the enemy simultaneously.
I have the enemy set to use that skill only when someone is at 1hp.
I thiiiink I know how to make the ally drop to 0 hp at the end of the countdown by working around the 1hp protection status and setting their hp directly to 0?
I have the permadeath plugin installed but haven't really been able to test it yet so for now I'll just assume it works lol.
I think I understand how to make the countdown using a variable.
I know how to make them invisible once they're ko'd since that's a constant thing I can just delete that from their sprite sheet I think.

What I'm lacking:
I don't quite know how to actually trigger the countdown. I think by creating a common event and putting that in the capture skill effects and using a battle event to decrease it by 1 each turn?
I don't know how to stop the countdown when the enemy transforms back or revert the variable to its maximum.
I don't know how to prevent the captured actor from being targeted by healing/buff abilities while they're captured.
Obviously as mentioned I don't know how to make the actor invisible while captured and return to visibility after.
I don't know how to make the characters react after battle if a party member is captured.

So I feel like I'm relatively close to pinning it down (unless y'all think I'm completely off), it's just those 5 remaining key components that I just can't seem to sus out to tie the rest together.

Sorry if that's just too much, big ideas but small knowledge. My brief understanding *cough*hubris*cough* makes me think it's doable it's just a matter of figuring out the how. As a note I also have very little javascript experience so I can sort of figure out some things but I'm mostly relying on the engine, plugins, and what the plugins say to put in the notes so please be patient I'm really doing my best and I've been googling and combing through past threads to figure out things as I go.
Hmm I tried that and unfortunately... once again nothing happens. It seemed pretty straightforward to put it in and I can tell it is applying the state because the icon's showing up but there's no change. Am I doing something wrong?
I know for a fact it works, so something is definitely up. Are you doing a full playtest when you check, or are you simply doing a battle test?
I'm so sorry this is probably incredibly dumb to ask but if I were to try that javascript where do I input it? So far most of what I've worked with has been in the state notes, does it go there or somewhere else?
When someone just gives you code, you paste it into a text editor, save as a *.js file, and include it as a plugin.

But it sounds like you need to figure out what's going wrong, because the plugin from caethyril should be plug 'n' play.

In addition to what Sword asked about playtest vs. battle test - are you starting a new game when you playtest? Save games won't load all changes to plugins and the database.
I see, that could be the problem. I've been doing the battle test through the troops tab, I didn't know it wouldn't pick up on some elements. I can't work on it today but tomorrow I'll check and see if that could be the issue potentially and get back with you guys. Thank you guys so much for the help! And for letting me know what to do with the code, I've seen that floating around in a few threads but never known what one is supposed to do with it. That's so much easier than I'd have expected.
Just gonna mention yanfly action sequencing here. You can just use the line opacity target: 0, x (frames)

to make the target of a skill invisible.
Just gonna mention yanfly action sequencing here. You can just use the line opacity target: 0, x (frames)

to make the target of a skill invisible.
True, but that won't allow it to function like a state - if something removes the state outside of another action sequence, the opacity won't just change back.
True, but that won't allow it to function like a state - if something removes the state outside of another action sequence, the opacity won't just change back.
Ya true. Maybe one could finaggle some js into buffs and states core to get the desired effect on a state.
Assuming the plugin is activated and you've saved your project, there really shouldn't be an issue with testing via the troops tab. I always write plugins with a troop battle test open and a text editor open and just F5 to refresh to see my changes. I've run into maybe two odd caching issues within the last couple of years.

If Cae's plugin doesn't work (it should), you can try adding my snippet as a plugin as a troubleshooting measure. If that still doesn't work, you can try building your desired effect/mechanic in a fresh project with only the plugin(s) that you absolutely need (e.g. a battler opacity plugin and nothing else). Then you can gradually introduce additional plugins as a means of figuring out where the breakdown is occurring.
Okay so the good news is, I think you guys were correct that it just wasn't working because it was in the battle test mode. When I actually try through the game test the plugin does make them invisible when the state is added. I unfortunately couldn't figure out with Cae's plugin how to get them to go visible again when the state is removed BUT it works perfectly with Kenen's code! At least for now that seems to be exactly on track. Thank you so very much on both of those fronts, it's SUCH a relief to have that one part solved! 😀

Now I'm on to the next big conundrum: "I don't know how to stop the countdown when the enemy transforms back or revert the variable to its maximum." I think I found a great solution to the second part by using Hime's Progressive States plugin https://himeworks.com/2015/11/progressive-states-mv/ so that once the timer reaches 0 it automatically progresses to the Knockout state. I'm just not sure how to get it so when the enemy transforms back, it removes the Captured state from the actor. I keep thinking of ideas that might work but I can't figure out if it's even possible to make it so transforming that enemy back removes the state from that an actor, let alone the correct one. Say if enemy 1 applies it to actor 1 and enemy 2 applies it to actor 2 how would I be able to keep those connected. Alternatively, if the only way is to blanket remove it from all actors, is there a way to make it so only 1 enemy/actor can have the transformed/captures state at a time, so that way it isn't silly like attacking enemy 2 to free actors 1 and 2? I hope that makes some semblance of sense.
If you're going to use my code, I'd just caution you that it'd probably override the "hidden" condition for enemy battlers and any other conditions that might make a battler sprite's opacity change. When I posted that code it was primarily to give you something to try, and I hadn't thoroughly tested it or taken the time to think about various conflicting factors in the default code.

I haven't read the rest of your post as of yet, but I'll try to do that later to see if I can help.
If you're going to use my code, I'd just caution you that it'd probably override the "hidden" condition for enemy battlers and any other conditions that might make a battler sprite's opacity change. When I posted that code it was primarily to give you something to try, and I hadn't thoroughly tested it or taken the time to think about various conflicting factors in the default code.

I haven't read the rest of your post as of yet, but I'll try to do that later to see if I can help.
Gotcha! I will keep that in mind! It at the moment doesn't conflict with anything else I have in mind but I appreciate the warning.

No problem at all, it's a lot I know ^_^;;; I hope my ambitions aren't too big for my britches.
I think the thread and some of the questions are confusing because you seem to be over-complicating things.

Post #5 is rather challenging to read through, but it really looks like all of this could be done pretty simply using some Yanfly Buffs & States notetags. But you're going off into variables and troop events and getting a separate plugin modifying the base sprite code instead of just the actor...it's kind of chaotic.

If they do not rescue the ally before the 3 turns run out, the ally's hp drops to 0 and they will be removed at the end of the battle using a permadeath plugin I've also downloaded.
Just put the permadeath command inside a Custom Leave Effect. That happens when the state's duration (the 3 turns) expires.

I don't quite know how to actually trigger the countdown. I think by creating a common event and putting that in the capture skill effects and using a battle event to decrease it by 1 each turn?
I don't understand why you're making this into some kind of variable with events and all that. States have a duration, that's built right into the database. Give it a duration of 3 turns.

I don't know how to stop the countdown when the enemy transforms back or revert the variable to its maximum.
You take the state off.

I don't know how to prevent the captured actor from being targeted by healing/buff abilities while they're captured.
Use Yanfly's Selection Control. Give the state one of the Cannot Target notetags.

Obviously as mentioned I don't know how to make the actor invisible while captured and return to visibility after.
Code:
<Custom Apply Effect>
target.battler().opacity=0;
</Custom Apply Effect>

<Custom Remove Effect>
if (target.stateTurns(stateId)>0)
    target.battler().opacity=255;
else
    $gameSwitches.setValue(X, true);
</Custom Remove Effect>

I don't know how to make the characters react after battle if a party member is captured.
Replace X above with the ID of a switch. Have a parallel event that runs after battles (or use Yanfly's Utility Common Events) that checks for that switch to be true. If yes, someone was captured.
I think the thread and some of the questions are confusing because you seem to be over-complicating things.

Post #5 is rather challenging to read through, but it really looks like all of this could be done pretty simply using some Yanfly Buffs & States notetags. But you're going off into variables and troop events and getting a separate plugin modifying the base sprite code instead of just the actor...it's kind of chaotic.


Just put the permadeath command inside a Custom Leave Effect. That happens when the state's duration (the 3 turns) expires.


I don't understand why you're making this into some kind of variable with events and all that. States have a duration, that's built right into the database. Give it a duration of 3 turns.


You take the state off.


Use Yanfly's Selection Control. Give the state one of the Cannot Target notetags.


Code:
<Custom Apply Effect>
target.battler().opacity=0;
</Custom Apply Effect>

<Custom Remove Effect>
if (target.stateTurns(stateId)>0)
    target.battler().opacity=255;
else
    $gameSwitches.setValue(X, true);
</Custom Remove Effect>


Replace X above with the ID of a switch. Have a parallel event that runs after battles (or use Yanfly's Utility Common Events) that checks for that switch to be true. If yes, someone was captured.
Overcomplicating things is what I do best! Uuuunfortunately.


I think why I delved into variables was partially because I saw someone use that for an invisibility state in a tutorial video so I figured it might be something that would work for the captured state and it was all downhill from there.

Most of that is perfect and honestly that solves almost everything! Thank you so much 😀

Except for "You take the state off" So that's where I'm confused and I still don't know how. I'm still at where I was in post 13 on that one and it's probably the toughest banana in the bunch to me. How do I remove the captured state from the actor when the transformed state is removed from the enemy before the timer runs out? I get how to do the countdown for it ending naturally, that's just setting the turn end and with Hime's progressive states I'm pretty sure I can have it flip them from that directly into the knockout state when the turns run out and if I'm understanding her plugin correctly it won't do that if it's removed prematurely. But how do I end it when the enemy is de-transformed so the character is "Saved" rather than ko'd like they will be when the timer runs out? I think this is where I keep spiraling into chaos trying to solve it (besides the invisibility thing which was solved with Kenen's code and doing a full playtest rather than battle test so at least I'm good on that). There's probably a super simple way to do it I just don't know about/understand yet.

Also quick clarifying question how do I set a parallel event to just check when a battle ends or is it just always going and checking for X all the time? I did read on the forum that if you have a ton of autorun/parallel events just constantly checking forever it will lag the game so it's best not to use too many of them if you can avoid it so I want to make sure I don't go overboard. Also, is there a repository of js commands like the "gameSwitches.setValue" command anywhere to couple with the custom add/remove effects or is that just a "know javascript already" thing?
Less text, more line breaks 🤣

Except for "You take the state off" So that's where I'm confused and I still don't know how.
Easiest way requires Yanfly's Buffs & States and State Categories. If you don't have the latter, there can be a more complex workaround.

In the state that goes on the target:
Code:
<Custom Apply Effect>
target.battler().opacity=0;
origin._captured=target;
</Custom Apply Effect>

In the transformed state:
Code:
<Category: Bypass Death Removal>
<Custom Respond Effect>
if ((target.hp<=0 || target.isDead()) && target._captured)
    target._captured.removeState(X);
</Custom Respond Effect>
where X is the ID of your target's state.

Also quick clarifying question how do I set a parallel event to just check when a battle ends or is it just always going and checking for X all the time?
To use a parallel event you'd have to put a copy on every map. Make it parallel or autorun, do the check and stuff you want, then Erase Event. It will reload every time you come back to the map including after battle.

I think this is an inefficient route compared to the Utility Events plugin.

Also, is there a repository of js commands like the "gameSwitches.setValue" command anywhere to couple with the custom add/remove effects or is that just a "know javascript already" thing?
There's a pinned thread in the MV support forum of MV script calls. You can also Google whatever you're looking for, pretty much everything has been asked about MV at this point.

Less text, more line breaks 🤣


Easiest way requires Yanfly's Buffs & States and State Categories. If you don't have the latter, there can be a more complex workaround.

In the state that goes on the target:
Code:
<Custom Apply Effect>
target.battler().opacity=0;
origin._captured=target;
</Custom Apply Effect>

In the transformed state:
Code:
<Category: Bypass Death Removal>
<Custom Respond Effect>
if ((target.hp<=0 || target.isDead()) && target._captured)
    target._captured.removeState(X);
</Custom Respond Effect>
where X is the ID of your target's state.


To use a parallel event you'd have to put a copy on every map. Make it parallel or autorun, do the check and stuff you want, then Erase Event. It will reload every time you come back to the map including after battle.

I think this is an inefficient route compared to the Utility Events plugin.


There's a pinned thread in the MV support forum of MV script calls. You can also Google whatever you're looking for, pretty much everything has been asked about MV at this point.

Ah my bad, I truly am trying to be better about that, it's just a bad habit.

So great news and bad news! The code you gave me works perfectly to add and remove the state! But unfortunately, something about it stopped Kenen's script from working. I disabled Kenen's script as a plugin and yours does work to make the character invisible. Unfortunately now we're back to them not turning visible again when the state is removed haha...

I tried futzing around with it a bit. Since I figured from what I was seeing there was nothing telling the system to turn them visible again I tried changing the second part to:


Code:
<Category: Bypass Death Removal>
<Custom Respond Effect>
if ((target.hp<=0 || target.isDead()) && target._captured)
    target._captured.removeState(X);
if ((target.hp<=0 || target.isDead()) && target._captured)
    target.battler().opacity=255;
</Custom Respond Effect>

I thought that by duplicating the conditions and command in reverse it might do both but it didn't do anything and I don't think that's how the flow of js works so I'm not sure what to do ^_^;;; I did also try removing the
target.battler().opacity=0;
but it still stopped it from working somehow though I can't for the life of me figure out why it would unless Kenen's just doesn't work for when the status is removed prematurely so one problem solved, another problem unsolved haha.

Thank you for that link to the call list! I wasn't sure what to call them so I wasn't coming across it.

Edit: I SWEAR it was working, I really thought it did, but now all of a sudden it's not. I did remove and re-input it a couple of times while messing with it but I copypasted it fresh straight out of your message and now it's not working and I'm questioning myself if it actually was the first time.

This is exactly what I have on the Transformed status:

Code:
<Custom Apply Effect>
// Check if the user is an enemy.
if (user.isEnemy()) {
  // Archive the previous enemy ID.
  user._prevEnemyId = user._enemyId;
  // Set the target enemy ID you want the enemy to change into.
  var transformEnemyId = 6;
  // Transform the user.
  user.transform(transformEnemyId);
}
</Custom Apply Effect>


<Custom Remove Effect>
// Check if the user is an enemy.
if (user.isEnemy()) {
  // Retrieve the archived enemy ID.
  var transformEnemyId = user._prevEnemyId;
  // Transform the enemy back.
  user.transform(transformEnemyId);
  // Clear the archived data.
  user._prevEnemyId = undefined;
}
</Custom Remove Effect>


<Category: Bypass Death Removal>
<Custom Respond Effect>
if ((target.hp<=0 || target.isDead()) && target._captured)
    target._captured.removeState(17);
</Custom Respond Effect>

And this is exactly what I have on the Captured status:

Code:
<Custom Apply Effect>
target.battler().opacity=0;
origin._captured=target;
</Custom Apply Effect>
I haven't looked super closely at what Kenen gave you, but you should not be using both of these solutions.

What I'm giving you has the commands to change opacity directly in applying and removing the state. You shouldn't also have code to do that in one of the underlying game functions.

Original thread: https://forums.rpgmakerweb.com/threads/making-an-actor-invisible-in-battle.159849/