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

[转载发布] Global Interpreters for common events.

[复制链接]
累计送礼:
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 21:40:21 | 显示全部楼层 |阅读模式
    What is a script with such a boring name for?

    Did you ever happen to use a parallel common event? It will run all across the maps. But alas, it will restart once you transfer to a new map. And thus, if you don't want that to happen, you would need heavy eventing.
    Spoiler: Click to see demonstration of the problemThe first photo shows the common event I made.
    Second photo is how it reached to the third message on it's execution.
    Third photo shows what happens once the player transfers to another map, while the event still works.

    Well, that won't happen anymore with this script
    . In the same example, the third image would show the forth message of the common event, if my script were activated.

    This script works only with common events!!!

    So, why do the common events restart?
    What I see of it, it is because their interpreter is assigned to class instance variable, which is erased once you transfer to another map. In my script, the interpreters are stored in global array, which is also added to the save file.

    What it is that interpreter anyway?
    The interpreter is class in the RPG Maker, that reads and interpret events code, and execute it. Which is why it is so important to be preserved when the player transfers to another map, if we don't want the common event to restart its execution.

    You don't want all common events to have global interpreter?
    There are settings. You can fill an array with the id's of the common events you want to have global interpreter, or set all to work with it (which I am not sure how much that will affect the productivity).

    Here is the script:
    Spoiler: Click to see the code
                    Code:       
    1. =begin
    2. Author:GGZiron
    3. Script Name: Global Interpreters
    4. Term of use: Free both for comercial and non comercial use. Credit me
    5. if you are going to use it. Do not share directly on other forums. Give link
    6. instead.
    7. Optionally, you can send me link to check your finished game, if
    8. my script is used on it.
    9. Version 1.0. Date of release: 22 May 2018
    10. Version 1.1 Date: 26 May 2018
    11. Changelog:
    12. Added additional aliases for more compability. Also fixed one part of my
    13. code that I did not liked.
    14. About the script: Did you ever had to use parallel process event, across the maps,
    15. without it to restart everytime you transfer?
    16. This script does just that, but only with the common events.
    17. It does that by adding the common event interpreters into global array.
    18. This global interpreter goes into the save file too.
    19. You have the option to set this to work for all common events,
    20. or only those, which id's are included in the array bellow, in the Settings
    21. header.
    22. =end
    23. module GGZiron_GlobalInterpreter # don't touch this
    24. #=============================Settings======================================
    25. #Add all the common events Id's you want to work
    26. #with global interpreter into this array.
    27. #You can add as many entries you like, as long you follow the syntaxis rules.
    28. COMMON_EVENTS =[1, 2, 3]
    29. #Or alternatively, if you want to work with all common events,
    30. #set the value of this to true:
    31. USE_FOR_ALL = false
    32. #===========================End of settings===================================
    33. #=============================================================================
    34. #                   DO NOT EDIT ANYTHING BELLOW, UNLESS YOU
    35. #                            UNDERSTAND THE CODE
    36. #=============================================================================
    37. end
    38. module DataManager
    39. singleton_class.send(:alias_method, :setup_new_game_old, :setup_new_game)
    40. singleton_class.send(:alias_method, :extract_save_contents_old, :extract_save_contents)
    41. singleton_class.send(:alias_method, :make_save_contents_old, :make_save_contents)
    42. #======================Edited Original methods===============================
    43.    def self.setup_new_game
    44.       $game_interpreters = []
    45.       setup_new_game_old
    46.       end
    47.     def self.extract_save_contents(contents)
    48.       extract_save_contents_old(contents)
    49.       $game_interpreters  = contents[:interpreter]
    50.       end
    51.     def self.make_save_contents
    52.       ggziron_extended_save_contents
    53.       end
    54. #=============================================================================
    55. #========================New Method===========================================
    56.     def self.ggziron_extended_save_contents
    57.       saves = {}
    58.       saves = make_save_contents_old
    59.       saves[:interpreter] = $game_interpreters
    60.       saves
    61.       end
    62. #=============================================================================
    63. end
    64. class Game_CommonEvent
    65.    alias_method :initialize_original, :initialize
    66.    alias_method :refresh_original, :refresh
    67.    alias_method :update_original, :update
    68. #======================Edited original methods================================
    69.   def initialize(common_event_id)
    70.     initialize_original(common_event_id)
    71.     @id = common_event_id
    72.     end
    73.   def refresh
    74.     global_interpreter? ?  global_refresh :  refresh_original
    75.     end
    76.   def update
    77.     global_interpreter? ? global_update : update_original
    78.     end
    79. #=============================================================================
    80. #============================New Methods======================================
    81.   def global_update
    82.     if $game_interpreters[@id]
    83.       $game_interpreters[@id].setup(@event.list) unless $game_interpreters[@id].running?
    84.       $game_interpreters[@id].update
    85.       end
    86.     end
    87.   def global_refresh
    88.     if active?
    89.       $game_interpreters[@id] ||= Game_Interpreter.new
    90.     else
    91.       $game_interpreters[@id] = nil
    92.       end
    93.     end
    94.   def global_interpreter?
    95.     work_with_this = GGZiron_GlobalInterpreter::COMMON_EVENTS.include?(@id)
    96.     work_with_all =  GGZiron_GlobalInterpreter::USE_FOR_ALL
    97.     work_with_this  ||  work_with_all
    98.     end
    99. #=============================================================================
    100. end
    复制代码


    And here is the header, together with the terms of use:
    Spoiler: Click to see the script's header
    Author:GGZiron
    Script Name: Global Interpreters
    Term of use: Free both for comercial and non comercial use. Credit me if you are going to use it. Do not share directly on other forums. Give link instead. Optionally, you can send me link to check your finished game, if my script is used on it.
    Version 1.0. Date of release: 22 May 2018
    Version 1.1 Date: 26 May 2018
    Changelog:
    Added additional aliases for more compability. Also fixed one part of my
    code that I did not liked.

    If I notice something wrong, will try to fix it. You can report bugs too. Cannot promise to fix, but ll try.


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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-8-17 13:39 , Processed in 0.134903 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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