Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # * [ACE] Custom Switch Storage
- #===============================================================================
- # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
- # * Version: 1.2
- # * Updated: 29/04/2015
- # * Requires: -------
- #-------------------------------------------------------------------------------
- # * < Change Log >
- #-------------------------------------------------------------------------------
- # * Version 1.0 (15/01/2015)
- # - Initial release.
- # * Version 1.1 (17/01/2015)
- # - Fixed switch initialization.
- # Switches didn't reset until the game was shut down and restarted,
- # regardless if the player quited the current game and started a new one.
- # This is now fixed.
- # * Version 1.2 (29/04/2015)
- # - Fixed the event comments checking. Whoops!
- #-------------------------------------------------------------------------------
- # * < Description >
- #-------------------------------------------------------------------------------
- # * By default, you have 5000 switches available to set up and use in your game,
- # and you can control them only one by one with a "Control Switches" event
- # command for each of them. This gets more complicated when you want to make a
- # switch toggle event, where the switch will either be turned ON or OFF
- # depending on the current state of the switch. Also, you can only assign 2 of
- # these switches for a page condition, and you can't make a page condition
- # which says "if switch 32 is turned OFF", for example.
- # While 5000 switches sounds more than enough, the available operations for
- # them are pretty limited without making long and repetetive, sometimes even
- # complicated condition checks.
- #
- # * With this script, you can:
- # - Create infinite amount of custom switches for your game.
- # - Name them however you want, so you will never mix them.
- # - Arrange them in a clean and organized way in the script.
- # - Assign them into a group.
- # - Turn them ON/OFF or even toggle them with simple script calls.
- # - Turn groups ON/OFF or even toggle them with simple script calls.
- # - Assign custom switch requirements for your events with unlimited switches.
- # - Shorten your custom switch requirements by simply assigning a group
- # requirement, or even more group requirements for an event.
- # - Save countless lines on your event pages.
- #-------------------------------------------------------------------------------
- # * < Event Comments >
- #-------------------------------------------------------------------------------
- # * To make custom switch requirements for your events, you need to use comment
- # commands on their pages. When I refer to the name of your custom switches
- # and groups, here is what I mean:
- #
- # - In the script, a switch looks like this:
- #
- # :custom1 => false, or :whatever32 => true, etc,
- #
- # Notice the ":" sign before the actual name of the switch!
- # When you make a custom switch requirement for your event page, you will
- # need to use the name of the switches or groups in it without that ":" sign!
- # So, the correct names from the above examples are:
- #
- # custom1, whatever32
- #
- # Now you know what I mean when I write
- # "the name of your custom switch/group" below in the detailed explanation.
- #
- # - There will be another commonly used word here. That one goes by "value".
- # The value can be either true or false.
- # If you use true, the page won't activate unless the assigned switch/group
- # is turned ON.
- # If you use false, the page won't activate unless the assigned switch/group
- # is turned OFF.
- #
- # Keep this in mind when setting up custom switch requirements!
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To make a single switch requirement for an event, make a comment command
- # which looks like this:
- #
- # <single_sw_req: name, value>
- #
- # name = The name of your custom switch.
- # value = The state required for the switch. Can be either true or false.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To make a single group switch requirement for an event, make a comment
- # command which looks like this:
- #
- # <group_sw_req: name, value>
- #
- # name = The name of your group.
- # value = The state required for the group. Can be either true or false.
- #
- # NOTE:
- # If you use a single group requirement for an event page, that means that all
- # switches assigned to that group must have the value defined in the comment.
- # So, if you use true for the value, all of the switches from the group must
- # be turned ON before the event activates!
- # Same thing applies if you use false, but than, obviously, all of the switches
- # from the group must be turned OFF before the event activates.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To make a fully customizable switch/group requirement for an event, make a
- # comment command which looks like this:
- #
- # <custom_sw_req: name value, name value, name value ... >
- #
- # name = The name of a switch or group. Both can be used.
- # value = The state required for the switch/group. Can be either true or false.
- #
- # All of the rules from the other switch requirement comments applies here too!
- #
- # The beauty of this last type of custom switch requirement is that you can
- # assign mixed switch requirements for your event page.
- # You can use single switch names or group names too.
- # You can also use true for one requirement and false for another one, so you
- # can create complicated requirements for your pages without having to make
- # dozens of (often nested) conditional branches on your event page.
- # You can also use unlimited number of switch requirements!
- # Don't forget to use groups to shorten your comments for the requirements!
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * Some examples:
- # (NOTE: The examples are using the sample switches and groups set up in the
- # script initially to present some exact practical examples.)
- #
- # <single_sw_req: test1, false>
- # The event will not start until the switch named :test1 is turned OFF.
- #
- # <group_sw_req: grupy2, true>
- # The event will not start until all of the switches are turned ON from the
- # group named :grupy2.
- #
- # <custom_sw_req: test3 true, test4 false, grupy5 true>
- # The event will not start until:
- # - The switch named :test3 is turned ON.
- # - The switch named :test4 is trurned OFF.
- # - All of the switches from :grupy5 are turned ON.
- #-------------------------------------------------------------------------------
- # * < Script Calls >
- #-------------------------------------------------------------------------------
- # * The rules for the script calls are the same as for the custom page
- # requirements mentioned above!
- #
- # There is a little difference thought:
- # You will need to use the entire symbol for the name of the switches and
- # groups in the script calls, meaning you will need that ":" sign at the start!
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To turn ON/OFF a custom switch, you can use the following script call:
- #
- # set_custom_sw(:name,value)
- #
- # :name = The name of your custom switch.
- # value = Can be either true or false.
- # If true, the switch will be turned ON.
- # If false, the switch will be turned OFF.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To turn ON/OFF a custom group, you can use the following script call:
- #
- # set_custom_group_sw(:name,value)
- #
- # :name = The name of your group.
- # value = Can be either true or false.
- # If true, all of the switches from the group will be turned ON.
- # If false, all of the switches from the group will be turned OFF.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To toggle ON/OFF a custom switch, you can use the following script call:
- #
- # toggle_custom_sw(:name)
- #
- # :name = The name of your custom switch.
- #
- # Depending on the current state of the switch, this script call will either
- # turn ON or turn OFF the switch. If the switch is turned ON, it will be turned
- # OFF, and if the switch is turned OFF, it will be turned ON.
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To toggle ON/OFF a custom group, you can use the following script call:
- #
- # toggle_custom_group_sw(:name)
- #
- # :name = The name of your group.
- #
- # Depending on the current states of the switches in the group, this script
- # call will either turn them ON or turn them OFF.
- # If a switch from the group is turned ON, after the script call it will be
- # turned OFF, and if a switch is turned OFF, it will be turned ON.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To check the state of a custom switch, you can use the following script call
- # in a conditional branch (using the script method on the last page):
- #
- # check_custom_sw(:name,value)
- #
- # :name = The name of your custom switch.
- # value = The state of the switch you want to check for.
- # If you use true, and if the checked switch is turned ON, this
- # conditional check will return true.
- # If you use false, and if the checked switch is turned OFF, this
- # conditional check will return true.
- # In all other cases, the check returns false.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To check the state of a custom group, you can use the following script call
- # in a conditional branch (using the script method on the last page):
- #
- # check_custom_group_sw(:name,value)
- #
- # :name = The name of your custom group.
- # value = The state of the group you want to check for.
- # If you use true, and if all of the switches from the checked group
- # are turned ON, the conditional check will return true.
- # If you use false, and if all of the switches from the checked group
- # are turned OFF, the conditional check will return true.
- # In all other cases, the check returns false.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * Some examples:
- # (NOTE: The examples are using the sample switches and groups set up in the
- # script initially to present some exact practical examples.)
- #
- # set_custom_sw(:test3,true)
- # Turns the switch named :test3 ON.
- #
- # set_custom_group_sw(:grupy1,false)
- # Turns all of the switches from the group named :grupy1 OFF.
- #
- # toggle_custom_sw(:test4)
- # Toggles the switch named :test4.
- # If it was turned ON, it will be turned OFF.
- # If it was turned OFF, it will be turned ON.
- #
- # toggle_custom_group_sw(:grupy3)
- # Toggles all of the switches from the group named :grupy3.
- # All of the switches turned ON from the group will be turned OFF.
- # All of the switches turned OFF from the group will be turned ON.
- #
- # check_custom_sw(:test2,true)
- # Checks if the switch named :test2 is turned ON or not.
- # If it is, it returns true, if it is not, it returns false.
- # Use it in a conditional branch with the script method!
- #
- # check_custom_group_sw(:grupy4,false)
- # Checks if the switches from the group named :grupy4 are turned OFF or not.
- # If all of them are, it returns true, if not all of them, it returns false.
- # Use it in a conditional branch with the script method!
- #-------------------------------------------------------------------------------
- # * < Installation >
- #-------------------------------------------------------------------------------
- # * Place this script below Materials but above Main!
- #-------------------------------------------------------------------------------
- # * < Compatibility Info >
- #-------------------------------------------------------------------------------
- # * No known incompatibilities.
- #-------------------------------------------------------------------------------
- # * < Known Issues >
- #-------------------------------------------------------------------------------
- # * No known issues.
- #-------------------------------------------------------------------------------
- # * < Terms of Use >
- #-------------------------------------------------------------------------------
- # * Free to use for whatever purposes you want.
- # * Credit me (Sixth) in your game, pretty please! :P
- # * Posting modified versions of this script is allowed as long as you notice me
- # about it with a link to it!
- #===============================================================================
- $imported = {} if $imported.nil?
- $imported["SixthCustomSwitches"] = true
- #===============================================================================
- # Settings:
- #===============================================================================
- module Sixth_Custom_Switch
- #-----------------------------------------------------------------------------
- # Custom Switch Settings:
- #-----------------------------------------------------------------------------
- # This is the place where you can set your custom switches up.
- # You can use any name for them, but there is one rule:
- # You must use a ":" sign at the start of every switch name!
- # You can make unlimited amounts of switches.
- # Remember to separate them with commas at the end of each line or after each
- # switch setup!
- #
- # Switch setup format:
- # :name => value,
- # The :name is the name of the switch.
- # You can not make the same name for a switch and for a group!
- # The value is the state of the switch.
- # If it is set to true, the switch will be turned ON at game startup.
- # If it is set to false, the switch will be turned OFF at game startup.
- #-----------------------------------------------------------------------------
- Single_Switches = { # <-- No touchy-touchy!
- :bomb_puzzle => false,
- :arrow_puzzle => false,
- :test1 => false,
- :test2 => false,
- :test3 => false,
- :test4 => false,
- } # <-- No touchy-touchy!
- #-----------------------------------------------------------------------------
- # Custom Group Settings:
- #-----------------------------------------------------------------------------
- # This is the place where you can set your groups up.
- # Groups are used to make batch operations and page requirements with your
- # custom switches.
- # Any switch assigned to the group will be affected by the group script calls.
- # All of them will be checked for the page requirements when using groups.
- # Remember to separate them with commas at the end of each line or after each
- # group setup!
- #
- # Group setup format:
- # :name => [:switch1, :switch2, switch3, ..., switchn],
- # The :name is the name of the group, same format as for the switches.
- # You can use any name for your groups as long as they don't have the same name
- # as your switches. Keep this in mind!
- # The :switchx is the name of the switch assigned to the group.
- # You can have unlimited amount of switches assigned to your groups.
- #-----------------------------------------------------------------------------
- Group_Switches = { # <-- No touchy-touchy!
- :grupy1 => [:test1,:test2],
- :grupy2 => [:test2,:test3],
- :grupy3 => [:test1,:test2,:test3],
- :grupy4 => [:test1,:test2,:test3,:test4],
- :grupy5 => [:test3,:test4],
- } # <-- No touchy-touchy!
- end # <-- No touchy-touchy!
- #===============================================================================
- # End of Settings! Editing anything below may lead to... you know it, right?
- #===============================================================================
- # Managing data (initialize/save/load).
- module DataManager
- class << self
- alias sixth_cw_create_objects create_game_objects
- alias sixth_cw_save_contents make_save_contents
- alias sixth_cw_extract_contents extract_save_contents
- end
- def self.create_game_objects
- sixth_cw_create_objects
- $custom_sw = Game_Custom_Switches.new
- end
- def self.make_save_contents
- contents = sixth_cw_save_contents
- contents[:custom_switches] = $custom_sw
- contents
- end
- def self.extract_save_contents(contents)
- sixth_cw_extract_contents(contents)
- $custom_sw = contents[:custom_switches]
- end
- end
- # Initializing all custom switches.
- class Game_Custom_Switches
- attr_accessor :id
- def initialize
- @id = {}
- init_custom_switches
- end
- def init_custom_switches
- Sixth_Custom_Switch::Single_Switches.each do |switch,value|
- @id[switch] = value
- end
- end
- end
- class Game_Event < Game_Character
- # Adding custom switch page requirements.
- alias sixth_custom_switches1223 conditions_met?
- def conditions_met?(page)
- return false if get_them_custom_switch_req(page) == false
- sixth_custom_switches1223(page)
- end
- # Checking for custom switch page requirements.
- def get_them_custom_switch_req(page)
- return true if page.list.nil? || page.list.size <= 0
- page.list.each do |cmd|
- next unless cmd.code == 108 || cmd.code == 408
- if cmd.parameters[0] =~ /<single_sw_req: (.*), (.*)>/i
- data = $2 == "true" ? true : false
- return false if check_for_single_sw_req($1.to_sym,data) == false
- elsif cmd.parameters[0] =~ /<group_sw_req: (.*), (.*)>/i
- data = $2 == "true" ? true : false
- return false if check_for_group_sw_req($1.to_sym,data) == false
- elsif cmd.parameters[0] =~ /<custom_sw_req: (.*[ ].*(?:\s*,\s*.*[ ].*)*)>/i
- $1.split(", ").each do |info|
- info =~ /(.*) (.*)/i
- data = $2 == "true" ? true : false
- if $custom_sw.id.include?($1.to_sym)
- return false if check_for_single_sw_req($1.to_sym,data) == false
- else
- return false if check_for_group_sw_req($1.to_sym,data) == false
- end
- end
- end
- end
- return true
- end
- # Checking for single switch page requirements.
- def check_for_single_sw_req(sym,data)
- return false if $custom_sw.id[sym] != data
- return true
- end
- # Checking for group page requirements.
- def check_for_group_sw_req(sym,data)
- Sixth_Custom_Switch::Group_Switches[sym].each do |switch|
- return false if $custom_sw.id[switch] != data
- end
- return true
- end
- end
- class Game_Interpreter
- # Setting a single switch.
- def set_custom_sw(sym,data)
- $custom_sw.id[sym] = data
- $game_map.need_refresh = true
- end
- # Checking for a single swicth.
- def check_custom_sw(sym,data)
- return true if $custom_sw.id[sym] == data
- return false
- end
- # Setting a group.
- def set_custom_group_sw(sym,data)
- Sixth_Custom_Switch::Group_Switches[sym].each do |switch|
- $custom_sw.id[switch] = data
- end
- $game_map.need_refresh = true
- end
- # Checking for a group.
- def check_custom_group_sw(sym,data)
- Sixth_Custom_Switch::Group_Switches[sym].each do |switch|
- return false if $custom_sw.id[switch] != data
- end
- return true
- end
- # Toggle single switch.
- def toggle_custom_sw(sym)
- $custom_sw.id[sym] = !$custom_sw.id[sym]
- $game_map.need_refresh = true
- end
- # Toggle a group.
- def toggle_custom_group_sw(sym)
- Sixth_Custom_Switch::Group_Switches[sym].each do |switch|
- $custom_sw.id[switch] = !$custom_sw.id[switch]
- end
- $game_map.need_refresh = true
- end
- end
- #==============================================================================
- # !!END OF SCRIPT - OHH, NOES!!
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement