Yanfly Event Spawner | Spawning Events in Front of Player

This is my first post on this forum, so my apologies in advance if I've placed this question in the wrong spot, I'm asking a newbie question or anything like that.

I wanted to see if it was possible to decorate a map with objects, similar to placing furniture in Animal Crossing, via Yanfly's Event Spawner plugin.

To spawn events via Yanfly's Event Spawner plugin, the following script call is used:
Yanfly.SpawnEventAt(mapId, eventId, x, y, preserved)

I've seen someone else say you can replace x and y with variables. If that's true, then the variables used could be equal to the player's x and y coordinates on the map.
The only problem with doing that is the event then spawns on top of the player. The player can walk away from the event and then the event will behave like normal but it's jarring to have the event on top of the player in the first place.

I'm very new to Javascript but I wrote what I believe to be the correct way to spawn events in front of the player:
if ($gamePlayer.direction(2)) {
Yanfly.SpawnEventAt(1, 5, $gameVariables.value(1), $gameVariables.setValue(2, $gameVariables.value(2)+1), true)
} else if ($gamePlayer.direction(4)) {
Yanfly.SpawnEventAt(1, 5, $gameVariables.setValue(1, $gameVariables.value(1)-1), $gameVariables.value(2), true)
}

( I only checked if the player is looking down or left at the moment )

I'm posting this here before purchasing the plugin to confirm if this is the code needed to spawn events in front of player. Please let me know if there's a mistake or if it's even possible to do this with Yanfly's Event Spawner plugin.

Thanks a bunch!
Hi!
I think you can do this:
JavaScript:
let playerX = $gamePlayer._x;
let playerY = $gamePlayer._y;
let playerDir = $gamePlayer._direction;
let objectX = 0;
let objectY = 0;
if(playerDir === 2) {
    objectX = playerX;
    objectY = playerY + 1;
}
if(playerDir === 8) {
    objectX = playerX;
    objectY = playerY - 1;
}
if(playerDir === 6) {
    objectX = playerX + 1;
    objectY = playerY;
}
if(playerDir === 8) {
    objectX = playerX - 1;
    objectY = playerY;
}
Yanfly.SpawnEventAt(mapId, eventId, objectX, objectY, preserved)

It's a little big, maybe you can leave it smaller removing the variables.
But the idea is to put the object always in front of the player, right?

Particularly, I used the template event and event spawner from triacontane, and I was able to do this in this:
Spoiler: Video


But here, I was making the event above the player(but invisible), when the player press the Z button, he change graphics and place the event in front of him.

But in your case, you can put an autonomous movement route in the event, for it is always in front of the player. You can calculate the coordinates x and y that is front of the player based on my code above.
You can actually simplify this if all you want to do is spawn stuff directly in front of the player.

JavaScript:
var direction = $gamePlayer.direction();
var x = $gameMap.roundXWithDirection($gamePlayer.x, direction);
var y = $gameMap.roundYWithDirection($gamePlayer.y, direction);
Yanfly.SpawnEventAt(mapId, eventId, x, y, true);

Just change the mapId to whatever your event map is, and the eventId to whatever you want to spawn.
You can actually simplify this if all you want to do is spawn stuff directly in front of the player.

JavaScript:
var direction = $gamePlayer.direction();
var x = $gameMap.roundXWithDirection($gamePlayer.x, direction);
var y = $gameMap.roundYWithDirection($gamePlayer.y, direction);
Yanfly.SpawnEventAt(mapId, eventId, x, y, true);

Just change the mapId to whatever your event map is, and the eventId to whatever you want to spawn.
Hi!
I think you can do this:
JavaScript:
let playerX = $gamePlayer._x;
let playerY = $gamePlayer._y;
let playerDir = $gamePlayer._direction;
let objectX = 0;
let objectY = 0;
if(playerDir === 2) {
    objectX = playerX;
    objectY = playerY + 1;
}
if(playerDir === 8) {
    objectX = playerX;
    objectY = playerY - 1;
}
if(playerDir === 6) {
    objectX = playerX + 1;
    objectY = playerY;
}
if(playerDir === 8) {
    objectX = playerX - 1;
    objectY = playerY;
}
Yanfly.SpawnEventAt(mapId, eventId, objectX, objectY, preserved)

It's a little big, maybe you can leave it smaller removing the variables.
But the idea is to put the object always in front of the player, right?

Particularly, I used the template event and event spawner from triacontane, and I was able to do this in this:
Spoiler: Video


But here, I was making the event above the player(but invisible), when the player press the Z button, he change graphics and place the event in front of him.

But in your case, you can put an autonomous movement route in the event, for it is always in front of the player. You can calculate the coordinates x and y that is front of the player based on my code above.

Sorry for the late reply! I wasn't expecting a response so fast, thanks a lot to both you though! I'll experiment with both of your solutions to see which fits what I'm trying to do the best.
Just to clarify, Eliaquim, you used triacontane's TemplateEvent and EventReSpawn plugins for that video, right?
Yes! Both plugins from triacontane 🙂

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-event-spawner-spawning-events-in-front-of-player.118844/