Global Interpreters for common events.
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 problem
https://image.ibb.co/kpXsvo/2.png
https://image.ibb.co/kwnLgT/3.pngThe 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
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7. 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:
=begin
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.
About the script: Did you ever had to use parallel process event, across the maps,
without it to restart everytime you transfer?
This script does just that, but only with the common events.
It does that by adding the common event interpreters into global array.
This global interpreter goes into the save file too.
You have the option to set this to work for all common events,
or only those, which id's are included in the array bellow, in the Settings
header.
=end
module GGZiron_GlobalInterpreter # don't touch this
#=============================Settings======================================
#Add all the common events Id's you want to work
#with global interpreter into this array.
#You can add as many entries you like, as long you follow the syntaxis rules.
COMMON_EVENTS =
#Or alternatively, if you want to work with all common events,
#set the value of this to true:
USE_FOR_ALL = false
#===========================End of settings===================================
#=============================================================================
# DO NOT EDIT ANYTHING BELLOW, UNLESS YOU
# UNDERSTAND THE CODE
#=============================================================================
end
module DataManager
singleton_class.send(:alias_method, :setup_new_game_old, :setup_new_game)
singleton_class.send(:alias_method, :extract_save_contents_old, :extract_save_contents)
singleton_class.send(:alias_method, :make_save_contents_old, :make_save_contents)
#======================Edited Original methods===============================
def self.setup_new_game
$game_interpreters = []
setup_new_game_old
end
def self.extract_save_contents(contents)
extract_save_contents_old(contents)
$game_interpreters= contents[:interpreter]
end
def self.make_save_contents
ggziron_extended_save_contents
end
#=============================================================================
#========================New Method===========================================
def self.ggziron_extended_save_contents
saves = {}
saves = make_save_contents_old
saves[:interpreter] = $game_interpreters
saves
end
#=============================================================================
end
class Game_CommonEvent
alias_method :initialize_original, :initialize
alias_method :refresh_original, :refresh
alias_method :update_original, :update
#======================Edited original methods================================
def initialize(common_event_id)
initialize_original(common_event_id)
@id = common_event_id
end
def refresh
global_interpreter? ?global_refresh :refresh_original
end
def update
global_interpreter? ? global_update : update_original
end
#=============================================================================
#============================New Methods======================================
def global_update
if $game_interpreters[@id]
$game_interpreters[@id].setup(@event.list) unless $game_interpreters[@id].running?
$game_interpreters[@id].update
end
end
def global_refresh
if active?
$game_interpreters[@id] ||= Game_Interpreter.new
else
$game_interpreters[@id] = nil
end
end
def global_interpreter?
work_with_this = GGZiron_GlobalInterpreter::COMMON_EVENTS.include?(@id)
work_with_all =GGZiron_GlobalInterpreter::USE_FOR_ALL
work_with_this||work_with_all
end
#=============================================================================
end
And here is the header, together with the terms of use:
Spoiler: Click to see the script's headerAuthor: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/
页:
[1]