Do $something if inside Area Extended 0.8 by Bulletxt & Digioso - http://www.digioso.org
Introduction This is a modified version of Bulletxts Do $something if inside Area Script. The basic idea is still the same: The script does something if the player steps into a area. The original script however could only enable switches and disabled them when the player left the area. This version here still can do that, but you can now start events directly as well. You no longer have to have an event that waits for a switch. You just need the event, so you can save switches this way. In addition to that this version here has some bugfixes as well. EG.: in the original script you couldn't use areas on different maps (or even on the same map) to change the same switch. So one switch per area and one area per switch. Now you can set multiple switches (or start multiple events ) with one area and areas sharing the same switches/events are supported as well. Since Bulletxt gave his approval to post a new thread for this version, well so I did.
Features - enables switches if you go into a area or starts events directly - disables the switches if you leave the area. Events don't need to be disabled. - allows overlapping areas - allows single areas to set one or more switches at the same time - allows single areas to start one or more events at the same time - supports multiple areas to set the same switches/event-ids, regardless if they're on the same map or on another one.
Screenshot Well... not really possible to show this with a screenshot.
How to Use
Instructions
Put below "Materials" and above "Main Process". See the instructions in the script for further details. Also check the demo to see the script in action!
CODE
################################################################################ # INSTRUCTIONS # # This script enables one or more switches or starts one or more events if you # go into an area. If you leave the area the switch is being disabled again. # Below you can setup what you want to put into an area name: # The defaults are <switch switch-ID>, so have to insert <switch switch-ID> # into the name of any area that uses this script for the switch way # and <event event-ID> for events. Replace ID with the ID of the # switch(es)/event(s) that the script will turn on or run.
# Example: Forest <switch 1> # This will enable switch 1 if the player enters the area. # or # Example: Forest <event 1> # This will start the event with ID 1 on the current map. # To set multiple switches (or start multiple events) you have to seperate them # by an underscore (_). # Example: <switch 1_2_3) # This enables switces 1, 2 and 3 when you go into the area and disables them when # you leave it. <event 3_4_5> will start events 3, 4 and 5 in that order.
# CONFIGURATION
#This is the switch that turns ON/OFF this script #The script is OFF by default, so you must turn it on in an event #I recommend to turn OFF the script in maps where you don't need this script #Default is 100
DSIA = 100
# Here you can specify what you want to have in your area name to start this # Default is: switch for switches and event for events. # The area name in the game will have to be like this: # <What_you_setup_below Switch/Event_id> # Example: <switch 1>
################################################################################ =begin Do $something if inside Area
Version: 0.8 Date: 12.11.2011 Author: BulletXt Email: bulletxt@gmail.com Editor: Enelvon Small Bug Fix by Miget man12 Edited by Digioso (http://www.digioso.org) - Credit also Zetu for the idea: You can now choose if you want to use switches or if you want to directly start events. And a lot more. :) Changelog: 0.5 - Bugfixes 0.6 - Bugfixes 0.7 - Included support to start multiple events/set multiple switches with one area. 0.8 - Now you can use both events and switches at the same time. You no longer have to decide if you want to use the switch way or the event way. Use both. :) =end
################################################################################ # INSTRUCTIONS # # This script enables one or more switches or starts one or more events if you # go into an area. If you leave the area the switch is being disabled again. # Below you can setup what you want to put into an area name: # The defaults are <switch switch-ID>, so have to insert <switch switch-ID> # into the name of any area that uses this script for the switch way # and <event event-ID> for events. Replace ID with the ID of the # switch(es)/event(s) that the script will turn on or run.
# Example: Forest <switch 1> # This will enable switch 1 if the player enters the area. # or # Example: Forest <event 1> # This will start the event with ID 1 on the current map. # To set multiple switches (or start multiple events) you have to seperate them # by an underscore (_). # Example: <switch 1_2_3) # This enables switces 1, 2 and 3 when you go into the area and disables them when # you leave it. <event 3_4_5> will start events 3, 4 and 5 in that order.
# CONFIGURATION
#This is the switch that turns ON/OFF this script #The script is OFF by default, so you must turn it on in an event #I recommend to turn OFF the script in maps where you don't need this script #Default is 100
DSIA = 100
# Here you can specify what you want to have in your area name to start this # Default is: switch for switches and event for events. # The area name in the game will have to be like this: # <What_you_setup_below Switch/Event_id> # Example: <switch 1>
# This is a workaround for a bug in the Game_Event class # If we ask the game to start an event that cannot start (eg conditions aren't # met for any of the event pages) the game normally would crash. # With this method we can return the array containing the event commands and # then check if there is something to do. class Game_Event < Game_Character
attr_reader :list
def digioso_return_list return @list end end
class Scene_Map < Scene_Base
# This method is aliased because we need to have a hash to store data in. alias digioso_event_start start def start digioso_event_start @digioso_area_started = Hash.new end
#-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias enelvon_bulletext_area_update update def update enelvon_bulletext_area_update ########################################################################### ##### #if the script switch is on if $game_switches[DSIA] == true area_found = Hash.new # Go through all areas for area in $data_areas.values # Is the found area on the map the player is on? next if(area.map_id != $game_map.map_id) # Check the area name for stuff to do. area.name.scan(/<(#{DIGIOSO_DO_SOMETHING_IN_AREA_NAME_SWITCH}|#{DIGIOSO_DO_SOMETHING_IN_AREA_N AME_EVENT}) (.*?)>/i) type = $1 # Any stuff found? No? Then it's a normal area. next if($2.nil?) # Get _-seperated stuff. for m in $2.split(/_/) m = m.to_i # Is the player in the area? if($game_player.in_area?(area)) area_found[m] = true # Let's see if we already started the stuff in this area unless(@digioso_area_started.has_key?(m)) # We didn't @digioso_area_started[m] = type # Do we want to use switches? if(type == DIGIOSO_DO_SOMETHING_IN_AREA_NAME_SWITCH) # Set game switch to true $game_switches[m] = true $game_map.need_refresh = true # tells $game_map that Events should be # refreshed # Lets check if the event is startable elsif(! $game_map.events[m].digioso_return_list.nil?) # Start event $game_map.events[m].start end end end end end # We went through all areas. Let's check if we need to disable some switches # or make an event startable again. # Are there even started events/set switches? unless(@digioso_area_started.empty?) # If yes, go through all of them. @digioso_area_started.each do|key,value| # Check if this entry is still valid. unless(area_found.has_key?(key)) # Player isn't in this area anymore - so disable switch or make # the events startable again. if(value == DIGIOSO_DO_SOMETHING_IN_AREA_NAME_SWITCH) # Disable switch $game_switches[key] = false $game_map.need_refresh = true # Events should be refreshed end @digioso_area_started.delete(key) end end end end end end
FAQ Q: The demo won't open, how to open it? A: Download 7zip and try again.
Q: Compatibility issues? A: No known issues. However you should disable it on maps (disable the switch used for the script) you don't need it to get a better performance.
Credit and Thanks Author: BulletXt Email: bulletxt@gmail.com Editor: Enelvon Small Bug Fix by Miget man12 Edited by Digioso (http://www.digioso.org) - Credit also Zetu for the idea: You can now choose if you want to use switches or if you want to directly start events. And a lot more.
Author's Notes Free to use in non-commercial projects. Modify the script if you like but credit everybody who worked on this script. Also I'd like to be informed of edits so that I can update the script here and maybe use them myself.
Rosenblack
Nov 15 2011, 03:24 PM
sweet
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.