As mentioned in the title, I try to check if a certain enemy is using a skill through JS. Something like this but for enemies.
if (user == $gameActors.actor(x))if (user == $gameActors.actor(x))if (user.isEnemy() && user.index() === 0) alert('enemy leader used a skill!');
if (user.enemyId?.() === 5) alert('enemy ID 5 used a skill!');
Maybe I'm wrong too. But these examples are for a skill formula, aren't they? I actually want to check in a notetag who is currently using this skill. This skill can be used by actors and enemies and there is an actor who is also represented as an enemy and if he uses this skill I want to change the cost.
<JS TP Cost>
if (user == $gameActors.actor(12)) {
cost = 0;
} else {
cost = $gameVariables.value(297) * 1;
}
</JS TP Cost>
The conditions I suggested should work in any context where
user refers to an instance of Game_Battler, i.e. an actor or an enemy. This does not, by default, include item/skill formulae. Variables available in scripted notetags will vary depending on how the corresponding plugin is coded.If you want to check for a specific enemy ID (case 2), I think something like this should work:
if (user === $gameActors.actor(12)) {
cost = 0; // actor ID 12
} else if (user.enemyId?.() === 34) {
cost = 0; // enemy ID 34
} else {
cost = $gameVariables.value(297) * 1;
}
?. is the optional chaining operator. It's a shorthand to check if user.enemyId exists before trying to evaluate it. Alternatively you could write something like this:if (user.isEnemy() && user.enemyId() === 34) {
<JS TP Cost>
if (user === $gameActors.actor(12) || user.enemyId?.() === 25 || user.enemyId?.() === 26 || user.enemyId?.() === 27 || user.enemyId?.() === 28 || user.enemyId?.() === 29 || user.enemyId?.() === 30 || user.enemyId?.() === 31) {
cost = 0;
} else {
cost = $gameVariables.value(297) * 1;
}
</JS TP Cost>
Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-check-if-skill-user-is-a-certain-enemy-in-the-database.138648/