Check to see if any enemy has state applied for allowing skill to appear

Snuh

Villager
Member
Joined
Feb 23, 2016
Messages
25
Reaction score
5
First Language
English
Primarily Uses
Hi!


I'm trying to add a skill that needs to check if an enemy is afflicted with a state before the skill appears and can be used. I'm using Yanfly skillcore ect and have come up with this, but i get 'gametroop is undefined' errors. It's true that I haven't defined an enemy note tag, because I want it to check for one with the state applied..


<Custom Show Eval>


if ($game_troop.members().isStateAffected(X)) {


visible = true;


} else {


visible = false;


}


</Custom Show Eval>


any help i appreciated!
 

Victor Sant

Veteran
Veteran
Joined
Mar 17, 2012
Messages
1,694
Reaction score
1,452
First Language
Portuguese
Primarily Uses
1. "$game_troop" is from VX Ace, not from MV. The correct code for MV is "$gameTroop".


2. "$gameTroop.members()" is an array, a list with all enemies. you need to specify the index of the enemy if you want to use the function "isStateAffected()". For example "$gameTroop.members()[0].isStateAffected(X)" (this will check the first enemy.)
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
I've moved this thread to JS/Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.
 

Snuh

Villager
Member
Joined
Feb 23, 2016
Messages
25
Reaction score
5
First Language
English
Primarily Uses
Fantastic! Made changes as above and it works on a fight with one enemy. do i replicate the line or is there a way to check to see if all the enemies in the fight have the state?
 

Victor Sant

Veteran
Veteran
Joined
Mar 17, 2012
Messages
1,694
Reaction score
1,452
First Language
Portuguese
Primarily Uses
to check if all enemies have the state.


$gameTroop.aliveMembers().every(function(member) { return member.isStateAffected(X) })


To check if at last one have the state.


$gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(X) })
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
You might also need to use aliveMembers() rather than members() if you only want to check the enemies still remaining.
 

Victor Sant

Veteran
Veteran
Joined
Mar 17, 2012
Messages
1,694
Reaction score
1,452
First Language
Portuguese
Primarily Uses
You might also need to use aliveMembers() rather than members() if you only want to check the enemies still remaining.
In fact, for the 'every' you must use it, otherwise if a single enemy is dead it will not have the state and the condition will be never met.


I will even edit the other post.
 

Snuh

Villager
Member
Joined
Feb 23, 2016
Messages
25
Reaction score
5
First Language
English
Primarily Uses
Thanks so much for your help! I've entered in this:


<Custom Show Eval>


if ($gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(X) }) { 


visible = true;


} else {


visible = false;


}


</Custom Show Eval>


however, I'm getting an 'unexpected token {' error


I'm very new at this and I appreciate your help and patience, but I can't figure out what is wrong here.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
You need an extra )


Here's what you have, vs what you need:

Code:
if ($gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(X) }) { 

if ($gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(X) })) {
 

Snuh

Villager
Member
Joined
Feb 23, 2016
Messages
25
Reaction score
5
First Language
English
Primarily Uses
That's got it! Thanks so much!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!

Forum statistics

Threads
106,036
Messages
1,018,461
Members
137,821
Latest member
Capterson
Top