Way of retrieving a unique event ID?

Kronicide

Veteran
Veteran
Joined
Jul 7, 2020
Messages
39
Reaction score
18
First Language
Swedish
Primarily Uses
RMMV
I think this.eventId() returns a number which can refer to different events on different maps. Are there event IDs somewhere that uniquely identify events across all maps in the game? I guess map ID + event ID constitutes a unique event ID, but are there any standard methods or tricks for working with such a construct?

Thanks!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,949
Reaction score
13,585
First Language
English
Primarily Uses
RMMV
Events only exist when a map is loaded into memory, and only one map can be loaded at a time, under normal circumstances.

If you want to refer to a specific event on a specific map, without getting it confused with an event on a different map with the same id, then you have to combine map id and event id.

Self switches, for example, exist in a single array in Game_System. It is a list of all self switches (there are 4) for every event, for every map. It uses [mapId, eventId, selfSwitchId] as the key.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
I suppose the more useful question would be "Why do you need this?"
 

Kronicide

Veteran
Veteran
Joined
Jul 7, 2020
Messages
39
Reaction score
18
First Language
Swedish
Primarily Uses
RMMV
If you want to refer to a specific event on a specific map, without getting it confused with an event on a different map with the same id, then you have to combine map id and event id.
Ok, thanks! I'm vaguely thinking of adding new state information to events, I think preferably in my own namespace. Say for example that turning some event into an NPC by way of a note tag associates a bunch of new persistent properties and methods to that event. I guess it would be best to model that on how switches are handled then, and use map ID + event ID as the key.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
Alternatively, you could create a new class called Game_NPC or something and then overwrite the event creation code to create one of those instead of Game_Event if the notetag is present.
 

Kronicide

Veteran
Veteran
Joined
Jul 7, 2020
Messages
39
Reaction score
18
First Language
Swedish
Primarily Uses
RMMV
Alternatively, you could create a new class called Game_NPC or something and then overwrite the event creation code to create one of those instead of Game_Event if the notetag is present.
Right, that sounds like the way to do it, from one point of view. I'm handicapped by having a brain tuned to relational databases and functions, not object oriented code. Still, I'm wondering if it's not a good idea if, as far as RMMV knows, these are just regular events that don't misbehave in any way. That is, I would manipulate them using the standard RMMV methods, but based on states and methods kept elsewhere. (This is what I meant by "vaguely thinking.")
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
Right, that sounds like the way to do it, from one point of view. I'm handicapped by having a brain tuned to relational databases and functions, not object oriented code. Still, I'm wondering if it's not a good idea if, as far as RMMV knows, these are just regular events that don't misbehave in any way. That is, I would manipulate them using the standard RMMV methods, but based on states and methods kept elsewhere. (This is what I meant by "vaguely thinking.")
You could get around that by having Game_NPC inherit from Game_Event (which will cause the engine to treat it like a regular event in every way that matters) but then add your properties/methods to that class. That would actually accomplish your goal better than tacking properties onto a Game_Event only if it has the notetag.
 

Kronicide

Veteran
Veteran
Joined
Jul 7, 2020
Messages
39
Reaction score
18
First Language
Swedish
Primarily Uses
RMMV
You could get around that by having Game_NPC inherit from Game_Event (which will cause the engine to treat it like a regular event in every way that matters) but then add your properties/methods to that class. That would actually accomplish your goal better than tacking properties onto a Game_Event only if it has the notetag.
Yeah, that sounds like the way to go, having NPCs be a type of event, and the game engine doesn't need to know that it's a special type. I just need to learn how to do this. :^D
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
460
Reaction score
1,435
First Language
Indonesia
Primarily Uses
RMMV
this if it's called inside an event will be referred to Game_Event, which is the current event.
this._eventId is referring to the ID of that current event.

To refer any event on the currently loaded map, it's $gameMap.event(ID)

If you're trying to refer a specific event in a specific map, it's something along $datamap... not sure... I don't quite remember as well. Maybe $datamap[map_id].events[event_id].

There's the same question with the same purpose asked in discord. IDK if it could help. But he planned to store the data and parameter inside the game variable which I think is more direct and flexible.
1594805761536.png
1594805854284.png
1594805898237.png

One thing I don't understand is, why are you trying to bind your event? If you specify a unique event by his map and event ID, then it will be bound forever to that specific map and event ID. You will lose flexibility in this aspect.

Here's the problem: What if you are trying to make that "Old Man A" from map X appear in map Y while carrying his unique parameter? You no longer can. They are bound to their location forever.

Just create a new accessible data and have your event access it anytime, anywhere.
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
Yeah, that sounds like the way to go, having NPCs be a type of event, and the game engine doesn't need to know that it's a special type. I just need to learn how to do this. :^D
If you look at rpg_objects.js, Game_Event is actually a child class of Game_Character. If you look at how Game_Character and Game_CharacterBase are coded, it should give you a fair idea of how to incorporate a new subclass for NPCs specifically.

Kuro, what you're suggesting won't work. $dataMap only contains the data for the currently-loaded map, and $dataMapInfos, although it has an element for every map in the game, only holds information about the map itself and has no concept of the events on it.
 
Last edited:

Kronicide

Veteran
Veteran
Joined
Jul 7, 2020
Messages
39
Reaction score
18
First Language
Swedish
Primarily Uses
RMMV
If you look at rpg_objects.js, Game_Event is actually a child class of Game_Character. If you look at how Game_Character and Game_CharacterBase are coded, it should give you a fair idea of how to incorporate a new subclass for NPCs specifically.
Cool, thanks!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,949
Reaction score
13,585
First Language
English
Primarily Uses
RMMV
Check out Yanfly's Self Variables plugin
 

Kronicide

Veteran
Veteran
Joined
Jul 7, 2020
Messages
39
Reaction score
18
First Language
Swedish
Primarily Uses
RMMV
If you're trying to refer a specific event in a specific map, it's something along $datamap... not sure... I don't quite remember as well. Maybe $datamap[map_id].events[event_id].

There's the same question with the same purpose asked in discord.
Thanks, that's useful!

One thing I don't understand is, why are you trying to bind your event? If you specify a unique event by his map and event ID, then it will be bound forever to that specific map and event ID. You will lose flexibility in this aspect.

Here's the problem: What if you are trying to make that "Old Man A" from map X appear in map Y while carrying his unique parameter? You no longer can. They are bound to their location forever.
That's a good point, and my original idea was actually to not bind the NPC data permanently to an event, but to create a new NPC object that is associated with an event (by a unique identifier), as one of its properties. That was more due to my relational-databases way of thinking than because of this issue, though.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

NeoPGX wrote on Kes's profile.
Oh hey I just saw your comment on my profile status update.

The thing is I have twitter set up mark all my content as being potentially sensitive by default. I do it as a precaution even though I very rarely upload any such content.
I'm the fly in your soup
I'm the pebble in your shoe
I'm the pea beneath your bed
I'm the bump on every head
I'm the peel on which you slip
I'm the pin in every hip
I'm the thorn in your side
Makes you wriggle and writhe
And it's so easy when you're evil
bro how do I have over 30 OCs
A good way to mix your own music? What's the learning curve on that?
Would it be better to pay a composer?
What theme for the next windowskin? You'll decide. Tell what you wanna see and I'll try for.

Forum statistics

Threads
103,263
Messages
998,441
Members
134,767
Latest member
Jealousguy
Top