Use a spawned event to set Player Location (Yanfly Event Spawner) [RESOLVED]

Status
Not open for further replies.

marbeltoast

Your future fish emporer
Veteran
Joined
Nov 11, 2018
Messages
80
Reaction score
28
First Language
English
Primarily Uses
RMMV
Hey all!

So, I'm using Yanfly's Event Spawner plugin. Here's the situation: I'm spawning two events on a map, via a common event, and based on region 1 in said map. The first event, which I will call "X" does nothing on it's own. The second event is a hole, which when the player steps on it, will send them falling down to the next floor of the dungeon.

Obviously I want to prevent the player from spawning on top of the hole. They woud miss the entire floor of the dungeon. Fortunatly, the plugin being used means that the hole cannot spawn on top of another event, and must select another tile in the region to spawn on instead. The plan is, I spawn the X, then I spawn the hole somewhere else, I move the player on the X, then de-spawn the X, and then the level can begin.

Here's the tricky part: I do not know how to set player location based on a spawned event. I don't even know if one can do such a thing. If you fine folks can see a solution, be it via a plugin, or some clever coding, please do let me know. Thanks for reading; have a pleasant wednesday.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
You could have three variables (map ID, X, Y) to get/store the event location, then use these in a Transfer Player event command by selecting "Designation with variables" rather than "Direct designation". E.g.
Code:
◆Comment:Transfer to map 2, on top of event 1
◆Control Variables:#0002 Destination Map = 2
◆Control Variables:#0003 Destination X = Map X of EV001
◆Control Variables:#0004 Destination Y = Map Y of EV001
◆Transfer Player:{Destination Map} ({Destination X},{Destination Y})
 

marbeltoast

Your future fish emporer
Veteran
Joined
Nov 11, 2018
Messages
80
Reaction score
28
First Language
English
Primarily Uses
RMMV
◆Comment:Transfer to map 2, on top of event 1
Would this work if, say, there was a grand total of 120 different maps, any one of which could be the target location, and on top of this, another map acting as a storage templete which holds the original event? If so, then that would be brilliant!
 

SeaPhoenix

Veteran
Veteran
Joined
May 14, 2015
Messages
251
Reaction score
232
First Language
English
Primarily Uses
RMMV
You can get a spawned event's location immediately after spawning it. Write the following code in one script call (// means it's a comment, so just replace the lines preceded by // with your own code):
Code:
// Write your code to spawn the event you call X
var spawn = $gameMap.LastSpawnedEvent();
var spawnX = spawn.x;
var spawnY = spawn.y;
// Write your code to spawn the hole, then despawn X
$gamePlayer.locate(spawnX, spawnY);
The last line (the locate code) assumes you are on the same map where you've spawned the event (since IIRC your player currently has to be on the map where events are spawned). But if you're not, use transfer player instead. If you're unfamiliar with coding and need more help, let me know.

EDIT: I just saw that the OP posted a new message; this is in response to your first post.
 

marbeltoast

Your future fish emporer
Veteran
Joined
Nov 11, 2018
Messages
80
Reaction score
28
First Language
English
Primarily Uses
RMMV
The last line (the locate code) assumes you are on the same map where you've spawned the event
Hhm... I suppose I could move the player to 0,0 on the map temporarily, just so they're on the same map. It would require some hard coding, given the sheer number of maps at play, but it's nothing too time consuming. I will confess my knowledge of code is severely limited, so odds are good I'll run into a few problems here and there, but we can discuss those as and when they arise. Expect an edit before too long.

EDIT: Okay, here's the code I ran and what happened afterwards:
Code:
// Spawn "X"
Yanfly.SpawnEventInRegion(10, 9, 1, false)
// Get "X"'s location
var RAM Memory 1 = $gameMap.LastSpawnedEvent();
var RAM Memory 2 = spawn.x;
var RAM Memory 3 = spawn.y;
var RAM Memory 4 = $gameMap.LastSpawnedEventID()
// Spawn Hole, despawn "X"
Yanfly.SpawnEventInRegion(10, 12, 1, false)
Yanfly.DespawnEventID(var RAM Memory 4)
// Move player
$gamePlayer.locate(RAM Memory 2, RAM Memory 3);
After running this code, my player was at 0,0, and an error message on screen told me that there was an "Unexpected identifier", whatever the hell that means.
 
Last edited:

SeaPhoenix

Veteran
Veteran
Joined
May 14, 2015
Messages
251
Reaction score
232
First Language
English
Primarily Uses
RMMV
Did you try variable names that are just single words? E.g., var spawnX, not var RAM Memory 2 because the spaces won't work in variable names; you can use underscore or just capitalization if you need to make the code more readable to yourself. e.g., var spawnedEventX.

EDIT: Oh and you need to change this line too:
Yanfly.DespawnEventID(var RAM Memory 4)
Aside from the variable name being ineligible, you don't want var in front of it either since that's used only when you initially declare the variable.
 

marbeltoast

Your future fish emporer
Veteran
Joined
Nov 11, 2018
Messages
80
Reaction score
28
First Language
English
Primarily Uses
RMMV
Victory! It works! Thank you, o Phoenix of the sea!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,225
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,050
Members
137,571
Latest member
grr
Top