VXAce Check Enemy ID when THEY use a skill

I'm helping a friend with his game and he wants to add a system where enemies can run away from battle only to later hijack other battles by surprise while also being stronger.

My solution to this is to have a Run Away skill that specific enemies can use, which activates a Common Event that checks the caster's database ID, let's say Enemy:008, and accordingly turn ON the Switch Enemy008Vendetta. However my issue comes with making said skill check for the enemy's database ID as all my attempts, i.e putting v[5] = b.id in the damage formula, but alas nothing works, you guys know how to achieve it ?
If it's a skill the enemy uses, shouldn't it be a.id? Or if it uses it on itself, a and b are the same? Not sure :LZSlol:

Maybe show us what the damage formula and the common event page look like exactly.
Maybe show us what the damage formula and the common event page look like exactly.
Here's the skill itself, it never really worked out and I tried doing it with different scopes, different formulas including a.id or enemy_id but none worked

the Common Event currently has nothing going on besides a debugging text message to check if it actually stores the ID from the enemy who casts it aaand... yeah it doesn't
So I had something similar I wanted to do (putting an actor's ID into a variable in a damage formula, for an escape skill) and your question made me realize that it's not working for me either*, so thanks.

Now I tried getting the actor ID right in the common event. I have the script call for that, so it was easy and it worked: I set the variable to $game_party.target_actor.id . I'm afraid I don't know how to do it with enemies, though. It will be something with $game_troop.

Hopefully someone else will help.

*(I just checked and my escape skill has scope set to none, when I changed it to user, the variable in the damage formula worked, so I'm not sure why it's not working for you :LZSskeptic: But maybe getting it from the common event would be better, since then you don't need to have the HP damage chosen).
Hello,

Enemy ids are not gathered with .id method (it does not exists for Game_Enemy), you should use .enemy_id instead.

Here is a formula I just tried on an (almost) empty project:
1762026000574.png


The formula:
(v[10] = a.enemy_id)*0

v[10] = x will return value x, so I multiply the result by 0 to avoid changing the battler's stats and I used MP recover instead of HP damage/recover to avoid battle messages about the battler taking no damage.

EDIT: note that if you design your skill to work for both actors and enemies, you can put conditions like .actor? or .enemy? to get something like this:
(v[10] = a.actor? ? a.id : 0) * (v[11] = a.enemy? ? a.enemy_id : 0)
This would always return 0, when an actor casts the skill, their id is stored in variable 10, when an enemy casts it, their id is stored in variable 11. The other variable is set to 0 so you can check in your common event which kind of battler has cast the spell.
v[10] = x will return value x, so I multiply the result by 0 to avoid changing the battler's stats and I used MP recover instead of HP damage/recover to avoid battle messages about the battler taking no damage.
Damage formulas use the last value provided as the result.
You don't need to multiply the value to get 0.
Simply use
(a.actor? ? v[10] = a.id; v[11] = 0 : v[10] = 0; v[11] = a.enemy_id) ; 0
a.actor? ? (v[10] = a.id; v[11] = 0) : (v[10] = 0; v[11] = a.enemy_id) ; 0
Damage formulas use the last value provided as the result.
I forgot we could put multiple instructions ahah, thank you!
a.actor? ? v[10] = a.id; v[11] = 0 : v[10] = 0; v[11] = a.enemy_id ; 0
This however, does not work. I am not familiar enough with ternary operators but I don't think you can put multiple instructions in each case (and syntactically I wouldn't know when the else case ends).

Maybe something like this would be shorter?
v[10] = v[11] = 0; a.actor? ? v[10] = a.id : v[11] = a.enemy_id; 0
(and syntactically I wouldn't know when the else case ends)
You may be right. But I think it will work. Of course I would have to test, but if it was all in brackets....
This the error from your first formula:
1762064970618.png


(a.actor? ? v[10] = a.id; v[11] = 0 : v[10] = 0; v[11] = a.enemy_id) ; 0
Unsurprisingly, this one creates the same error.

After a bit of testing this one works:
a.actor? ? (v[10] = a.id; v[11] = 0) : (v[10] = 0; v[11] = a.enemy_id) ; 0

I never thought parenthesis could span over multiple instructions but it seems we can in Ruby... I don't like this syntax x)
I don't like this syntax x)
Was adding this functionality to my code cheat sheet when I came across this one.
Code:
v[10] = a.actor? ? a.id : 0 ; v[11] = a.actor? ? 0 : a.enemy_id ; 0
Slightly shorter and doesn't use parentheses.

Original thread: https://forums.rpgmakerweb.com/threads/check-enemy-id-when-they-use-a-skill.180804/