How can I store enemy ID for a talk system?

Hi!

I want to make a talk system similar to a SMT game into my project. I don't think a plugin is needed, but if there's any plugin that can solve my problem, It would be great too!

Basically, I want to make a very simple skill that can start a conversation with an enemy based on the enemy ID of the target. I created a Common Event, but I'm unsure of which script call I should use, or how I should use it...

If I can somehow store the target enemy ID into a variable, I think I can then make a Condition for each enemy ID... How should I do it?

Thanks!
You can use BattleManager.actor()._lastTargetIndex for this.
You can use BattleManager.actor()._lastTargetIndex for this.

Thanks! But how should I use it exactly? I tried to paste that line as a script call for a variable, but it didn't work as intended... It simply won't show any messages on battle. What should I do?

01.png
It works fine for me; are you remembering the indexes start at 0? (you also don't need it to be parallel process; just have the Talk skill call the common event)
It works fine for me; are you remembering the indexes start at 0? (you also don't need it to be parallel process; just have the Talk skill call the common event)

Yep, I though it started at 1 lol.

It's working perfectly now. Thanks!
Always happy to help. 🙂
You can use BattleManager.actor()._lastTargetIndex for this.
Is that actually correct if you have more than one actor in the party, though? What I would expect to get from that in the common event is the last enemy targeted by the actor in the last position in the party.
No, it stores the index of the most recent target (which will be the enemy you targeted with the skill).

BattleManager.actor() returns the actor that is *currently acting* which when the skill executes will be the one who used the skill that called the common event.
When does that common event actually execute? I know that items "reserve" a common event to execute at the next opportunity... which is when exactly?
It's executed as part of execution of the skill; the common event happens after damage is applied.
Ah okay, so it should work then.
Funnily enough I'm currently writing the new Jump into Javascript and I'm on Game_Action, which will break down how this works.
Funnily enough I'm currently writing the new Jump into Javascript and I'm on Game_Action, which will break down how this works.
I glanced at the first entry to that but it seemed a little too basic for me... that is, everything in the first entry was something I already knew or could have easily figured out from the code myself. Do later entries have less of a "just translate the JavaScript code into English prose" angle than the first one did?
I glanced at the first entry to that but it seemed a little too basic for me... that is, everything in the first entry was something I already knew or could have easily figured out from the code myself. Do later entries have less of a "just translate the JavaScript code into English prose" angle than the first one did?

Nah, not in this series. It was literally designed to be a "just translate the JavaScript into English" though I have started noting interesting aspects of the code and why they were done that way.

What would you find more helpful?
I did some more tests, and I think I may have done something wrong... It's always returning the variable value as 0, even if I target another enemy.

For example, I want enemy ID below 20 to have a default message, So I set that if Variable 21 is Less than or equal to 19, it will give the default message.

If Variable 21 is equal to 20, it will give message 1.

If Variable 21 is equal to 21, it will give message 2, etc.

From Enemy ID 1 to 20 (which I guess would be from 0 to 19 for the variable), I have set the monsters which you can't talk to. But if I start a battle with Enemy ID 21, it stills shows the default message and, once outside of the battle, it shows Variable 21 as 0 on the debug menu.
The code I gave you returns the *enemy index* of the last target, not the ID of its entry in the database. Did you want the ID of the actual enemy type selected?
Nah, not in this series. It was literally designed to be a "just translate the JavaScript into English" though I have started noting interesting aspects of the code and why they were done that way.

What would you find more helpful?
I'm sure that approach is helpful for some people, it's just that I already know JavaScript so I can more or less read the code directly and understand what it's doing.

Basically I need to understand some stuff about how the engine works so I can figure out how to modify it. I have a thread in JS/Plugin support about one of the things I need, but no useful responses yet.

I did some more tests, and I think I may have done something wrong... It's always returning the variable value as 0, even if I target another enemy.

For example, I want enemy ID below 20 to have a default message, So I set that if Variable 21 is Less than or equal to 19, it will give the default message.

If Variable 21 is equal to 20, it will give message 1.

If Variable 21 is equal to 21, it will give message 2, etc.

From Enemy ID 1 to 20 (which I guess would be from 0 to 19 for the variable), I have set the monsters which you can't talk to. But if I start a battle with Enemy ID 21, it stills shows the default message and, once outside of the battle, it shows Variable 21 as 0 on the debug menu.
There are only up to 8 enemies in a battle (unless you have a plugin that adds more), so this method will never return a number greater than or equal to 8. If you want the ID of the enemy in the database, use this instead:

Code:
$gameTroop.members()[BattleManager.actor()._lastTargetIndex].enemyId()

You can see that it incorporates the formula from before but adds more to it. This index will start from 1, rather than 0.
I'll check out your thread and see if I can help. The plan once I've finished breaking down the default code is expanding into engine customisation and more interesting stuff.
I'm sure that approach is helpful for some people, it's just that I already know JavaScript so I can more or less read the code directly and understand what it's doing.

Basically I need to understand some stuff about how the engine works so I can figure out how to modify it. I have a thread in JS/Plugin support about one of the things I need, but no useful responses yet.

There are only up to 8 enemies in a battle (unless you have a plugin that adds more), so this method will never return a number greater than or equal to 8. If you want the ID of the enemy in the database, use this instead:

Code:
$gameTroop.members()[BattleManager.actor()._lastTargetIndex].enemyId()

You can see that it incorporates the formula from before but adds more to it. This index will start from 1, rather than 0.

Yeah, I wanted to get the enemy ID from the database. I used the line you suggested, but it's still returning only 0... Should I put it somewhere else? I'm using the Script function inside Control Variable.
Whereabouts do you have this line, exactly? Can you show screenshots?

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-store-enemy-id-for-a-talk-system.123374/