How to check if enemy has a certain skill?

Dawsmead

Villager
Member
Joined
Mar 22, 2023
Messages
16
Reaction score
1
First Language
English
Primarily Uses
RMMZ
Seems like a very noob question but I couldn't find anything in the script call sheets...

In a common event, is there a way to check if an enemy has a certain skill? Basically the same thing that "actor.hasSkill(skill id)" does but for enemies?
 

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
45,989
Reaction score
16,776
First Language
English
Primarily Uses
RMMV
Enemy skills aren't changeable through the game like an actor's skills are - unless you have some plugin to alter it, enemies will only have the skills you give them when you create them.

If you didn't know what enemy you were going to be facing and wanted to know if they had a particular skill, you'd need a script call to look at all the attack patterns to see if the skill was in the list. But even then it doesn't mean they'd USE the skill, as they may have conditions or priorities or requirements that would prevent them using it.

You might need to give a little context to what you're trying to do, as the most obvious answer (is this skill in the enemy's list) may not give you quite what you want.
 

Dawsmead

Villager
Member
Joined
Mar 22, 2023
Messages
16
Reaction score
1
First Language
English
Primarily Uses
RMMZ
You might need to give a little context to what you're trying to do, as the most obvious answer (is this skill in the enemy's list) may not give you quite what you want.
I'm currently using some skills as "tags" to mark which actors and enemies can trigger certain things when using / being targeted by a skill.

For example, when an actor's equipped weapon or armor has a skill called "tag: magnetic", then when he's affected by a AOE skill called "Magnetism" he takes extra damage and gets stunned. The "tag: magnetic" skill itself does nothing and doesn't show up in the players battle options.

In the common event for the skill "Magnetism", I have a check to see if target ".hasSkill(skill id for tag: magnetic)" and this part works fine when the target is an actor.

However, I want some enemies to be magnetic too, but after I give the "tag: magnetic" skill to some enemies (since I can't give them weapon or armor), I don't know how to check for that in the "Magnetism" common event to do the "extra damage and gets stunned" thing.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,718
Reaction score
6,537
First Language
English
Primarily Uses
RMMV
I suggest a more efficient way to implement this would be with passive states, such as from the VisuStella Skills and States Core.

You can make a Magnetic state and have every relevant piece of equipment grant the passive state. You can also just put it into the note boxes of enemies who should have it.

Then you use the script call provided in the plugin instructions to check for that state and it works universally on actors and enemies.

If you want to stick to your method, the way to see if a skill is in an enemy's list is rather convoluted. I'm not sure how you're referencing the enemy, so I'll just use the variable target
Code:
$dataEnemies[target.enemyId()].actions.some(action => action.skillId==X)
where X is the ID of the skill you're checking for.
 

Dawsmead

Villager
Member
Joined
Mar 22, 2023
Messages
16
Reaction score
1
First Language
English
Primarily Uses
RMMZ
I suggest a more efficient way to implement this would be with passive states, such as from the VisuStella Skills and States Core.

You can make a Magnetic state and have every relevant piece of equipment grant the passive state. You can also just put it into the note boxes of enemies who should have it.

Then you use the script call provided in the plugin instructions to check for that state and it works universally on actors and enemies.

If you want to stick to your method, the way to see if a skill is in an enemy's list is rather convoluted. I'm not sure how you're referencing the enemy, so I'll just use the variable target
Code:
$dataEnemies[target.enemyId()].actions.some(action => action.skillId==X)
where X is the ID of the skill you're checking for.
Thanks for the suggestion! I tried out the passive state method on the "Magnetism" skill and it seems to work well! I also would like to convert other skills I made to this method, and I have a couple of follow-up questions if you don't mind:

1. Is there a maximum number of active & passive states a character can have at the same time? I've been using quite a few states already to limit the number of uses of some skills per battle.

2.
Code:
a.states().!includes($dataStates[state id])
Is this how you would check for NOT having a passive state?

3. Is there an easy way to add a passive state to the user of a skill, if the skill itself is targeting an enemy? When I put the "<Passive State: x>" in the skill note tag, it seems to always try to put the passive state on the target.

Thanks in advance!
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,718
Reaction score
6,537
First Language
English
Primarily Uses
RMMV
1. Is there a maximum number of active & passive states a character can have at the same time? I've been using quite a few states already to limit the number of uses of some skills per battle.
Not mechanically. I have seen a couple of people using MV claim they get lag when they have, like, a dozen or more, but I don't know if they might have had bad code in those states or under-qualified computers.

If you have a lot of these traits, you might find it even better to just use notetags instead. Similarly for how you checked a skill in their list,
Code:
$dataEnemies[target.enemyId()].meta.magnetic
will return true if the target has the notetag <magnetic> in their database entry.

3. Is there an easy way to add a passive state to the user of a skill, if the skill itself is targeting an enemy? When I put the "<Passive State: x>" in the skill note tag, it seems to always try to put the passive state on the target.
That seems weird - you can't "put" a passive state on anything unless it's by equipping an armor/weapon with the notetag.

Putting the passive state notetag on a skill should give that state to any actor as soon as they learn the skill.

But you can just apply the state to the target non-passively, in the same ways you apply any state.
 

Dawsmead

Villager
Member
Joined
Mar 22, 2023
Messages
16
Reaction score
1
First Language
English
Primarily Uses
RMMZ
If you have a lot of these traits, you might find it even better to just use notetags instead. Similarly for how you checked a skill in their list,
Does this work on actors if I put note tags on weapons / armors? I tried putting a <magnetic> tag in a weapon and have the actor equip it, and when I use
Code:
actor().meta.magnetic
it returns negative.

Then I guess I need to set up a conditional branch
Code:
$subject.isActor()
and do a passive state check for actors, and a meta notetag check for enemies?


Putting the passive state notetag on a skill should give that state to any actor as soon as they learn the skill.
Ah I misunderstood how it works on skills. I was reading the description of passive state tags and it says "If you plan on applying a passive state through a skill, it must be through a skill that has been learned by the target", so I gave the enemy that skill too.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,718
Reaction score
6,537
First Language
English
Primarily Uses
RMMV
I tried putting a <magnetic> tag in a weapon and have the actor equip it, and when I use
Code:
actor().meta.magnetic
it returns negative.

Then I guess I need to set up a conditional branch
Code:
$subject.isActor()
and do a passive state check for actors, and a meta notetag check for enemies?
I feel like my attempts to help you are confusing you more.

1 - actor() is not a valid reference in any situation or notetag that I'm familiar with.
2 - I suggested the notetag as a way to cut down on having states and doing messy junk, not as something you'd implement if it forced you to do multiple checks for every tag. If a solution makes your life more complicated instead of less, ignore it.

it says "If you plan on applying a passive state through a skill, it must be through a skill that has been learned by the target", so I gave the enemy that skill too.
To go back to your very first question at the beginning of the thread - enemies do not have "learned" skills. Only actors do.
 

Dawsmead

Villager
Member
Joined
Mar 22, 2023
Messages
16
Reaction score
1
First Language
English
Primarily Uses
RMMZ
2 - I suggested the notetag as a way to cut down on having states and doing messy junk, not as something you'd implement if it forced you to do multiple checks for every tag. If a solution makes your life more complicated instead of less, ignore it.
I think I'll just use passive state in this skill for now; the note tag method is very helpful for some other skills I'm trying out. Thx for the help!
 

Latest Threads

Latest Posts

Latest Profile Posts

Ooops ended up trying out making my own A2 tile page instead of testing doors everywhere. Went well so far I think.
I guess I'm done making a blue squirrel's life difficult for posting new threads on different forums.
That's just for today so don't get used to this, squirrel-ish friend! :p
Got new hard drive, now trying to install the softwares I lost to the dead drive, and more than half of them won't install because they're already installed on the dead drive, and uninstallers won't run because they can't find where their programs are installed. So I take it having a drive die on you screws you in more ways than just data loss. >:\
PC got fixed finally. Back online again. Turns out I have no business trying to self repair pcs because it was getting to like 176F / 80C. Shop installed a totally new cooling system and now it runs fine and is super quiet.
When you're making major progress, but have to stop to go to work.

Forum statistics

Threads
131,484
Messages
1,220,206
Members
173,225
Latest member
ZecaVn
Top