Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- #
- # HERETIC's AUTO STATE SWITCHES [XP/VX/VXA]
- # Version 1.0x
- # * edited by LiTTleDRAgo
- # Tuesday, October 1st, 2013
- #
- #==============================================================================
- #
- # *** YOU MUST EDIT THE CONFIG BEFORE USING THIS SCRIPT ***
- #
- # This Script will allow Game Switches to be changed Automatically when a
- # State is applied to ANY Member of the Party.
- #
- # *** IMPORTANT ***
- #
- # Once you set a Game Switch ID, do not try to alter that Switch in any
- # other way. The Switch is controlled Automatically by the Script and
- # is not checked frequently. The Script only checks when a State is Added
- # or Removed, or when the Game Party is Refreshed to have minimal impact
- # on compatability and performance.
- #
- # When any Actor in the Party has a specific State, the corresponding Game
- # Switch will be Enabled. If none of the Actors in the Party have a specified
- # State, the corresponding Game Switch is set to False / Off.
- #
- # This is all done with State IDs and Switch IDs. These might be a big
- # confusing, but the Database and Editor do just fine at telling you
- # what the ID's are. So dont use Names. I also didnt put in any
- # Error Checking so if you mess up your Config, you'll have to figure
- # it out for yourself. The Defaults in the Script correspond to a Demo
- # so you MUST CHANGE the Values. I tried to pick High Numbers to not
- # cause any conflits in your Game.
- #
- # --- USES ---
- #
- # This is Useful for altering the Behavior of NPCs. You might use this
- # to have Townsfolk say Different Things. If you have Enemy NPC Events
- # this is useful for altering their Behavior by adding additional Pages
- # to those Enemy Events. Game Switches are used specifically because
- # of the Effects they have on Events and Pages.
- #
- # --- OPTIONS ---
- #
- # Enabled: In case you want or need to disable the effects of this script.
- # change with $game_system.state_switches.enabled = true / false
- #
- # Movable: If you want to allow Dead Actors to affect the Game Switches
- # change with $game_system.state_switches.movable = true / false
- #
- # List: Alters the List of State IDs and Switch IDs. Not commonly needed.
- # change with $game_system.state_switches.list = [ [state_id, switch_id] ]
- #
- #==============================================================================
- #==============================================================================
- # *** CONFIG *** (Default Values)
- #==============================================================================
- class State_Switches_Config
- # Change the List around HERE as needed. Defaults, can be changed later.
- LIST = [ [35,140],[36,141] ]
- # [35,140] - State ID 35 (Drunk), Game Switch ID 140
- # [36,140] - State ID 36 (Infected), Game Switch ID 141
- # If Actors MUST BE ALIVE for Effects
- MOVABLE = true
- end
- #==============================================================================
- # ** State Switches for Game_System Object
- #
- # These can ALL be Edited on the fly with $game_system.state_switches
- # - Enabled: Whether to Change Switches or not
- # - List: List of State ID's and Corresponding Game Switch IDs
- # - Movable: If Actor MUST BE ALIVE for Effect to be recognized
- #==============================================================================
- class State_Switches
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :enabled # Enable to allow Auto Changing Game Switches
- attr_accessor :list # List of State and Switches to Change
- attr_accessor :movable # Require Actors to be Alive to Change
- #--------------------------------------------------------------------------
- # * Object Initialization - Uses Config for Default Values
- #--------------------------------------------------------------------------
- def initialize
- # DO NOT EDIT HERE
- @enabled = true
- @movable = State_Switches_Config::MOVABLE
- end
- #--------------------------------------------------------------------------
- # * List of State and Switches to Change
- #--------------------------------------------------------------------------
- def list
- @list || State_Switches_Config::LIST
- end
- end
- #==============================================================================
- # ** Game_System
- #==============================================================================
- class Game_System
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_writer :state_switches # Enable to allow Auto Changing Switces
- #--------------------------------------------------------------------------
- # * Game System Initialization
- # - Add @state_switches as Object for Settings
- # - Access and change with $game_system.state_switches.property =
- #--------------------------------------------------------------------------
- def state_switches
- # Object holds State Switches
- @state_switches ||= State_Switches.new
- end
- end
- #==============================================================================
- # ** Game_Party
- #==============================================================================
- class Game_Party
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- unless method_defined?(:auto_state_refresh)
- method_defined?(:members) || (alias_method :members, :actors)
- method_defined?(:refresh) && (alias_method :auto_state_refresh, :refresh)
- end
- #--------------------------------------------------------------------------
- # * Check Auto State Switches
- #--------------------------------------------------------------------------
- def check_auto_state_switches
- # If Auto Changing Switches is Enabled
- if $game_system.state_switches.enabled
- # Check for State ID for Switch Disabling
- for state_switch in $game_system.state_switches.list
- # Get Values
- state, switch = *state_switch
- # Get Config
- require_movable = $game_system.state_switches.movable
- # Result of each Actors having this State
- actor_has_state = members.compact.any? do |actor|
- # If somehow states id is not an integer
- states = actor.states.collect {|s| s.is_a?(Integer) ? s : s.id }
- # If Actor not Dead and Actor has this State
- states.include?(state) and
- (not require_movable or (require_movable and actor.movable?))
- end
- # if switch is Integer and State of Switch not same as Actors having State
- if switch.is_a?(Integer) and actor_has_state != $game_switches[switch]
- # Change the Auto Game Switches to match Value
- $game_switches[switch] = actor_has_state
- # Refresh the Map and all Events accordingly
- $game_map.need_refresh = true
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Refresh Party Members
- #--------------------------------------------------------------------------
- if method_defined?(:refresh)
- def refresh
- # Call Original or Other Aliases
- auto_state_refresh
- # Check for Switch Changes
- check_auto_state_switches
- end
- end
- end
- #==============================================================================
- # ** Game_Battler
- #==============================================================================
- class Game_Battler
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- unless method_defined?(:auto_state_switches_add_state)
- alias_method :auto_state_switches_add_state, :add_state
- alias_method :auto_state_switches_remove_state, :remove_state
- end
- #--------------------------------------------------------------------------
- # * Add State
- # state_id : state ID
- # force : forcefully added flag (used to deal with auto state)
- #--------------------------------------------------------------------------
- def add_state(*args)
- # Call Original or Other Aliases
- auto_state_switches_add_state(*args)
- # Get scene class
- scene = defined?(SceneManager) ? SceneManager.scene : $scene
- # If scene is not Scene_Title (to avoid stack error)
- unless scene.nil? or scene.is_a?(Scene_Title)
- # Check for State Self Switch Changes if Game_Actor
- $game_party.check_auto_state_switches if self.is_a?(Game_Actor)
- end
- end
- #--------------------------------------------------------------------------
- # * Remove State
- # state_id : state ID
- # force : forcefully removed flag (used to deal with auto state)
- #--------------------------------------------------------------------------
- def remove_state(*args)
- # Call Original or Other Aliases
- auto_state_switches_remove_state(*args)
- # If Game Actor
- if self.is_a?(Game_Actor)
- # Check for State Self Switch Changes
- $game_party.check_auto_state_switches
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement