Global Switches and Variables for RMX-OS
Authors: Blizzard
Version: 1.3
Type: RMX-OS plugin
Key Term: RMX-OS Plugin
IntroductionThis script will allow to have global switches and variables on your server.
This script is to be distributed under the same terms and conditions like the script it was created for: RMX-OS.
Features
- easy to configure
- controls a certain set of switches globallly
- controls a certain set of variables globallly
ScreenshotsN/A for this sort of script.
DemoN/A
ScriptJust make a new script above main and paste this code into it.
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Global Switches and Variables for RMX-OS by Blizzard
# Version: 1.3
# Type: RMX-OS Add-on
# Date: 7.1.2010
# Date v1.01: 22.2.2010
# Date v1.1: 11.2.2011
# Date v1.2: 22.1.2013
# Date v1.21: 30.3.2013
# Date v1.3: 12.6.2013
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# This script is to be distributed under the same terms and conditions like
# the script it was created for: RMX-OS.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# Information:
#
# This script must be placed below RMX-OS and requires RMX-OS to work
# properly. This script will allow to have global switches and variables on
# your server.
#
#
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
if !defined?(RMXOS) || RMXOS::VERSION < 2.0
raise 'ERROR: The "Global Switches and Variables" requires RMX-OS 2.0 or higher.'
end
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
GLOBAL_SWITCHES = [1, 2] # make sure this matches the extension configuration
GLOBAL_VARIABLES = [1, 2] # make sure this matches the extension configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$rmxos_gswivars = 1.3
#==============================================================================
# Game_Temp
#==============================================================================
class Game_Temp
attr_accessor :disable_global
end
#==============================================================================
# Game_Switches
#==============================================================================
class Game_Switches
alias set_gswivar_later []=
def []=(id, value)
if !$game_temp.disable_global && GLOBAL_SWITCHES.include?(id)
$network.send_switch(id, value)
else
set_gswivar_later(id, value)
end
end
end
#==============================================================================
# Game_Switches
#==============================================================================
class Game_Variables
alias set_gswivar_later []=
def []=(id, value)
if !$game_temp.disable_global && GLOBAL_VARIABLES.include?(id)
$network.send_variable(id, value)
else
set_gswivar_later(id, value)
end
end
end
#==============================================================================
# RMXOS::Network
#==============================================================================
class RMXOS::Network
alias check_game_gswivar_later check_game
def check_game(message)
case message
when /\AGSWI\t(.+)\t(.+)/
$game_temp.disable_global = true
$game_switches[$1.to_i] = ($2 != '0')
$game_temp.disable_global = false
$game_map.need_refresh = true
return true
when /\AGVAR\t(.+)\t(.+)/
$game_temp.disable_global = true
$game_variables[$1.to_i] = $2.to_i
$game_temp.disable_global = false
$game_map.need_refresh = true
return true
end
return check_game_gswivar_later(message)
end
alias check_loading_gswivar_later check_loading
def check_loading(message)
result = check_loading_gswivar_later(message)
if result
if @messages.include?(RMXOS::LOADING_END)
@messages.delete(RMXOS::LOADING_END)
self.send('LGDAT')
end
else
case message
when /\ALGSWI\t(.+)/ # load global switches
hash = eval($1)
$game_temp.disable_global = true
hash.each_key {|id| $game_switches[id] = hash[id]}
$game_temp.disable_global = false
return true
when /\ALGVAR\t(.+)/ # load global variables
hash = eval($1)
$game_temp.disable_global = true
hash.each_key {|id| $game_variables[id] = hash[id]}
$game_temp.disable_global = false
$game_map.need_refresh = true
@messages.push(RMXOS::LOADING_END)
return true
end
end
return result
end
def send_switch(id, value)
self.send('GSWI', id, value ? 1 : 0)
end
def send_variable(id, value)
self.send('GVAR', id, value)
end
end
Make a new file with an
.rb extension in the
Extensions folder of RMX-OS and copy-paste this script into it.
module RMXOS
def self.load_current_extension
return GlobalSwitchesVariables
end
module Data
GlobalSwitchChange = 'Client \'CLIENT\' changed switch \'ID\' to \'STATE\'.'
GlobalVariableChange = 'Client \'CLIENT\' changed variable \'ID\' to \'STATE\'.'
end
end
#======================================================================
# module GlobalSwitchesVariables
#======================================================================
module GlobalSwitchesVariables
VERSION = 1.3
RMXOS_VERSION = 2.0
SERVER_THREAD = false
IDENTIFIER = 'Global Switches and Variables'
# START Configuration
GLOBAL_SWITCHES = [1, 2] # make sure this matches the configuration in the client
GLOBAL_VARIABLES = [1, 2] # make sure this matches the configuration in the client
SWITCHES_FILENAME = './gswitches.dat' # filename for global switch saving
VARIABLES_FILENAME = './gvariables.dat' # filename for global variable saving
SERVER_DISPLAY = true # show log in command prompt screen
LOG_FILENAME = './logs/gswivar.log' # leave empty if no log file should be created
DELETE_LOG_ON_START = false
# END Configuration
def self.initialize
@mutex = Mutex.new
@switches = {}
GLOBAL_SWITCHES.each {|id| @switches[id] = false}
if FileTest.exist?(SWITCHES_FILENAME)
file = File.open(SWITCHES_FILENAME, 'r')
ids = Marshal.load(file)
file.close
(ids & GLOBAL_SWITCHES).each {|id| @switches[id] = true}
end
@variables = {}
GLOBAL_VARIABLES.each {|id| @variables[id] = 0}
if FileTest.exist?(VARIABLES_FILENAME)
file = File.open(VARIABLES_FILENAME, 'r')
hash = Marshal.load(file)
file.close
(hash.keys & GLOBAL_VARIABLES).each {|id| @variables[id] = hash[id]}
end
if LOG_FILENAME != ''
File.delete(LOG_FILENAME) if DELETE_LOG_ON_START && FileTest.exist?(LOG_FILENAME)
RMXOS::Logs[IDENTIFIER] = LOG_FILENAME
end
end
def self.mutex
return @mutex
end
def self.main
while RMXOS.server.running
@mutex.synchronize {
self.server_update
}
sleep(0.1)
end
end
def self.server_update
end
def self.client_update(client)
case client.message
when /\ALGDAT\Z/ # load global data
client.send('LGSWI', @switches.inspect.sub(' ', ''))
client.send('LGVAR', @variables.inspect.sub(' ', ''))
return true
when /\AGSWI\t(.+)\t(.+)/ # global switch change
id = $1.to_i
value = ($2 != '0')
@switches[id] = value
self.save_switches
client.sender.send_to_all(client.message, true)
message = RMXOS::Data.args(RMXOS::Data::GlobalSwitchChange, {'CLIENT' => client.player.username, 'ID' => id.to_s, 'STATE' => value.to_s})
self.log(message)
return true
when /\AGVAR\t(.+)\t(.+)/ # global variable change
id = $1.to_i
value = $2.to_i
@variables[id] = value
self.save_variables
client.sender.send_to_all(client.message, true)
message = RMXOS::Data.args(RMXOS::Data::GlobalVariableChange, {'CLIENT' => client.player.username, 'ID' => id.to_s, 'STATE' => value.to_s})
self.log(message)
return true
end
return false
end
def self.save_switches
ids = @switches.keys.find_all {|id| @switches[id]}
file = File.open(SWITCHES_FILENAME, 'w')
Marshal.dump(ids, file)
file.close
end
def self.save_variables
hash = {}
@variables.each_key {|id| hash[id] = @variables[id] if @variables[id] != 0}
file = File.open(VARIABLES_FILENAME, 'w')
Marshal.dump(hash, file)
file.close
end
def self.log(message)
puts message if SERVER_DISPLAY
RMXOS.log('Log', IDENTIFIER, message)
end
end
InstructionsIn the script in the first comment.
CompatibilityRequires RMX-OS to work.
Credits and Thanks
Author's NotesIf you find any bugs, please report them here:
http://forum.chaos-project.comThat's it! N-Joy! =D