MZ Make an actor untargetable with a state?

Hello!

As the title says, I'm wondering if it's possible with VisuStella plugins to make an ally completely untargetable. I put "with a state" in the title as I assume there'd be a way to do it with JS notetags, but I'm not sure.

If anyone's wondering what I need it for:

1673098122306.png


I have a fun boss here that every once in awhile "eats" an actor, preventing that actor from moving and slowly taking damage for a couple turns. But with how the skill is set up, that actor can still be targeted by allies and by any AoE attacks from the enemy.

I'm aware just KOing the ally or removing them from the party would also solve the problem, but I'd rather not do either of those two things for other reasons.
I think the easiest way to do this is with

Give all the other party members taunt, and the worm can only attack them.
That would be a partial solution, but other allies would still be able to target the consumed ally (i.e. with healing spells/etc)
That's true. You can add a notetag from VisuStella Battle Core to restrict the targeting of every ally-targeting skill in your game.

I can't think of any existing way to do this from the other direction, putting something onto a state that prevents the actor from being targeted.
I'm aware just KOing the ally or removing them from the party would also solve the problem, but I'd rather not do either of those two things for other reasons.
I keep thinking about this because it is a mechanic that I have considered. This happens in Wizardry 8 with one of the monsters...appropriately named a Swallower. In that game, your character's photo becomes a ? I think and they take damage until you actually kill the monster.

Every alternative I have considered doesn't seem as good as removing the character from the party. Was there a specific reason why removing the character wasn't ideal?

Just curious.
Was there a specific reason why removing the character wasn't ideal?
I'm not the OP, but just throwing out reasons I would consider it not ideal (feasible, as with many other things, but not preferable):
- It might mess with party order, at the least, and potentially other things if there are any formation plugins or anything like that in use.

- If the actor is out of the party, you wouldn't see their information on the battle status window. So you couldn't see they're taking continual damage (you could display a regular text window saying "blah blah took 5 damage," but that might be kludgy, and you wouldn't have a continual reference for their current health).

- Taking actors in and out of the party can cause jankiness with things like turn order displays (which the OP doesn't appear to be using, but hey).

All of those things could be overcome, but at that point it would be easier to code a little plugin for the targeting process that tells it to ignore anyone with a specific notetag.

Code:
Game_Unit.prototype.randomTarget = function() {
    let tgrRand = Math.random() * this.tgrSum();
    let target = null;
    for (const member of this.aliveMembers()) {
        tgrRand -= member.tgr;
      if (member.states().some(state => $dataStates[state.id].meta["notarget"]))
        continue;
        if (tgrRand <= 0 && !target) {
            target = member;
        }
    }
    return target;
};

Game_Action.prototype.itemTargetCandidates = function() {
    var targets;
    if (!this.isValid()) {
        return [];
    } else if (this.isForOpponent()) {
        targets = this.opponentsUnit().aliveMembers();
    } else if (this.isForUser()) {
        targets = [this.subject()];
    } else if (this.isForDeadFriend()) {
        targets = this.friendsUnit().deadMembers();
    } else {
        targets = this.friendsUnit().aliveMembers();
    }
    targets=targets.filter(target => !target.states().some(state => $dataStates[state.id].meta["notarget"]));
    return targets;
};

Try pasting the above into a text editor, save as a *.js file and include as a plugin. Put the notetag <notarget> on your swallowed state.

I did not test it, so let me know if there are any errors. Also, if you're using any VisuStella plugins, there's no way to check if they modify the same functions, so there may be conflicts.
I keep thinking about this because it is a mechanic that I have considered. This happens in Wizardry 8 with one of the monsters...appropriately named a Swallower. In that game, your character's photo becomes a ? I think and they take damage until you actually kill the monster.

Every alternative I have considered doesn't seem as good as removing the character from the party. Was there a specific reason why removing the character wasn't ideal?

Just curious.

I have a set party order in game that I don't like to mess with unless absolutely necessary. I also wanted to keep the member in the party so they could take damage from being consumed.

Thanks @ATT_Turan ! Just to be clear, do I need to put the ID of the untargetable state in this line?

Code:
targets=targets.filter(target => !target.states().some(state => $dataStates[state.id].meta["notarget"]));
Just to be clear, do I need to put the ID of the untargetable state in this line?
Nope! Per the instructions above, paste it as it is into a plugin and let me know if it works or not.

It should cause anyone with a state that has the <notarget> tag to be unavailable for ally or enemy targeting.
My bad, I missed that part in the original post 😅

I saved the code as a plugin and tried making a <notarget> state, but it didn't seem to work, at least for allies targeting other allies. I tried after turning off all other plugins and still couldn't get a result.
Okay. It's kind of annoying that MZ has, like, three or four ways it makes target lists under different circumstances.

Try adding this in:
Code:
Game_Action.prototype.makeTargets = function() {
    let targets = [];
    if (!this._forcing && this.subject().isConfused()) {
        targets.push(this.confusionTarget());
    } else if (this.isForEveryone()) {
        targets.push(...this.targetsForEveryone());
    } else if (this.isForOpponent()) {
        targets.push(...this.targetsForOpponents());
    } else if (this.isForFriend()) {
        targets.push(...this.targetsForFriends());
    }
    targets=targets.filter(target => target && !target.states().some(state => $dataStates[state.id].meta["notarget"]));
    return this.repeatTargets(targets);
};
Thank you! So when the turn begins, I initially got this error:

1673559928304.png

So I went ahead and changed this line from your latest code block instead of a constant:

Code:
let targets = [];

Anyway with this setup, I can still target the ally with the <notarget> state, however any skill or item used on them will fail or target another ally instead, which satisfies me!

I haven't tested this outside of one test battle, so I'm not sure if changing that variable off of a constant would cause any problems or not. Either way, thank you very much for all your help 😍

EDIT: After a little more testing, it turns out that this script breaks any skill that uses a VisuStella targeting notetag (e.g. <Target: 1 Random Allies>, <Target: X Random Enemies>, etc). It seems like this code should still work as long as the dev isn't using targeting notetags from VisuStella's Battle Core.
So I went ahead and changed this line from your latest code block instead of a constant:
Heh, sorry, that was definitely my fault for half copy/pasting and half typing code.

EDIT: After a little more testing, it turns out that this script breaks any skill that uses a VisuStella targeting notetag
Yeah, there's basically no way around that. Because the VisuStella plugins have obfuscated code, none of the rest of us can look up their modified functions and account for them.

I'm glad it's good enough! There are a couple of other targeting functions, if one stuck the same code into enough of them you'd eventually not be able to select the target at all...I thought I had found the one 😕

I put the all the functions from this thread into one plugin file for more convenient grabbing.
I'm going to test out that last block of code you wrote again, except by adding your extra code directly into the core script instead of over-writing it in a new plugin.

So far after a few test battles, it's working as it originally was (can still target the ally with a <notarget> state, but the skill or item will fail), and doesn't seem break VisuStella's targeting notetags.

Usually modifying the core script is a no-no, but this seems to be working so far, so I'll just have to remember not to update my corescript. :hhappy:

Original thread: https://forums.rpgmakerweb.com/threads/make-an-actor-untargetable-with-a-state.153848/