=begin #=============================================================================== Title: Event Wait Command Author: Hime Date: Dec 19, 2014 URL: http://himeworks.com/2014/12/event-wait-command/ -------------------------------------------------------------------------------- ** Change log Dec 19, 2014 - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script introduces a new command that allows you to tell an event to stop and wait until a certain condition is met before proceeding. RPG Maker comes with a wait command, but that is only to check whether a certain amount of frames have passed before proceeding. This custom wait command allows you to condition on things such as the value of a switch or variable, player input, or anything else that you can imagine that can be done with formulas. The command is provided in two formats: a marked up conditional branch, or a script call so that you can choose which one you are most comfortable with. -------------------------------------------------------------------------------- ** Installation In the script editor, place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage There are two ways to specify a wait command: using a conditional branch along with a comment, or using a script call. -- Conditional Branch -- Start by creating a comment and add the following to it Then immediately after the comment, create a conditional branch. The event will understand that it should keep evaluating the condition until it is true. This is not a normal conditional branch. Because it will continue to wait until the condition is true, the else branch will never be entered. -- Script Call -- Conditional branch supports script calls, but if you would like a compact command, you can simply use a script call command directly wait_until(CONDITION) Where the CONDITION is a valid formula that resolves to true or false. The event will wait until the condition is met. -------------------------------------------------------------------------------- ** Examples To have an event wait until the player pressed the C button (Z or Return key), use the script call wait_until("Input.trigger?(:C)") To wait until variable 5 has a value of 20, the conditional branch would look like this #=============================================================================== =end $imported = {} if $imported.nil? $imported[:TH_EventWaitCondition] = true #=============================================================================== # ** Configuration #=============================================================================== module TH module Event_Wait_Condition Regex = //i end end class Game_Interpreter def wait_until(condition) proc = eval( "lambda { #{condition} }" ) Fiber.yield until proc.call end alias :th_event_wait_condition_command_111 :command_111 def command_111 if @list[@index].is_wait_condition Fiber.yield(th_event_wait_condition_command_111) until @branch[@indent] else th_event_wait_condition_command_111 end end end module RPG class Event::Page alias :th_event_wait_condition_list :list def list parse_event_wait_condition unless @event_wait_condition_parsed th_event_wait_condition_list end def parse_event_wait_condition @event_wait_condition_parsed = true @list.each_with_index do |cmd, i| if cmd.code == 108 && cmd.parameters[0] =~ TH::Event_Wait_Condition::Regex next_cmd = @list[i+1] if next_cmd.code == 111 next_cmd.is_wait_condition = true end end end end end class EventCommand attr_accessor :is_wait_condition attr_accessor :wait_time end end