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

[转载发布] Event Wrapper

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

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 2026-8-1 08:24:37 | 显示全部楼层 |阅读模式
    Event Wrapper

    -Tsukihime

    Overview

    This script provides a wrapper for the RPG::Event object. It adds additional methods to allow you to create event commands directly  without having to go through the event editor, and provides intuitive  names that are based on the command names available on the event editor.

    This is mainly a scripting tool, and is not intended to replace the event editor.

    If something can be achieved using the event editor, use it.

    Features


    • Easily create events using scripts
    • An Event Builder that helps you create your list of command events
    • Use the Event Builder to mix scripting with event commands to create all sorts of event processing
    • Create move routes using a Move Builder, using the same syntax as the Event Builder with intuitive move commands and some custom move commands for convenience (eg: move strings)

    Downloads

    Script: http://db.tt/QiaEiAN2

    Demo: http://db.tt/TavscwIB

    If you are not sure where to start, I've provided some examples in the demo.

    Usage

    Currently, your scripted events are just scripts, so they are not very accessible. You must have an event on the map to be able to use a script call to create more events, though after that your custom events can create their own events provided that you've written the logic into their command list.

    You can choose to write methods in Game_Interpreter or just a custom module. As long as you can call the methods that will create the event.



                    Code:       
    1. class Game_Interpreter
    2.    def make_my_event
    3.       # your event building code
    4.    end
    5. end
    复制代码





    Creating an event is simple.

    1. Instantiate an Event object, passing in x,y coordinates



                    Code:       
    1. event = Event.new(2, 4)
    复制代码

    2. Set some page properties. For a list of properties, refer to the help manual, or look through the Event class. You can either access the properties directly, or use some convenience methods defined in the Event class. So for example, assuming we are on page 0,



                    Code:       
    1. event.page[0].character_name = "actor1"
    2. event.character_name = "actor1"
    复制代码

    Both do the same thing.

    Some common properties you might set are



                    Code:       
    1. event.priority_type = 1    # 1 is "same as characters". You can choose 0, 1, or 2
    2. event.trigger = 2    # 2 is "event touch". It goes from 0 to 4, same order as in the editor
    3. event.direction_fix = true
    复制代码

    Note that the convenience methods always operate on the "current" page.

    When you first initialize a new event, the "current" page is 0.

    You can change the page by calling



                    Code:       
    1. event.set_page(n)
    复制代码

    For some integer n. Thus, you may want to work on one page a time, as such:



                    Code:       
    1. event.set_page(0)
    2. #do stuff for page 0
    3. event.set_page(1)
    4. # do stuff for page 1
    5. event.set_page(2)
    6. # do stuff for page 2
    复制代码

    3. Set some page conditions. Refer to the Event_Condition class for details.



                    Code:       
    1. event.condition.switch1_id = 2   # this means switch 2 must be ON
    2. event.condition.switch2_id = 3   # remember that the event supports two switches
    3. event.condition.actor_id = 4     # actor 4 must be in party
    复制代码

    4. Add the event to the map



                    Code:       
    1. $game_map.add_event(event)
    复制代码

    That should create an event on the map at the designated x,y coords when we make a script call to create this event, but it's not very useful. We want to add some event commands.

    I've provided an "Event Builder" that allows you to use a custom syntax to create your events in addition to regular ruby syntax.

    I have written a set of methods that essentially alias Game_Interpreter methods, except instead of using command codes, I use the common editor names to identify what the command is. All of the methods are available in the EventCommands class. So for example, let's write an event that will display a simple message



                    Code:       
    1. event = Event.new(3, 3)
    2. event.character_name = "actor1"
    3. event.character_index = 2
    4. event.build {
    5.   show_text("actor1", 2)
    6.   add_message("Hello World")
    7. }
    8. $game_map.add_event(event)
    复制代码

    When you create this event, you can talk to it and it will say "Hello World"





    Note that `add_message` can take multiple strings. Each string will be treated as a new line.



                    Code:       
    1. event.build {
    2.   show_text("actor1", 2)
    3.   add_message("Hello World", "Goodbye")
    4. }
    复制代码

    The event builder supports branching, which is used in various commands such as showing a list of choices, conditional branching, and other things.



                    Code:       
    1. event.build {
    2.    show_text("actor1", 1)
    3.    add_message("What do you like?")
    4.    show_choices(["Health", "Mana"], 0)
    5.    choice_branch(0) {
    6.       show_text("actor1", 1)
    7.       add_message("So you prefer health")
    8.    }
    9.    choice_branch(1) {
    10.       show_text("actor1", 1)
    11.       add_message("Mana is ok too")
    12.    }
    13. }
    复制代码

    This example demonstrates how to using branching to create a list of choices that the player can select from, and how to define the commands that should be executed depending on the choice.

    Naturally, you can provide an unlimited number of branches, though the choice window is not designed for that (meaning, you might have choices that are drawn outside the screen if there are just too many)





    It is also possible to use typical ruby syntax when building your commands.

    You know, take advantage of loops and variables.



                    Code:       
    1. event = Event.new(x, y)
    2. event.character_name = "actor2"
    3. event.character_index = 5
    4. event.build {
    5.   show_text("actor2", 5)
    6.   add_message("Which party member do you wish to view?")
    7.   actors = $game_party.members.collect {|actor| actor.name }
    8.   show_choices(actors, 0)
    9.   $game_party.members.each_with_index { |actor, i|
    10.     choice_branch(i) {
    11.       show_text(actor.face_name, actor.face_index)
    12.       add_message("%s is a level %d %s" %[actor.name, actor.level, actor.class.name])
    13.     }
    14.   }
    15. }
    16. $game_map.add_event(event)
    复制代码

    This example demonstrates how you would write an event that will go  through all of the actors in your party, display their names in a choice list, and then when you select an actor, it will display information about the actor in a text box.









    However, note that because this code is run only when the event is created, the event commands have already been hardcoded into the event. It is no different from manually creating an event and writing your own choice branches and such.

    One of the goals of this script is to eventually allow you to create completely dynamic events whose commands may change at any time.

    I am currently working on a way for you to specify that an event should be "rebuilt" everytime you enter the map, or your refresh the event. By rebuilding the event, you are basically clearing out the command list and re-running the script, which will correctly reflect the current state of the game.

    Reference

    The objects of interest are

    RPG::Event

    RPG::Event:
    age

    RPG::Event:
    age::Condition

    RPG::Event:
    age::Graphic

    RPG::EventCommand

    RPG::MoveRoute

    RPG::MoveCommand

    All of these are described in the help manual under RGSS Reference Manual -> Game Library -> RPGVXAce Data Structures.


    本贴来自国际rpgmaker官方论坛作者:Tsukihime处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/event-wrapper.3148/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-8-17 21:10 , Processed in 0.146324 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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