MV Yanfly event spawner reset ID starting range?

So using Yanfly's event spawner I have a sequence set up in my game that spawns enemies in intervals and the enemies are partially commanded by being referred to by their ID number in various ways. This works fantastically until you die in which I have it scripted to kick you out of said map and reset everything before you can access it again. The problem is that the ID's of the spawned enemies after re-entering continue to climb and no longer align with their command references causing it to crash. So my question is does anyone know of some sort of script or something I can use to reset the starting Id's of spawned events back to the original starting ID, or of any way to add some sort of feature like this?
By looking at the code, it doesn't look like the IDs should climb up; it rather looks like your old events are still there. Maybe you need to clear all spawned events when dying.
By looking at the code, it doesn't look like the IDs should climb up; it rather looks like your old events are still there. Maybe you need to clear all spawned events when dying.
All events are set to be cleared upon dying, the image below shows the error I'm running into.
Screenshot 2025-08-19 042208.png


2 enemies are scripted to spawn in this instance which should be events 1001 and 1002, and using the "this._eventX = $gameMap.event(1001).x;" script call along with the "Y" variation and the same for event 1002 I track and manipulate the actions of these 2 events. So this is what I get when I die and reload into the map and try to respawn the events. Maybe I'm wrong it just seems to me it's not able to find the right ID # event now.
So using Yanfly's event spawner I have a sequence set up in my game that spawns enemies in intervals and the enemies are partially commanded by being referred to by their ID number in various ways. This works fantastically until you die in which I have it scripted to kick you out of said map and reset everything before you can access it again. The problem is that the ID's of the spawned enemies after re-entering continue to climb and no longer align with their command references causing it to crash. So my question is does anyone know of some sort of script or something I can use to reset the starting Id's of spawned events back to the original starting ID, or of any way to add some sort of feature like this?
Hi @Geeguz ,

If I understand the issue correctly:
- you generate events once, for example IDs from 1001 to 1010,
- after the map is reset following the player's death, the IDs increase, for example from 1011 to 1020, instead of resetting to 1001?

If you use one of the following commands when resetting the map, and it deletes the IDs, doesn't that reset the IDs of the events created to 1001?


excerpt from the plugin page:
Yanfly.ClearSpawnedEvents()
- Clears the current map of all spawned events.


Yanfly.ClearSpawnedEvents(mapId)
- Clears a specific map of all spawned events.
- Replace ‘mapId’ with the map you wish to clear of spawned events.

* Example: Yanfly.ClearSpawnedEvents(10)

- Clears all spawned events on map 10.

* Note: When a spawned event is despawned, any preserved data will also be
removed in addition to the removed spawned event.

Sorry, I'm not at home, so I can't test it myself, and it's been a long time since I've used it.
2 enemies are scripted to spawn in this instance which should be events 1001 and 1002, and using the "this._eventX = $gameMap.event(1001).x;" script call along with the "Y" variation and the same for event 1002 I track and manipulate the actions of these 2 events. So this is what I get when I die and reload into the map and try to respawn the events. Maybe I'm wrong it just seems to me it's not able to find the right ID # event now.
I would never-ever refer to spawned events by their blank IDs. Fortunately, there are workarounds.

What I usually do is to add a notetag into an event's box, let's say "Boss1". As always, you need to wrap it in <> symbols inside your note box:

Code:
<Boss1>

Example:
1755610192732.png

(whether it's <Boss1> or <Bank>, doesn't matter...)

Then, in your code, you can find it by using this call:

Code:
const event = $gameMap.events().find(event => event.event().meta.Boss1);
this._eventX = event ? event.x : 1; // in case this event is not found, use 1 as fallback
this._eventY = event ? event.y : 1;
I would never-ever refer to spawned events by their blank IDs. Fortunately, there are workarounds.

What I usually do is to add a notetag into an event's box, let's say "Boss1". As always, you need to wrap it in <> symbols inside your note box:

Code:
<Boss1>

Example:
View attachment 347795
(whether it's <Boss1> or <Bank>, doesn't matter...)

Then, in your code, you can find it by using this call:

Code:
const event = $gameMap.events().find(event => event.event().meta.Boss1);
this._eventX = event ? event.x : 1; // in case this event is not found, use 1 as fallback
this._eventY = event ? event.y : 1;
Aw man... this is going to take some time to rework... Well thank you very much for the helpful information, I will give that method a shot. So could you use the same method of reference for scripts like "$gameMap.event(1001).turnTowardPlayer();" or "$gameMap.event(1001).act(71)"?

Also quickly what does this "const event = $gameMap.events().find(event => event.event().meta.Boss1);" bit of code do?
Hi @Geeguz ,

If I understand the issue correctly:
- you generate events once, for example IDs from 1001 to 1010,
- after the map is reset following the player's death, the IDs increase, for example from 1011 to 1020, instead of resetting to 1001?

If you use one of the following commands when resetting the map, and it deletes the IDs, doesn't that reset the IDs of the events created to 1001?


excerpt from the plugin page:


Sorry, I'm not at home, so I can't test it myself, and it's been a long time since I've used it.
It doesn't seem like it from what I'm seeing now but it's possible it's running into another error I'm mistaking for that. I don't know of any other method to truly confirm if the newly spawned event is the same ID as the old ones or is continuing to climb.
Aw man... this is going to take some time to rework... Well thank you very much for the helpful information, I will give that method a shot. So could you use the same method of reference for scripts like "$gameMap.event(1001).turnTowardPlayer();" or "$gameMap.event(1001).act(71)"?

Also quickly what does this "const event = $gameMap.events().find(event => event.event().meta.Boss1);" bit of code do?

$gameMap.events().find(event => event.event().meta.Boss1) gives you the first event from the map that has <Boss1> in its notetag, so it's a simple substitution for $gameMap.event(X) when you are not sure about the number X.
$gameMap.events().find(event => event.event().meta.Boss1) gives you the first event from the map that has <Boss1> in its notetag, so it's a simple substitution for $gameMap.event(X) when you are not sure about the number X.
Ok so just to confirm I understand correctly, let's say I noted the event as <punk>. Then I would do "this._eventX = event punk event.x : 1;" and the same for Y?
A one-liner is possible when you absolutely know that this event exists; if your event is not there, your game will crash.

Code:
this._eventX = $gameMap.events().find(event => event.event().meta.punk).x
this._eventY = $gameMap.events().find(event => event.event().meta.punk).y

This more defensive approach continues your game and positions your event to position (1, 1) when your event does not exist:
Code:
const event = $gameMap.events().find(event => event.event().meta.punk);
this._eventX = event ? event.x : 1;
this._eventY = event ? event.y : 1;

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-event-spawner-reset-id-starting-range.179646/