设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 94|回复: 0

[制作教程] Creating a Move Route with a Script command

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    前天 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4461

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    22929
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    28284

    灌水之王

    发表于 前天 15:23 | 显示全部楼层 |阅读模式
    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:        
    1. class RPG::MoveRoute
    2.   def initialize
    3.     @repeat = true
    4.     @skippable = false
    5.     @wait = false
    6.     @list = [RPG::MoveCommand.new]
    7.   end
    8.   attr_accessor :repeat
    9.   attr_accessor :skippable
    10.   attr_accessor :wait
    11.   attr_accessor :list
    12. end
    13. class RPG::MoveCommand
    14.   def initialize(code = 0, parameters = [])
    15.     @code = code
    16.     @parameters = parameters
    17.   end
    18.   attr_accessor :code
    19.   attr_accessor :parameters
    20. 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:        
    1. > Direction Fix OFF
    2. > Turn Left
    3. > Wait: 3 frame(s)
    4. > Turn Right
    5. > Wait: 3 frame(s)
    6. >
    复制代码


            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:        
    1. mr = RPG::MoveRoute.new
    2. mr.repeat = false
    3. mr.wait = true
    4. 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:        
    1. > Direction Fix OFF ... code 36, no parameters
    2. > Turn Left         ... code 17, no parameters
    3. > Wait: 3 frame(s)  ... code 15, parameter is the number of frames (see line 150 in default script)
    4. > Turn Right        ... code 18, no parameters
    5. > Wait: 3 frame(s)  ... code 15, parameter is the number of frames
    6. >                   ... 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:        
    1. mr.list.push( RPG::MoveCommand.new(36, []) )
    2. mr.list.push( RPG::MoveCommand.new(17, []) )
    3. mr.list.push( RPG::MoveCommand.new(15, [3]) )
    4. mr.list.push( RPG::MoveCommand.new(18, []) )
    5. mr.list.push( RPG::MoveCommand.new(15, [3]) )
    6. 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:        
    1. $game_map.events[@event_id].force_move_route(mr)
    复制代码


            So your full script is going to look something like this:

    Spoiler                 Code:        
    1. mr = RPG::MoveRoute.new
    2. mr.repeat = false
    3. mr.wait = true
    4. mr.list = []
    5. mr.list.push( RPG::MoveCommand.new(36, []) )
    6. mr.list.push( RPG::MoveCommand.new(17, []) )
    7. mr.list.push( RPG::MoveCommand.new(15, [3]) )
    8. mr.list.push( RPG::MoveCommand.new(18, []) )
    9. mr.list.push( RPG::MoveCommand.new(15, [3]) )
    10. mr.list.push( RPG::MoveCommand.new )
    11. $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:        
    1. mr = RPG::MoveRoute.new
    2. mr.list = []
    3. mr.list.push( RPG::MoveCommand.new )
    4. for evt in 5..9
    5.   $game_map.events[evt].force_move_route(mr)
    6. 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/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-14 16:52 , Processed in 0.086305 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表