These are the commands you need to use if you want to create a move route and apply it to one or move events, by using a Script call in an event list. You might want to do it this way, rather than using the Set Move Route event command, for a number of reasons:
- the move route is quite long and movement commands are repeated (you can use a loop to repeat one or more commands rather than writing them all out individually)
- you don't know which event you want to apply the move route to (you can use a variable to hold the event id, or even decide in the script if the move route should be applied to an event, a player, a follower or a vehicle)
- you want to apply the same move route to several events, but don't want to copy/paste the entire thing for each event
Here's how to do it ...
A move route is an object of type RPG::MoveRoute - you can find this in the help file under RGSS Reference Manual > Game Library > RPGVXAce Data Structures > RPG::MoveRoute. It contains values for repeat, skippable, and wait (the checkboxes you see on the Set Move Route command), as well as an array of RPG::MoveCommand objects (also defined in the help file, just below RPG::MoveRoute). So to create a move route via script, you're going to need to create a new RPG::MoveRoute object plus one or more RPG::MoveCommand objects. This is how each one is defined in the help file:
Spoiler Code:
- class RPG::MoveRoute
- def initialize
- @repeat = true
- @skippable = false
- @wait = false
- @list = [RPG::MoveCommand.new]
- end
- attr_accessor :repeat
- attr_accessor :skippable
- attr_accessor :wait
- attr_accessor :list
- end
- class RPG::MoveCommand
- def initialize(code = 0, parameters = [])
- @code = code
- @parameters = parameters
- end
- attr_accessor :code
- attr_accessor :parameters
- end
复制代码
As an example, I'll show you how to create a move route with a script call, that does what the Quick Event for a chest does. A chest quick event has Wait for Completion turned on, Repeat Action and Skip turned off, and the following commands:
Code:
- > Direction Fix OFF
- > Turn Left
- > Wait: 3 frame(s)
- > Turn Right
- > Wait: 3 frame(s)
- >
复制代码
notice there's a blank movement at the end of the move route.
So we'll create the move route itself first, and change the values for @repeat and @wait from the defaults (we don't want to skip, and to not skip is the default, so we can omit that one), and clear out the one blank movement command (we'll add it back later, after the real movements have been added):
Code:
- mr = RPG::MoveRoute.new
- mr.repeat = false
- mr.wait = true
- mr.list = []
复制代码
Now we have to add in all the correct movement commands, followed by the empty one. To do this, we need to know the code for the move action, and what parameters it expects, if any, and create a new RPG::MoveCommand for each one. The Game_Character script lists all of these - just find the text in the constants section that describes the movement command, and use the code that follows. Then look in the process_move_command method to see if any parameters are required.
Here are the codes and parameters for each of the commands above:
Code:
- > Direction Fix OFF ... code 36, no parameters
- > Turn Left ... code 17, no parameters
- > Wait: 3 frame(s) ... code 15, parameter is the number of frames (see line 150 in default script)
- > Turn Right ... code 18, no parameters
- > Wait: 3 frame(s) ... code 15, parameter is the number of frames
- > ... no code or parameters needed - this is just a fresh RPG::MoveCommand
复制代码
Okay, so now that we know the codes and parameters, we just need to add them to mr.list:
Code:
- mr.list.push( RPG::MoveCommand.new(36, []) )
- mr.list.push( RPG::MoveCommand.new(17, []) )
- mr.list.push( RPG::MoveCommand.new(15, [3]) )
- mr.list.push( RPG::MoveCommand.new(18, []) )
- mr.list.push( RPG::MoveCommand.new(15, [3]) )
- mr.list.push( RPG::MoveCommand.new )
复制代码
That finishes up your move route. The last thing you need to do is apply it to your event (@event_id is the 'current' event, if you are putting this as a Script command on an event page - if you're actually writing a script and not attaching it to an event, you need to use an actual number for the event id):
Code:
- $game_map.events[@event_id].force_move_route(mr)
复制代码
So your full script is going to look something like this:
Spoiler Code:
- mr = RPG::MoveRoute.new
- mr.repeat = false
- mr.wait = true
- mr.list = []
- mr.list.push( RPG::MoveCommand.new(36, []) )
- mr.list.push( RPG::MoveCommand.new(17, []) )
- mr.list.push( RPG::MoveCommand.new(15, [3]) )
- mr.list.push( RPG::MoveCommand.new(18, []) )
- mr.list.push( RPG::MoveCommand.new(15, [3]) )
- mr.list.push( RPG::MoveCommand.new )
- $game_map.events[@event_id].force_move_route(mr)
复制代码
Now, you can apply the same move route to a number of events by using a loop with a variable for the event id. Let's say you have a little cutscene and there are 5 NPCs consecutively numbered as events 5, 6, 7, 8 and 9. You want to make the player follow a particular path around them, and you want them all to turn to face the player as he/she moves. You could do it with a number of move routes, trying to synchronise the timing, or you could do this:
mr = RPG::MoveRoute.new
mr.list = []
mr.list.push( RPG::MoveCommand.new(25,[]) )
mr.list.push( RPG::MoveCommand.new )
for evt in 5..9
$game_map.events[evt].force_move_route(mr)
end
The move route defaults are kept (repeat, no skip, no wait). After you add that script, add the player's move route, with a Wait for Completion. Then cancel the NPC move routes (so they stop turning to face the player if the player moves again) with this:
Code:
- mr = RPG::MoveRoute.new
- mr.list = []
- mr.list.push( RPG::MoveCommand.new )
- for evt in 5..9
- $game_map.events[evt].force_move_route(mr)
- end
复制代码
This is just a move route with the default settings, and no movement command, which has the effect of cancelling out any previous move routes that might have been running on the event.
本贴来自国际rpgmaker官方论坛作者:Shaz处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/creating-a-move-route-with-a-script-command.59367/