=begin CSCA RegionSwitch version: 1.1 Created by: Casper Gaming (https://www.caspergaming.com/) Compatibility: Made for RPGVXAce IMPORTANT: ALL CSCA Scripts should be compatible with each other unless otherwise noted. INTRODUCTION: This script automatically turns a switch on if the player is inside a region. FEATURES: -Turns a switch ON if player is in a region. SETUP Script is Plug and Play. To set up regions and switches affected, insert these notetags in the map's notebox: =============================================================================== The X will be the regions affected, more than 1 region is acceptable. For example, will turn switches on if the player is in region 1 or region 2. =============================================================================== The X will be the switches affected, more than 1 switch is acceptable. For example, The X will be the terrain tags affected, more than 1 terrain tag is acceptable. For example, will turn switches on if the player is standing on a tile with terrain tag 1 or 2. =============================================================================== The X will be the switches affected, more than 1 switch is acceptable. For example, Will turn switch 3 ON if player is in region 1, and switch 4 ON if in region 2. =============================================================================== Example: Will turn switch 3 ON if player is standing on a tile with terrain tag 1, and switch 4 ON if standing on a tile with terrain tag 2. ================================================================================ ================================================================================ UPDATES version 1.1 - Added ability to turn switches on by terrain tags. - Made code more compatible (Now works well with CSCA Event Movement). ================================================================================ CREDIT and TERMS: Please visit https://www.caspergaming.com/terms-of-use/ for terms of use and credit guidelines =end $imported = {} if $imported.nil? $imported["CSCA-RegionSwitch"] = true class Game_Map #--------------------------------------------------------------------------# # alias method. # #--------------------------------------------------------------------------# alias :csca_rs_update :update def update(main) csca_update_region_switch if @map.note =~ //i csca_update_tag_switch if @map.note =~ //i csca_rs_update(main) end #--------------------------------------------------------------------------# # Turn switches On/Off with regions # #--------------------------------------------------------------------------# def csca_update_region_switch regions = csca_get_rs_note(:region) switches = csca_get_rs_note(:switch) for i in 0...regions.size region_id($game_player.x, $game_player.y) == regions[i] ? csca_toggle_switch(switches[i], true) : csca_toggle_switch(switches[i], false) end end #--------------------------------------------------------------------------# # Turn switches On/Off with tags # #--------------------------------------------------------------------------# def csca_update_tag_switch tags = csca_get_rs_note(:tag_terrain) tag_switches = csca_get_rs_note(:tag_switch) for i in 0...tags.size terrain_tag($game_player.x, $game_player.y) == tags[i] ? csca_toggle_switch(tag_switches[i], true) : csca_toggle_switch(tag_switches[i], false) end end #--------------------------------------------------------------------------# # Get region tag, and switch arrays # #--------------------------------------------------------------------------# def csca_get_rs_note(type) case type when :region; @map.note =~ //i when :switch; @map.note =~ //i when :tag_terrain; @map.note =~ //i when :tag_switch; @map.note =~ //i end ids = [] for x in $1.split(",") ids.push(x.to_i) end return ids end #--------------------------------------------------------------------------# # Toggle # #--------------------------------------------------------------------------# def csca_toggle_switch(switch, b) $game_switches[switch] = b unless $game_switches[switch] == b end end