09-16-2009, 10:20 AM
PK8's Self Variables XP
Version: 1
Version: 1
Introduction
This script is pretty similar to that of the built in feature: Self Switches. For those not familiar with Self Switches, Self Switches pretty much pertain to a specific event. Example: Treasure Chests.
Self Variables allows users to set certain variables pertaining to a specific event. Examples include: An event's feelings towards you.
Features
- Set self variables of an event via call script.
- Get self variables of an event via call script.
Screenshots
How can I screenshot this?
Demo
No demo.
Script
Code:
=begin
?????????????????????????????????????????????????????????????????????????????????
? PK8's Self Variables ?
? Version 1.0 ?
? by PK8 ?
? 9/16/09 ?
? http://rmvxp.com ?
?????????????????????????????????????????????????????????????????????????????????
? ? Table of Contents ?
? ?? Author's Notes - Line 18?21 ?
? ?? Introduction & Description - Line 23?29 ?
? ?? Features - Line 31?33 ?
? ?? How to Use - Line 35?59 ?
? ?? This aliases the following... - Line 61?64 ?
? ?? Thanks - Line 66?71 ?
? ?? Changelog - Line 73,74 ?
????????????????????????????????????????????????????????????????????????????????
? ? Author's Notes ?
? Lowell/Adalwulf mentioned creating a "Personal Variables" system which filled?
? my head in with ideas about variables and switches. One of these ideas being ?
? self variables. ?
?????????????????????????????????????????????????????????????????????????????????
? ? Introduction & Description ?
? This script is pretty similar to that of the built in feature: Self Switches.?
? For those not familiar with Self Switches, Self Switches pretty much pertain ?
? to a specific event. Example: Treasure Chests. ?
? ?
? Self Variables allows users to set certain variables pertaining to a specific?
? event. Examples include: An event's feelings towards you. ?
?????????????????????????????????????????????????????????????????????????????????
? ? Features ?
? ? Set self variables of an event via call script. (How to use is below) ?
? ? Get self variables of an event via call script. (How to use is below) ?
????????????????????????????????????????????????????????????????????????????????
? ? How to Use ?
? ?
? ? Setting up a self variable: ?
? To set a self variable for an event, you'll need to call this script on a ?
? map event: ?
? self_variable(id, value, oper) ?
? id: Self Variable Identification. Example: 'feeling' ?
? value: Give it a value. ?
? oper: 0: Set, 1: Add, 2: Sub, 3: Mul, 4: Div, 5: Mod ?
? ?
? ? Getting a self variable: ?
? To get a self variable for an event, you can call this script. ?
? self_variable(id) ?
? id: Self Variable Identification. ?
? ?
? ? Using self variables in evented if conditions. ?
? You're probably wondering how, right? Alright. To do this, go to the ?
? conditional branch event command, click on the fourth tab, select Script ?
? and type either of these in the input form: ?
? self_variable(id) == value <- Equal to. ?
? self_variable(id) >= value <- Greater than or Equal to. ?
? self_variable(id) <= value <- Less than or Equal to. ?
? self_variable(id) > value <- Greater than. ?
? self_variable(id) < value <- Less than. ?
? self_variable(id) != value <- Not Equal to. ?
????????????????????????????????????????????????????????????????????????????????
? ? This aliases the following... ?
? command_new_game - Scene_Title ?
? write_save_data - Scene_Save < Scene_File ?
? read_save_data - Scene_Load < Scene_File ?
????????????????????????????????????????????????????????????????????????????????
? ? Thanks ?
? Lowell: He mentioned creating a personal variables system for his project ?
? (I think), which made me catch "the scripting bug". ?
? Decibel: Wanted some way to get self variables into messages but I couldn't ?
? do it. Someone, help! ?
? Kain Nobel: He helped me with making this an RMXP script. ?
????????????????????????????????????????????????????????????????????????????????
? ? Changelog ?
? Version 1.0 - 9/16/09: Initial Release ?
?????????????????????????????????????????????????????????????????????????????????
=end
#==============================================================================
# ** Game_SelfVariables
#------------------------------------------------------------------------------
# This class handles self variables. It's a wrapper for the built-in class
# "Hash." The instance of this class is referenced by $game_self_variables.
#==============================================================================
class Game_SelfVariables
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = {}
end
#--------------------------------------------------------------------------
# * Get Self Switch
# key : key
#--------------------------------------------------------------------------
def [](key)
if @data[key] == nil
return 0
else
return @data[key]
end
end
#--------------------------------------------------------------------------
# * Set Self Switch
# key : key
# value : key's value
#--------------------------------------------------------------------------
def []=(key, value)
@data[key] = value
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
def self_variable(id, value = nil, oper = nil)
if @event_id > 0
key = [@map_id, @event_id, id]
if value != nil
case oper
when nil, 0, 'equal', 'set', '=' # Setting
$game_self_variables[key] = value
when 1, 'add', '+' # Adding
$game_self_variables[key] += value
when 2, 'sub', 'subtract', '-' # Subtracting
$game_self_variables[key] -= value
when 3, 'mul', 'multiply', 'x', '*' # Multiplying
$game_self_variables[key] *= value
when 4, 'div', 'divide', '/' # Dividing
$game_self_variables[key] /= value if value != 0
when 5, 'mod', 'modular', '%' # Modulating
$game_self_variables[key] %= value if value != 0
end
else
return $game_self_variables[key]
end
if value != nil
$game_map.need_refresh = true
return true
end
end
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs the title screen processing.
#==============================================================================
class Scene_Title
alias pk8_self_variables_command_new_game :command_new_game
#--------------------------------------------------------------------------
# * Create Game Objects
#--------------------------------------------------------------------------
def command_new_game
pk8_self_variables_command_new_game
$game_self_variables = Game_SelfVariables.new
end
end
#==============================================================================
# ** Scene_Save
#------------------------------------------------------------------------------
# This class performs save screen processing.
#==============================================================================
class Scene_Save < Scene_File
alias pk8_self_variables_write_save_data :write_save_data
#--------------------------------------------------------------------------
# * Write Save Data
# file : write file object (opened)
#--------------------------------------------------------------------------
def write_save_data(file)
pk8_self_variables_write_save_data(file)
Marshal.dump($game_self_variables, file)
end
end
#==============================================================================
# ** Scene_Load
#------------------------------------------------------------------------------
# This class performs load screen processing.
#==============================================================================
class Scene_Load < Scene_File
alias pk8_self_variables_read_save_data :read_save_data
#--------------------------------------------------------------------------
# * Read Save Data
# file : file object for reading (opened)
#--------------------------------------------------------------------------
def read_save_data(file)
pk8_self_variables_read_save_data(file)
$game_self_variables = Marshal.load(file)
end
end
Instructions
How to use is in the instructions.
FAQ
No questions asked so far...
Compatibility
It aliases the following methods from the following classes:
- command_new_game - Scene_Title
- write_save_data - Scene_Save < Scene_File
- read_save_data - Scene_Load < Scene_File
Thanks
Lowell: He mentioned creating a personal variables system for his project (I think), which made me catch "the scripting bug".
Decibel: Wanted some way to get self variables into messages but I couldn't do it. Someone, help!
Kain Nobel: He helped me with making this an RMXP script.
Author's Notes
Lowell/Adalwulf mentioned creating a "Personal Variables" system which filled my head in with ideas about variables and switches. One of these ideas being self variables.
Terms and Conditions
Possibly an RMVXP exclusive.