MZ Creating Skills that only target enemies/players with a passive state (VisuStella)

Hi,

As the title says, am trying to create a skill that will only be able to target enemies that have a certain passive state applied to them. I am using VisuStella's BattleCore and SkillsStatesCore and have been able to successfully add the passive state to an enemy. However when I use the following notetag on my skill, it still allows the player to target any enemy in the troop.

<JS Targets>
targets=user.opponentsUnit().aliveMembers().filter(member => member.isStateAffected(3));
</JS Targets>

I read in the documentation that passive states are seen differently than states that are applied directly. The documentation says that when creating a damage formula you should use "a.states().includes($dataStates[X])" to check for them rather than "a.isStateAffected(X)"

This led me to believe that maybe if I replaced "member.isStateAffected(3)" with "member.states().includes($dataStates[3])" it might work. However this resulted in the same issue.
What am I doing wrong?

Thank you in advance for any help!
A good first troubleshooting test would be to look at what that code is generating.

So copy the whole thing and stick in into a log on another line
Code:
console.log(user.opponentsUnit().aliveMembers().filter(member => member.states().includes($dataStates[3])));
Then, during the battle, press F8, go to the Console tab, and you can see the array produced by that line of code.

You can click into it and into each individual battler to check their states. You'll also see if it's generating any error.
Ok i have been playing around with it and still can't get it to work properly. I added the log line to my notetag like you suggested so it now reads:

<JS Targets>
console.log(user.opponentsUnit().aliveMembers().filter(member=>(member.states().includes($dataStates[3]))))
targets = user.opponentsUnit().aliveMembers().filter(member => (member.states().includes($dataStates[3])))
;
</JS Targets>


Unfortunately, nothing is coming up in the console when I navigate to the skill in battle during a playtest.


As I continued experimenting, I decided to try making the skill invisible instead, using the JS Skill Visible Notetag in the VS SkillsStatesCore plugin. By using a nearly identical notetag i was able to get data in the console:

<JS Skill Visible>
console.log(user.opponentsUnit().aliveMembers().filter(member=>(member.states().includes($dataStates[3]))))
visible = user.opponentsUnit().aliveMembers().filter(member => (member.states().includes($dataStates[3])))
;
</JS Skill Visible>


I have a troop set up with one enemy that has the passive state and another that does not. When i first enter battle and navigate to the Skill, I can see that it returns an array with the correct Game_Enemy inside it with the passive state shown on the enemy. If I defeat that enemy and navigate back to the Skill, it is still visible and the console returns an empty array.
Screenshot 2024-11-05 212029.png

I know I must be doing something wrong still in both cases but I'm not sure what it is :blush:
Just to clarify, when you say "navigate to" you mean you actually use the skill? It won't do anything for targeting until you've selected the skill and are targeting with it.

Aside from that, I don't know. The complete absence of anything in the log means the JS Targets notetag isn't getting evaluated at all. Unless someone else has any ideas, you may need to start a bug report with VisuStella.

As a tip, when you post code you should put it inside the CODE tags (the </> on edit bar). See how your code is all mangled and in italics?
Sorry for the late reply! Work got in the way for a bit and then I wanted to play around with it a bit before replying to make sure I was not wasting your time.

I think i may have been misunderstanding the <JS Targets> part of the BattleCore plugin. I thought it would make it so that the skill would only be able to select a target that had the indicated state, however it instead seems to search for a target with that state and attack it despite which target you pick. It would only return an array to the console once I had selected an enemy to use it on, and if I chose an enemy without the specified state it would instead attack the enemy with the specified state. So that may have just been my misunderstanding of how the plugin works.

Is there a way to have a skill only able to target an enemy that has a specified state? In MV it used to be possible with Yanflys Selection Control but I am not seeing a similar plugin fo MZ. Maybe the

With the <JS Skill Visible> notetag indicated above from the Skills and States Core Plugin, I see the array returned in the console once I highlight the skill. I tried removing the enemy with the specified state from the troop and then launching the game/battle, thinking that it would make the skill invisible in combat since there would be no enemies with the needed state present. However it still showed up and allowed me to attempt to use the skill on the enemy with no state applied. Am I misunderstanding this plugin as well?
I think i may have been misunderstanding the <JS Targets> part of the BattleCore plugin. I thought it would make it so that the skill would only be able to select a target that had the indicated state, however it instead seems to search for a target with that state and attack it despite which target you pick.
No, that doesn't make sense. From the documentation:

1731203126046.png


The notetag should be defining/limiting which battlers you're able to select as a target. If it isn't doing that, then I suggest you file a bug report with VisuStella.

With the <JS Skill Visible> notetag indicated above from the Skills and States Core Plugin...However it still showed up and allowed me to attempt to use the skill on the enemy with no state applied. Am I misunderstanding this plugin as well?
No, but you're misusing the JavaScript. 😉

The filter() method will always create an array, thus trying to use it as a boolean result (the visible variable is going to be evaluated as truthy or falsy) will always be true. The array may be empty, if there are no valid elements to place in it, but it will exist and thus that check for visible will never fail.

You could append .length to the end of it, and then visible will only be true if there is at least 1 battler in the array.
try something like this to see what's happening? I also added Turan's console line for measure

JavaScript:
<JS Targets>
console.log("Initial targets:", targets);
targets = targets.filter(target => {
  const hasState = target.states().includes($dataStates[3]);
  console.log(`Checking target ${target.name()}:`, hasState);
  return hasState;
});
console.log("Filtered targets:", targets);
console.log("enemies with passive 3:", user.opponentsUnit().aliveMembers().filter(member => member.states().includes($dataStates[3])));
</JS Targets>

Is your skill single or multi-target by default? should not make a difference, but always useful to know.
The Skill is single target by default. I've now created a troop that contains one enemy without the state and 2 enemies with the state. When I replace my notetag with the one Dark_Ansem has provided and target the enemy without the state i get the following readout in the console and the skill does not land:
Screenshot 2024-11-10 151533.png

If I target an enemy with the state, I get the following readout and it hits that individual enemy:
Screenshot 2024-11-10 153156.png


This is a step in the right direction, but I was under the impression based on the documentation for the plugin that the notetag would limit which enemies I could target with the skill prior to attacking them, thereby not allowing the user to target an enemy that did not have the state applied. It appears that the notetag is not accessed or logged until after an enemy is chosen to be attacked, so I think I am misunderstanding that aspect.

I filed a bug report with the VS Team last night and they responded with the following which seems to confirm that suspicion, unless I am totally missing the mark:
Screenshot 2024-11-10 152342.png


My aim was to do something similar to the Yanfly Selection Control plugin for MZ, where only enemies that have the specified state could be targeted so the user does not waste a move using the skill on an enemy that would be unaffected by the skill.
I hope this all makes sense, I know its a very minor difference and I hope I am explaining it well.
Thank you for your patience and all the help so far!
But when you actually use the skill, even the enemy that is not a valid target is affected? Or it just does the "invalid" sound
No, that doesn't make sense. From the documentation:

View attachment 322578

The notetag should be defining/limiting which battlers you're able to select as a target. If it isn't doing that, then I suggest you file a bug report with VisuStella.


No, but you're misusing the JavaScript. 😉

The filter() method will always create an array, thus trying to use it as a boolean result (the visible variable is going to be evaluated as truthy or falsy) will always be true. The array may be empty, if there are no valid elements to place in it, but it will exist and thus that check for visible will never fail.

You could append .length to the end of it, and then visible will only be true if there is at least 1 battler in the array.

Adding .length fixed the visibility issue! Thank you so much!
Now if I can just figure out the targeting I will be all set...
The Skill is single target by default. I've now created a troop that contains one enemy without the state and 2 enemies with the state. When I replace my notetag with the one Dark_Ansem has provided and target the enemy without the state i get the following readout in the console and the skill does not land:
makes sense. targets was initially the one battler that didnt have the state. you didnt use $gameTroop.members() or user.opponentsUnit().members()

cant speak on how to limit the selection at all though. best i can say is just making it retarget a battler that has the state that is alive, but the player would still be able to target one enemy and hit a separate one
But when you actually use the skill, even the enemy that is not a valid target is affected? Or it just does the "invalid" sound
When I use the skill on an invalid enemy, the skill initializes and plays the animation, then nothing happens and it moves on to the enemy's turn, which is what I would expect and working as it should. My issue is that I want the user not to be able to target this enemy with the skill in the first place
From what I understand, skill targeting after the skill has been activated, and controlling who you can select before that are two different things. (As per what they say in the comments for JS Targets: 'This is NOT used for filtering out who the player can or cannot select.')

On MV, there was the Yanfly Selection Core that handled these sorts of things, but as per this article from Visustella, they have no intentions of porting this over: http://www.yanfly.moe/wiki/Why_Certain_Plugins_Wont_Be_Ported#Selection_Control_.28YEP.29

Granted, due to sponsored contributions, they have ported over certain features of this such as being able to swap skills between allies and enemies and swap from targeting single to all. But nothing like conditional selection as far as I know, unless I'm misunderstanding something.
I have a plugin called Cae_OnUseEffects, linked from here:
It has a <target filter: code> notetag for skills/items, so you could try this:

<target filter: return target.states().includes($dataStates[3]);>
If you want to try it, I'd recommend loading my plugin after VisuStella's. Remember to save your project to apply Plugin Manager changes before testing. 👋
As per what they say in the comments for JS Targets
Well, I looked the tag up, like, twice and didn't manage to properly read that 😛 (can't speak for the OP/others)

Thanks for the clarification.
I have a plugin called Cae_OnUseEffects, linked from here:
It has a <target filter: code> notetag for skills/items, so you could try this:

<target filter: return target.states().includes($dataStates[3]);>

If you want to try it, I'd recommend loading my plugin after VisuStella's. Remember to save your project to apply Plugin Manager changes before testing. 👋
YAY! This did exactly what I needed 😀😀😀

Thank you everyone for all the help! This ticket can be closed 🤘
Great, happy RPG Making!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

(In future you can click the Report button on your own post and give a reason like "problem solved" or "thread can be closed". No need this time though, since I'm already here.)

Original thread: https://forums.rpgmakerweb.com/threads/creating-skills-that-only-target-enemies-players-with-a-passive-state-visustella.173018/