More Self-Switches
Authors: game_guy
Version: 1.5
Type: Event Modification
Key Term: Environment Add-on
IntroductionEver need more than 4 self switches? With this small script, you can now have as many self switches you want. You aren't just limited to letters either. You can have names for them.
Features
- More Self Switches
- Name them whatever
- Access/toggle them from wherever
Screenshots(http://decisive-media.net/gameguy/switch.png)
DemoN/A
Script
#===============================================================================
# More Self-Switches
# Version 1.5
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# Ever need more than 4 self switches? With this small script, you can now
# have as many self switches you want. You aren't just limited to letters
# either. You can have names for them.
#
# Features:
# -More Self Switches
# -Name them whatever
# -Access/toggle them at anytime
#
# Instructions:
# -First, lets create a self switch for our event. Anywhere in the event, add
# a comment and type this,
# Switch:switch_name.
# switch_name can be whatever you want to name the switch. Thats all you have
# to do to create a self switch for that page.
# There cannot be any spaces between the colon and the switch name.
# e.g. Switch: switch - Does not work.
# e.g. Switch:switch - Does work.
#
# -Now to turn this switch of or on, call this in a script call.
# self_switch("switch", true/false)
# switch is the switch name, this must be in double " " or single ' ' quotes.
# true/false tells the script whether to turn it off or on. true = on,
# false = off.
#
# -If you want to see if a self switch is on/off, use this script in a
# condtional branch.
# self_switch_state("switch") == true/false
# switch is the switch name, this must be in double " " or single ' ' quotes.
# true = on, false = off
#
# -Now you can toggle switches/check switch state of any event.
# Just use these script calls:
# self_switch("switch", true/false, event_id)
# self_switch_state("switch", event_id)
# The previous script calls still work without event_id, it just works within the event then.
#
# Compatibility:
# Not tested with SDK.
# Should work with anything.
#
# Credits:
# game_guy ~ For creating it.
# Thanks to KK20 for a Bug Fix
#===============================================================================
$gg_self_switches = 1.5
class Game_Event < Game_Character
alias gg_init_more_switches_lat initialize
def initialize(map_id, event)
gg_init_more_switches_lat(map_id, event)
@event.pages.each {|page| page.list.each {|command|
if [108, 408].include?(command.code)
command.parameters.each {|p| check_custom_switch(page, p) }
end
}}
refresh
end
def check_custom_switch(page, code)
a = code.split(':')
return if a[0].nil?
if a[0].downcase == "switch" && a[1] != nil
page.condition.self_switch_ch = a[1]
page.condition.self_switch_valid = true
end
end
end
class Interpreter
def self_switch(switch, state, event_id = @event_id)
key = [$game_map.map_id, event_id, switch]
$game_self_switches[key] = state
$game_map.need_refresh = true
end
def self_switch_state(switch, event_id = @event_id)
key = [$game_map.map_id, event_id, switch]
return $game_self_switches[key]
end
end
VX Version Here (http://rmrk.net/index.php/topic,42822.new.html#new)
InstructionsIn the script.
Place above main, below Scene_Debug, the normal.
CompatibilityNot tested with SDK.
Should work with anything.
Credits and Thanks
- game_guy ~ For creating it.
- Thanks to KK20 for a Bug Fix
Author's NotesEnjoy! :)
Erm, sorry for the double post, updated the script, forgot a couple of things in the script. :S
... umm, I don't see how this will be useful, :???:
after all we can use self switches unlimitedly
$game_self_switches[[$game_map.map_id, @event_id, 'STRING']] = true
and it's not just 'A', 'B', 'C', 'D'
Yea but then people would have to go through the work of figuring out how to set the event's page to that switch. This makes it easier for those non scripters to create new self switches, set them on and off, and set an events page to that self switch.
EDIT:
While this is true:
$game_self_switches[[$game_map.map_id, @event_id, 'STRING']] = true
People with little to no scripting knowledge would not know how to set an event's page to that custom switch they just turned on. This makes it easy because all you have to do is place a comment in the page.
And bam, that event's page self switch is set to "custom_switch".
Then you just call this:
self_switch("custom_switch", true)
To turn that self switch on.
Fixed a bug where event wouldn't go to correct page on map transfers.
I need help D:
I used this script after I build a couple of maps.
The script works fine, but on only one Map it always gives me a error message:
QuoteScript 'More Self Switches' line 59: NoMethodError occurred.
undefined Method 'downcase' for nil:NilClass
Hope you can help me :uhm:
(But all in all it works great :D)
The reason for the error is that you have a line break in one of your comments. Example is
This is my comment.
I just made a line break.
Here's a fix for that:
class Game_Event < Game_Character
alias gg_init_more_switches_lat initialize
def initialize(map_id, event)
gg_init_more_switches_lat(map_id, event)
@event.pages.each {|page| page.list.each {|command|
if [108, 408].include?(command.code)
command.parameters.each {|p| check_custom_switch(page, p) }
end
}}
refresh
end
def check_custom_switch(page, code)
a = code.split(':')
return if a[0].nil?
if a[0].downcase == "switch" && a[1] != nil
page.condition.self_switch_ch = a[1]
page.condition.self_switch_valid = true
end
end
end
class Interpreter
def self_switch(switch, state)
if @event_id > 0
key = [$game_map.map_id, @event_id, switch]
$game_self_switches[key] = state
end
$game_map.need_refresh = true
end
def self_switch_state(switch)
key = [$game_map.map_id, @event_id, switch]
return $game_self_switches[key]
end
end
To G_G (who just recently changed his name? :???:) the fix is in 'def check_custom_switch'. I added a 'return if a[0].nil?'.
Thanks! It works :D
Thanks KK20 for fixing that.
As requested by Heretic, you can now change the switches and get the switches current state from anywhere. e.g. In event id 5, you can check for event id 6's self switches now.
there is a mistake in your code
Quote
class Interpreter
def self_switch(switch, state)
self_switch(switch, state, @event_id) if @event_id > 0
end
def self_switch(switch, state, event_id)
key = [$game_map.map_id, event_id, switch]
$game_self_switches[key] = state
$game_map.need_refresh = true
end
def self_switch_state(switch)
return self_switch_state(switch, @event_id)
end
def self_switch_state(switch, event_id)
key = [$game_map.map_id, event_id, switch]
return $game_self_switches[key]
end
end
I believe you want it to be like this
Quote
class Interpreter
def self_switch(switch, state, event_id = @event_id)
key = [$game_map.map_id, event_id, switch]
$game_self_switches[key] = state
$game_map.need_refresh = true
end
def self_switch_state(switch, event_id = @event_id)
key = [$game_map.map_id, event_id, switch]
return $game_self_switches[key]
end
end
Yeah, forgot that works. Sorry, been working with C#, and before .NET 4.0, you can't have default arguments. Still, the code works lol.
EDIT: Nonetheless, fixed.
Quote from: gameus on September 21, 2013, 08:13:09 pm
...been working with C#, and before .NET 4.0, you can't have default arguments...
Not true, works in .NET 2.0. I haven't used any version lower than that, but it's been around for a while.
Oh really?
Quote from: ForeverZer0 on September 23, 2013, 07:18:34 am
Quote from: gameus on September 21, 2013, 08:13:09 pm
...been working with C#, and before .NET 4.0, you can't have default arguments...
Not true, works in .NET 2.0. I haven't used any version lower than that, but it's been around for a while.
I'll rephrase it then. Anything before Visual Studio 2010 e.g. before the existence of C# 4.0, you could not do it. I don't care for Visual Studio 2010, and I have difficulties getting XNA to work properly in 2012, so I tend to work with 2008 when I'm working with XNA.
You are making the mistake that C# are .NET version are not the same. gameus is right, C# is v4.0 in VS 2010 and since then they have added default arguments, regardless of whether you use .NET v2.0 or v4.0.