How can I store enemy ID for a talk system?

ShiningRomantica

Villager
Member
Joined
Mar 9, 2020
Messages
18
Reaction score
1
First Language
Portuguese
Primarily Uses
RMMV
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!
 

ShiningRomantica

Villager
Member
Joined
Mar 9, 2020
Messages
18
Reaction score
1
First Language
Portuguese
Primarily Uses
RMMV
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
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
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)
 

ShiningRomantica

Villager
Member
Joined
Mar 9, 2020
Messages
18
Reaction score
1
First Language
Portuguese
Primarily Uses
RMMV
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!
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
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.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
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?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
It's executed as part of execution of the skill; the common event happens after damage is applied.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
Ah okay, so it should work then.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
Funnily enough I'm currently writing the new Jump into Javascript and I'm on Game_Action, which will break down how this works.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
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?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
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?
 

ShiningRomantica

Villager
Member
Joined
Mar 9, 2020
Messages
18
Reaction score
1
First Language
Portuguese
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
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?
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
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.
 

ShiningRomantica

Villager
Member
Joined
Mar 9, 2020
Messages
18
Reaction score
1
First Language
Portuguese
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
Whereabouts do you have this line, exactly? Can you show screenshots?
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,574
Latest member
nikisknight
Top