MZ How to requestAnimation for this.event from plugin rather than event script call

Hello everyone,
I'm trying to call an animation from a plugin and it's working when I choose a specific event

Rich (BB code):
var character = $gameMap.event(34);
                var id = 370;
                character.requestAnimation(id);

but not when I put this._eventId (it works on map but not on script and common event)

Rich (BB code):
var character = $gameMap.event(this._eventId);
                var id = 370;
                character.requestAnimation(id);

Also tried with

Rich (BB code):
$gameMap.event(this._eventId).requestAnimation(370);

or

Rich (BB code):
$gameTemp.requestAnimation([$gameMap.event(this._eventId)], 370);

but same issue.


Seems like it doesn't find this.event via script, any idea how to do that ?
Thanks again
As a side note, it's more correct to use getter functions when they're provided - that is, this.eventId() rather than this._eventId

but not when I put this._eventId (it works on map but not on script and common event)
Rich (BB code):
var character = $gameMap.event(this._eventId);
                var id = 370;
                character.requestAnimation(id);

Also tried with
Rich (BB code):
$gameMap.event(this._eventId).requestAnimation(370);
These two are the same thing, except the second one doesn't have two unnecessary variables.

I don't know where you got this code from, but it's for MV - this isn't valid syntax for MZ. I don't see how your original code that you said works could work, either.

or
Rich (BB code):
$gameTemp.requestAnimation([$gameMap.event(this._eventId)], 370);
but same issue.
What issue? That script call works perfectly in my MZ test project.
These two are the same thing, except the second one doesn't have two unnecessary variables.

I don't know where you got this code from, but it's for MV - this isn't valid syntax for MZ. I don't see how your original code that you said works could work, either.
Oh I'm using FOSSIL so maybe that's why MV syntax worked, and found it here
Scripts

What issue? That script call works perfectly in my MZ test project.
Just tried that $gameMap.event(this.eventId()).requestAnimation(370);
in a .js script (not in an event script) and it crash "this.eventId is not a function"

This work but only for one event (the 34) : line 445
Spoiler: screenshot
1724685393053.png

This doesn't (and I need to be able to use it for any event)
Spoiler: screenshot
1724685431677.png
I think you are using the wrong words. Also, your screenshots don't work.

Script means something you're entering into the Script event command, or the script field within an event command.

If you're talking about a plugin, that is not "a script" and it would not be using this to refer to an interpreter object unless you're making your function be a method of Game_Interpreter.

If that's what you're talking about, you need to actually show the code you're writing for your plugin.
I think you are using the wrong words. Also, your screenshots don't work.

Script means something you're entering into the Script event command, or the script field within an event command.

If you're talking about a plugin, that is not "a script" and it would not be using this to refer to an interpreter object unless you're making your function be a method of Game_Interpreter.

If that's what you're talking about, you need to actually show the code you're writing for your plugin.
Sorry I meant plugin indeed, and I updated the screens they should work now
Are you writing this code yourself? Because that's simply not how this works, which is a pretty fundamental JavaScript concept.


You even use this correctly on other lines in the same function, which makes it doubly odd.

As far as basic stuff goes, if you need to be able to use any event, then you need a point of reference for that event. If you're not writing this code to be methods of Game_Interpreter, then you need to have the event be an argument you pass into the functions.
Are you writing this code yourself? Because that's simply not how this works, which is a pretty fundamental JavaScript concept.


You even use this correctly on other lines in the same function, which makes it doubly odd.

As far as basic stuff goes, if you need to be able to use any event, then you need a point of reference for that event. If you're not writing this code to be methods of Game_Interpreter, then you need to have the event be an argument you pass into the functions.
No I'm not it's a plugin called "SoR_MapActionIndicator_MZ_Alpha" that I use cause it use directional detection of the player to the event to display a window (like "talk") and I want to add an highlight animation on the event when you are in front of it.

Before that I used a range of event sensor to launch the animation and window text but it didn't detect player direction, so with the abs system if I was near an npc in fight It would launch dialogue even when not facing the npc event.

Is it maybe possible to launch a common event via the plugin and put the script to launch the animation inside the common event ?

Or is there a way to check if the player is facing the even ? so I can bypass the plugin and do it inside the event itself
To answer the initial question I just tried to put this into a random event :

Code:
$gameTemp.requestAnimation([$gameMap.event(this.eventId())], 2);

When interacting with it the animation with id=2 started playing.

(nevermind I'm too late)
To answer the initial question I just tried to put this into a random event :

Code:
$gameTemp.requestAnimation([$gameMap.event(this.eventId())], 2);

When interacting with it the animation with id=2 started playing.

(nevermind I'm too late)
yes me too the problem is it does work in an event but not in a plugin and I'm trying to call the animation from the plugin rather than the event


So I tried this direction detection method from @Aerosys and It works great
Rich (BB code):
Game_Event.prototype.isFacedByPlayer = function() {
    return ($gamePlayer.direction() == 2 && $gamePlayer.y < this.y)
        || ($gamePlayer.direction() == 4 && $gamePlayer.x > this.x)
        || ($gamePlayer.direction() == 6 && $gamePlayer.x < this.x)
        || ($gamePlayer.direction() == 8 && $gamePlayer.y > this.y);
}
Then in your IF Condition, you can shortcut to
Rich (BB code):
$gameMap.event(this.eventId()).isFacedByPlayer()
and using this eventing I made something similar but kinda complicated and it require a lot of parallel events (for each npc)

Spoiler: screenshot
1.png

2.png
Does anyone knows how to call an animation on "this.event()" from a blank plugin ?
I guess "this.event()" has to be defined but not sure how to do that.
"this" has a different meaning depending on its context.
If you use "this" in an actor class method, this will be a reference to an actor. But in another context it can be a game window, a skill, a sprite...

We cannot know what is the "this" you are talking about without context.

But to locate an event on the current map, use something like $gameMap.event(X) where X is the id of the event.

This "X" can be a fixed value, an argument of the calling method, the content of a plugin parameter or of a notetag, the result of some processing.
You need to insert a logic to determine which is the event you want and how to tell it to your plugin.
At least for me, the confusing part is why you're trying to write plugins if you don't know what you're doing.

It would seem to make more sense to do some JavaScript tutorials, because - as I said before - this is a pretty basic part of the language.

If you don't understand how this works, it's very unlikely that the rest of the code in there would have the correct syntax and work at all.

You can make a post in Plugin Support where you actually describe what you're trying to achieve in your game, and other people can suggest which plugins you can use or possibly write a bit of code for you. But asking people for isolated pieces of syntax doesn't seem like it would achieve anything.

@TG22 is absolutely correct - but it's the same information I gave you back on Monday.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-requestanimation-for-this-event-from-plugin-rather-than-event-script-call.171425/