Return player using x, y and direction

Setup:
An item takes the player from the map where they are standing to another one. I use 3 variables to get them back to the same spot, one for the x, one for y, and one for the map ID. These are set in the normal way on the transfer out and used in the transfer event which sends them back.

However, I also want the player to be facing the same direction as when they left the first map but cannot see a straightforward way of establishing it in the first place.
I have thought of using 4 temporary variables with 4 conditional branches before the first transfer, so if e.g. the player is facing right, then one would be added to temp variable 2.
Then have 4 conditionals on the transfer back which would pick up which of those variables was higher than zero and use that to, in this example, turn right.
However, that seems incredibly cumbersome, and I'm wondering if there is a script call or something which I could use?

Thanks.
You can use Control Variables to retrieve the player's facing direction, in the same way as you get the map id, x and y locations.

Then add a script call as follows:
Code:
@params = [1, a, b, c, d, 0]
command_201

replacing a, b, c and d with the variable ids that contain the map number, x, y and direction. The 1 indicates you're using variables, and the 0 indicates the normal fade.

Also works if you have followers turned on.
@Shaz Thank you, this works just as I want it to.
Your help is much appreciated.

EDIT
@Shaz I've run into a problem.

When I transfer back the sprite is invisible until I move, then it is clearly there. I didn't notice it when I tested before because, I think, I must have nudged the mouse or arrowkey so that the sprite was visible before I realized that it wasn't (if you see what I mean).

You won't be surprised to read that I haven't a clue what to do about this.
@Kes to me it looks like you are trying to display a non-existing sprite. That might explain why it is invisible until you move. If that is the case it might be caused by a wrong direction so when you move the engine automatically shows the sprite for the direction you are facing and everything is fixed.

How did you obtain player direction? Did you set player direction automatically ($game_player.direction)? Did you use conditional branches?

Of course this is the first thing that comes into my mind. The issue might lie somewhere else.
@Heirukichi I am using the script call given by Shaz 2 post up, having set the 4 variables (map id, player's x, player's y, player's direction) and using that script call instead of a normal transfer event. The player direction is taken from the ordinary Control Variable -> Game Data->Character->Player's Direction selections.
That sounds like an issue that people reported with my map edge transfer plugin. I'll go back to that and see what I had to do to solve the problem. However, we're packing/travelling today, so I'll either have to wait until we're all packed and I have some spare time, or until we arrive at the coast later today, to be able to look at it.

Hopefully you can put up with the issue for a little longer, until I have time to look at a fix 🙂
@Kes just in case you have something that modified how that method works (command_201) try to use this:
Code:
$game_player.reserve_transfer(map, x, y, direction)
Fiber.yield while $game_player.transfer?
map is the variable you used to store your map id, x and y and variables used to store player coordinates and direction is the variable you used to store player direction. You should use them in the form $game_variables[id]. If it does not fit in a single line you can change it like this:
Spoiler: this should not be necessary theoretically as long as you start a new line after a comma
Code:
m = $game_variables[the_one_used_for_map_id]
px = $game_variables[the_one_used_for_player_x]
py = $game_variables[the_one_used_for_player_y]
pd = $game_variables[the_one_used_for_player_direction]
$game_player.reserve_transfer(map, px, py, pd)
Fiber.yield while $game_player.transfer?
Does the issue persist even if you use this?
@Heirukichi Sorry about the delay in getting back to you - RL intervened and I had no time to test.

Your solution works, I transfer back and am immediately visible.
Thank you very much for your help.
I am glad that helped you. It seems the method you used previously (command_201) has been somehow modified by other scripts. By default it only contains those line I wrote and another line to check your fade type. Other lines are just checks to see if you are in battle, if there are messages etc.

Hopefully knowing the issue is related to that method can also help who wrote the script to fix that.

Original thread: https://forums.rpgmakerweb.com/threads/return-player-using-x-y-and-direction.95462/