Creating Move Routes via Script

Hello!

I am attempting to create move routes for events via scripts. I know how to use scripts to tell an event "go here", but telling it "go here, and then once you get there, go to this other place and then do something" is much harder. Obviously you can do this through event commands, but those require you to know exactly which event you're commanding beforehand (and that it exist at the time you create the map). I do not. For those wondering about my use case, I'm using Yanfly's spawned events plugin to create events, and then I want the spawned events to take a sequence of actions.

I noticed Shaz had made a thread which described the process for VX Ace, but I'm not sure how to translate that into MV.

For background, I have a basic familiarity with javascript and the engine, and have made a few plugins for my own game (mostly helper functions and such). I get that I'll need to construct an array of some sort that contains all the stuff I want my event to do, but I'm not sure what I should put in it.

I'm sure I'll figure it out eventually, but I'd be quite thankful if someone could point me in the right direction. I also suspect this is a question of general interest. Thank you!
I'm dead tired and off to bed soon, so I can't go into the detail.

I will say that MV has a similar structure to Ace - a move route consists of a list of move commands and some other parameters. So the process of setting it up will be similar. But obviously the syntax will be a bit different because you're building it in js and not ruby.

Your big advantage with MV is that everything you create in a map is saved in a readable json format. So you can see exactly what the properties are of a move route, and how the sub-commands are formatted.

If you want all your events to do a similar thing, I suggest you make a brand new map and add just one event and give it that move route. Save it, then go check out the json file and see what it's put there.

Once you can build that through script, the only other issue is figuring out how to call/activate it on each event.
You must create a move route object by referring from the data/Mapxxx.json file, for example :

PHP:
var _moveRoute = {"list":[],"repeat":false,"skippable":false,"wait":true};

_moveRoute.list.push({"code":Game_Character.ROUTE_MOVE_DOWN});
_moveRoute.list.push({"code":Game_Character.ROUTE_MOVE_UP});
_moveRoute.list.push({"code":Game_Character.ROUTE_MOVE_RIGHT});
_moveRoute.list.push({"code":Game_Character.ROUTE_SCRIPT, "parameters": ["console.log(\'wow\')"]});
_moveRoute.list.push({"code":Game_Character.ROUTE_PLAY_SE, "parameters": [{"name":"Attack3","volume":90,"pitch":100,"pan":0}]});
_moveRoute.list.push({"code":Game_Character.ROUTE_END});

var ev = $gameMap.event(1);

if(ev) {
 ev.forceMoveRoute(_moveRoute);
}
Thanks to both of you! I followed biud436's template and it worked perfectly the first time.

For those trying to figure this out, you can get the codes through Kino's excellent resource, or enter them as numbers by looking them up in rpg_objects.js (starts around line 6841 as of right now). You'd still do well to follow Shaz's advice and create a move route similar to what you want and look at the map's json file to understand how to populate the parameters property (if needed).

Original thread: https://forums.rpgmakerweb.com/threads/creating-move-routes-via-script.102508/