=begin #============================================================================== ** Effect: Set Variable Author: Hime Date: Jan 26, 2013 ------------------------------------------------------------------------------ ** Change log Jan 26, 2013 - updated to support equip/unequip triggers Nov 10, 2012 - updated to support all effect objects Oct 24, 2012 - 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 * Preserve this header ------------------------------------------------------------------------------ ** Required -Effect Manager (http://himeworks.com/2012/10/05/effects-manager) ------------------------------------------------------------------------------ Set the value of a switch when an effect object is used Tag skills with Where `id` is the ID of the variable to set `val` is an operand `op` will operate on the selected variable using val: = assign val to variable ID + add val to variable ID - subtract val from variable ID * multiply variable ID with val / divide variable ID by val % mod variable ID by val ** raise val to the power val << left shift by val >> right shift by val & bitwise AND ^ bitwise XOR | bitwise OR Note that short-hands such as += are unnecessary because the operations are evaluated as var[id] = var[id] op val #============================================================================== =end $imported = {} if $imported.nil? $imported["Effect_SetVariable"] = true #============================================================================== # ** Rest of the script #============================================================================== module Effects module Set_Variable Effect_Manager.register_effect(:set_var, 2.6) Op_Whitelist = ["=", "+", "-", "*", "/", "%", "**", "<<", ">>", "&", "^", "|"] end end class RPG::BaseItem # Check whether the operator is valid def add_effect_set_var(code, data_id, args) return unless Effects::Set_Variable::Op_Whitelist.include?(args[1]) args[0] = args[0].to_i args[2] = args[2].to_i add_effect(code, data_id, args) end end class Game_Battler < Game_BattlerBase def effect_set_var(user, item, effect) id, op, value = effect.value1 if op == "=" $game_variables[id] = value else $game_variables[id] = $game_variables[id].send(op, value) end end def item_effect_set_var(user, item, effect) effect_set_var(user, item, effect) end def weapon_effect_set_var_equip(obj, effect) id, op, value = effect.value1 if op == "=" $game_variables[id] = value else $game_variables[id] = $game_variables[id].send(op, value) end end alias :weapon_effect_set_var_attack :effect_set_var alias :armor_effect_set_var_guard :effect_set_var alias :weapon_effect_set_var_equip :weapon_effect_set_var_equip alias :weapon_effect_set_var_unequip :weapon_effect_set_var_equip alias :armor_effect_set_var_equip :weapon_effect_set_var_equip alias :armor_effect_set_var_unequip :weapon_effect_set_var_equip end