Created
June 11, 2013 19:51
-
-
Save kl/5760030 to your computer and use it in GitHub Desktop.
RPG Maker VX Ace run common event on state removal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module StateRemoveCommonEventsKal | |
TAG_NAME = "srce" | |
class IDExtractor | |
def get_common_event_id_for_state(state_id) | |
rpg_state = get_rpg_state(state_id) | |
extract_common_event_id(rpg_state.note) | |
end | |
private | |
def get_rpg_state(state_id) | |
$data_states.find do |rpg_state| | |
rpg_state && rpg_state.id == state_id | |
end | |
end | |
def extract_common_event_id(note) | |
id = note[/<#{TAG_NAME}\s+(\d+)\s*>/, 1] | |
id.nil? ? nil : id.to_i | |
end | |
end | |
class CommonEventRunner | |
def run(common_event_id) | |
page = make_page(common_event_id) | |
$game_troop.interpreter.setup(page.list) | |
end | |
private | |
def make_page(id) | |
page = RPG::Troop::Page.new | |
# 117 => common event code, 0 => indent, id => id of common event | |
page.list.unshift(RPG::EventCommand.new(117, 0, [id])) | |
page | |
end | |
end | |
@id_extractor = IDExtractor.new | |
@common_event_runner = CommonEventRunner.new | |
def self.run_event_from_state(state_id) | |
event_id = @id_extractor.get_common_event_id_for_state(state_id) | |
@common_event_runner.run(event_id) if event_id | |
end | |
end | |
class Game_BattlerBase | |
alias_method :erase_state_srce_kal, :erase_state | |
def erase_state(state_id) | |
StateRemoveCommonEventsKal.run_event_from_state(state_id) | |
erase_state_srce_kal(state_id) | |
end | |
end |
Of course, go ahead and use/edit as you see fit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI! omg this post is super duper old I hope u respond but I am so totally not going to use it without asking u first, could I use this for a project that may or may not be commercial? I would add credit obv.