[Unsupported] PK8's Self Variables XP
#1
PK8's Self Variables XP
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.
Reply }


Messages In This Thread
[Unsupported] PK8's Self Variables XP - by PK8 - 09-16-2009, 10:20 AM
RE: PK8's Self Variables XP - by LilyKnight - 03-07-2012, 10:21 PM
RE: PK8's Self Variables XP - by DerVVulfman - 03-08-2012, 04:42 AM
RE: PK8's Self Variables XP - by LilyKnight - 03-08-2012, 01:54 PM
PK8's Self Variables XP - by Yin - 09-16-2009, 08:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
   ATOA CBS Equipment Set Variables Patch kyonides 0 200 10-14-2024, 12:47 AM
Last Post: kyonides
   [Unsupported] Title Skip 2 XP PK8 3 9,436 02-17-2010, 12:01 PM
Last Post: Villain
   Skills That Use Variables DerVVulfman 2 7,369 01-06-2010, 09:44 AM
Last Post: Queue
   Group Variables v1.1 PK8 1 6,771 11-12-2009, 05:35 AM
Last Post: earthboy
   Common Event Self Variables XP PK8 0 874 09-17-2009, 04:57 AM
Last Post: PK8
   Actor & Party's Self Variables XP PK8 0 910 09-17-2009, 01:47 AM
Last Post: PK8
   [Unsupported] Actor & Party's Self Switches XP PK8 3 8,812 09-17-2009, 01:46 AM
Last Post: Yin
   [Unsupported] Title Skip 1 PK8 2 6,961 09-15-2009, 10:44 PM
Last Post: DerVVulfman
   [Unsupported] Force Save Before New Game PK8 0 4,910 12-07-2008, 04:44 PM
Last Post: PK8
   [Unsupported] MapSwitch! XP PK8 0 4,886 12-07-2008, 04:39 PM
Last Post: PK8



Users browsing this thread: 2 Guest(s)