=begin #=============================================================================== Title: Negate Conditional Branch Author: Hime Date: Oct 22, 2013 -------------------------------------------------------------------------------- ** Change log Oct 22, 2013 - 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 allows you to create negated conditional branches in your events. For example, if your conditional branch tests "if actor exists", then the negated conditional branch tests "if actor does not exist". The purpose is to provide negation logic without having to figure out how to write the condition as a script call. -------------------------------------------------------------------------------- ** Installation In the script editor, place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage To negate a conditional branch, create a comment before a conditional branch and write #=============================================================================== =end $imported = {} if $imported.nil? $imported["TH_NegateConditionalBranch"] = true #=============================================================================== # ** Configuration #=============================================================================== module TH module Negate_Conditional_Branch Regex = //i def parse_negate_conditional_branch @negate_condition_parsed = true @list.size.times do |i| cmd = @list[i] if cmd.code == 108 && cmd.parameters[0] =~ TH::Negate_Conditional_Branch::Regex next_cmd = @list[i+1] next_cmd.negate_condition = true if next_cmd.code == 111 end end end end end #=============================================================================== # ** Rest of script #=============================================================================== module RPG class EventCommand attr_accessor :negate_condition end class Event::Page include TH::Negate_Conditional_Branch alias :th_negate_conditional_branch_list :list def list parse_negate_conditional_branch unless @negate_condition_parsed th_negate_conditional_branch_list end end class Troop::Page include TH::Negate_Conditional_Branch alias :th_negate_conditional_branch_list :list def list parse_negate_conditional_branch unless @negate_condition_parsed th_negate_conditional_branch_list end end end class Game_Interpreter alias :th_negate_conditional_branch_command_111 :command_111 def command_111 if @list[@index].negate_condition old_index = @index th_negate_conditional_branch_command_111 # revert the command skipping and negate the result, then check again @index = old_index @branch[@indent] = !@branch[@indent] command_skip if !@branch[@indent] else th_negate_conditional_branch_command_111 end end end