Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

More Self-Switches

More Self-Switches
Authors: game_guy
Version: 1.2
Type: Event Modification
Key Term: Environment Add-on


Introduction

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

Screenshots

switch.png

Demo

http://decisive-media.net/gameguy/switches.exe

Script

XP Version
Ruby:
 

#===============================================================================

# More Self-Switches

# Version 1.2

# 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

#

# 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.

# You also need the Self-Switch box on the page checked.

#

# -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

#

# Compatibility:

# Not tested with SDK.

# Should work with anything.

#

# Credits:

# game_guy ~ For creating it.

#===============================================================================

 

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

    }}

  end

  def check_custom_switch(page, code)

    a = code.split(':')

    if a[0].downcase == "switch" && a[1] != nil

      page.condition.self_switch_ch = a[1]  

    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

 

VX Version - Believe it or not, there was only one line difference to get it to work.
Ruby:
#===============================================================================

# More Self-Switches (VX Version)

# Version 1.0

# 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

#

# 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.

# You also need the Self-Switch box on the page checked.

#

# -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

#

# Compatibility:

# Not tested with SDK.

# Should work with anything.

#

# Credits:

# game_guy ~ For creating it.

#===============================================================================

 

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

    }}

  end

  def check_custom_switch(page, code)

    a = code.split(':')

    if a[0].downcase == "switch" && a[1] != nil

      page.condition.self_switch_ch = a[1]  

    end

  end

end

 

class Game_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

Instructions

In the script.
Place above main, below Scene_Debug, the normal.

Compatibility

Not tested with SDK.
Should work with anything.

Credits and Thanks

game_guy ~ For creating it.

Author's Notes

Enjoy! :)
 
Added a VX version. Essentially it already worked with VX, however, the interpreter class was named different in VX, so I had to change one line. But thats it. xD
 
Useful stuff!

A different approach you could also try is using self-variables. This way, you could still use the preset editor Conditions by creating one global variable that's used for all self-variables. You would still be able to set, alter (add, subtract, etc.) for use in puzzles and the like, but it would only apply to a single event.
 
Well, there you go.
Yours is still a great idea, though. The comment system allows you to even name your self-switches if you need to, that's pretty cool.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top