Yanfly Event Spawner | Spawning Events in Front of Player

CosmicMagician

Villager
Member
Joined
Dec 6, 2019
Messages
9
Reaction score
4
First Language
English
Primarily Uses
RMMV
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!
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,710
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
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:

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.
 

ImaginaryVillain

One With The Particle
Veteran
Joined
Jun 22, 2019
Messages
791
Reaction score
4,494
First Language
Absurdism
Primarily Uses
RMMV
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.
 

CosmicMagician

Villager
Member
Joined
Dec 6, 2019
Messages
9
Reaction score
4
First Language
English
Primarily Uses
RMMV
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:

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?
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,710
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
Yes! Both plugins from triacontane :)
 

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

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top