How to teleport event in front of Player?

Basically I want an event to spawn/teleport in front of the player after their first random encounter. But since this is a random encounter they could be anywhere when this happens. I think I may have some idea on how to do this but don't know how to write it, I'd want to find the x and y of the player and then teleport the event to in front of that location.

I'm assuming I'll have to use the script button to do this, can anyone help?
no need for scripts, this can be done with eventing alone.

you'll need two variables for x and y. use control variable:game data to get the player coordinates into them (change map id to map x of player and map y of player).
then four conditional branches checking the facing of the player, adding or substracting one from the coordinates to get the coordinate the player looks at.
use those two modified variables for the change event location command.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-teleport-event-in-front-of-player.133866/