MV [SOLVED] (Script) Find Event ID by Event Name

Hello guys.

I am using the plugin Aramis Sprite Zoom in my project and it works fine. But it is a bit tedious to put the event ID when I use the command SpriteZoom.zoom(X, Y);

So it occurred to me "automate" that it find the "X" ID of the events after finding all events with the "Z" name, so "X" will be the ID of the event with "Z" name of the event.

I tried to do it but I can't find how and I already know that the code is wrong:

Code:
Game_Map.prototype.findEventsByName = function (event_name) {
     return this._events.filter(ev => {
         return (ev) ? ev.event().name == event_name: false;
     });
};
Game_Map.prototype.findEventByName = function (event_name) {
     return this._events.find(ev => {
         return ev.event().name == event_name;
     });
};

Code:
SpriteZoom.zoom($gameMap.findEventByName('_char'), 0.2);

Thanks.

Edit: This code is from this thread.
It looks like you got that code from this thread - which would be good to include a link to, for everyone's reference. And the code is correct, depending on how you're trying to use it.

But all of those are returning actual events, whereas the script call you're referencing doesn't take that:
1715017130182.png


The first argument is supposed to be the ID of the event, not the event itself.

So you would do SpriteZoom.zoom($gameMap.findEventByName("_char").eventId(), 0.2);
It looks like you got that code from this thread - which would be good to include a link to, for everyone's reference. And the code is correct, depending on how you're trying to use it.

But all of those are returning actual events, whereas the script call you're referencing doesn't take that:
View attachment 304219

The first argument is supposed to be the ID of the event, not the event itself.

So you would do SpriteZoom.zoom($gameMap.findEventByName("_char").eventId(), 0.2);
Thanks for the answer, I'm checking
It looks like you got that code from this thread - which would be good to include a link to, for everyone's reference. And the code is correct, depending on how you're trying to use it.

But all of those are returning actual events, whereas the script call you're referencing doesn't take that:
View attachment 304219

The first argument is supposed to be the ID of the event, not the event itself.

So you would do SpriteZoom.zoom($gameMap.findEventByName("_char").eventId(), 0.2);
For some reason no works... I has a parallel event that calls the scripts and it works fine, I did something wrong?

Spoiler
1.PNG

2.PNG

3.PNG

Edit: I found this pressing F12:

Spoiler
4.PNG
A few tips.

1 - Please post your events in English so we can understand the event commands. You can right-click MV in your Steam library, go to Properties, and temporarily change the language.

2 - You appear to have a number of errors with your event.
  • Parallel and Autorun events automatically loop. They try to execute themselves once every frame (60 times a second). What you have in there shouldn't be done more than once, you tell it to zoom these specific sprites and then you should turn the event off.
  • Instead, you're using a label and going continuously back to it. That's trying to loop inside of the loop.
Get rid of the label. Have the script commands and at the bottom Erase Event. That will make it run only one time every time you enter the map.

If that still doesn't work, post another screenshot of your fixed event as well as the event named "_char" that it isn't working on.
A few tips.

1 - Please post your events in English so we can understand the event commands. You can right-click MV in your Steam library, go to Properties, and temporarily change the language.

2 - You appear to have a number of errors with your event.
  • Parallel and Autorun events automatically loop. They try to execute themselves once every frame (60 times a second). What you have in there shouldn't be done more than once, you tell it to zoom these specific sprites and then you should turn the event off.
  • Instead, you're using a label and going continuously back to it. That's trying to loop inside of the loop.
Get rid of the label. Have the script commands and at the bottom Erase Event. That will make it run only one time every time you enter the map.

If that still doesn't work, post another screenshot of your fixed event as well as the event named "_char" that it isn't working on.
Sorry for the wait, I tried something but it didn't work.
It still doesn't work...

Spoiler
1.PNG

2.PNG
During the game, press F8, go to the Console tab, and paste the script call in:
Code:
SpriteZoom.zoom($gameMap.findEventByName("_char")

Show a screenshot of what it says.
Spoiler
3.PNG
ATT_Turan forgot a ")" on the end.
Code:
SpriteZoom.zoom($gameMap.findEventByName("_char"))
Spoiler
4.PNG
Sorry. I was leaving to get the kid from the schoolbus and I typed the wrong thing.

The zoom has nothing to do with it - we're testing whether your findEvent works at all.

What you should be pasting in to test is just
Code:
$gameMap.findEventByName("_char")

That's why I didn't have the parentheses in there, I didn't mean it to be inside another function 😛
Spoiler
5.PNG

I just realized that the first findEventsByName function in the first code is the one I need and not findEventByName. But it doesn't work either.
Sorry. I was leaving to get the kid from the schoolbus and I typed the wrong thing.

The zoom has nothing to do with it - we're testing whether your findEvent works at all.

What you should be pasting in to test is just
Code:
$gameMap.findEventByName("_char")

That's why I didn't have the parentheses in there, I didn't mean it to be inside another function 😛
In case you are wondering, yes, I have the plugin enabled :eswt2:
so "X" will be the ID of the event with "Z" name of the event.
Finding the id of an event with a given name is rather simple and can be done like so (using you "_char" as an example):
$dataMap.events.find(e => e && e.name == "_char").id
So for the complete script call:
SpriteZoom.zoom($dataMap.events.find(e => e && e.name == "_char").id, 0.2);
No plugins needed.

The problem with the snippet you shared is that it doesn't account for undefined events, and crashes when it encounters one.

EDIT: Initially the post included .eventId() instead of the correct .id.
I just realized that the first findEventsByName function in the first code is the one I need and not findEventByName.
No, it's not. That's returning an array (a list) of events and that won't work at all with the rest of your code.

Use the code that @Mac15001900 provided.
Finding the id of an event with a given name is rather simple and can be done like so (using you "_char" as an example):
$dataMap.events.find(e => e && e.name == "_char").id
So for the complete script call:
SpriteZoom.zoom($dataMap.events.find(e => e && e.name == "_char").id, 0.2);
No plugins needed.

The problem with the snippet you shared is that it doesn't account for undefined events, and crashes when it encounters one.

EDIT: Initially the post included .eventId() instead of the correct .id.
Spoiler
6.PNG


F8:

7.PNG

It doesn't seem to work... :eswt2: Sorry for the inconvenience
Okay. You appear to be using an obsolete version of RPG Maker MV.

If you go to your js directory and open rpg_core.js in a text editor, what version does it say at the top?

If it's not at least 1.6, you should update your core scripts per these instructions:
Okay. You appear to be using an obsolete version of RPG Maker MV.

If you go to your js directory and open rpg_core.js in a text editor, what version does it say at the top?

If it's not at least 1.6, you should update your core scripts per these instructions:
Says rpg_core.js v1.6.1
Okay. You appear to be using an obsolete version of RPG Maker MV.

If you go to your js directory and open rpg_core.js in a text editor, what version does it say at the top?

If it's not at least 1.6, you should update your core scripts per these instructions:
I think that maybe the Aramis´s plugin is not compatible with some commands
I think that maybe the Aramis´s plugin is not compatible with some commands
That can't have anything to do with it.

What @Mac15001900 gave you is correct JavaScript syntax - a plugin can't be "not compatible" with it.

I've seen the error you posted from other people using older versions of MV that didn't support the syntax for arrow functions. If you're using 1.6.1, I have no idea why it's saying that.

Original thread: https://forums.rpgmakerweb.com/threads/solved-script-find-event-id-by-event-name.168413/