Common Event Self Variables XP
#1
Common Event Self Variables XP
Version: 1

Introduction
This script is a 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.

Common Event Self Variables allows developers to set certain variables pertaining to a certain Common Event.

Features
  • Set Common Event's self variables via call script.
  • Get Common Event's self variables via call script.

Screenshots
No screencap.

Demo
No demo.

Script
Code:
=begin
????????????????????????????????????????????????????????????????????????????????
? Common Event Self Variables XP                                               ?
? 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?62                                ?
? ?? This aliases the following... - Line 64,65                                ?
? ?? Thanks                        - Line 67?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 ?
? giving COMMON EVENTS their own self variables.                               ?
????????????????????????????????????????????????????????????????????????????????
? ? Introduction & Description                                                 ?
? This script is a 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.                               ?
?                                                                              ?
? Common Event Self Variables allows developers to set certain variables       ?
? pertaining to a certain Common Event.                                        ?
????????????????????????????????????????????????????????????????????????????????
? ? Features                                                                   ?
? ? Set Common Event's self variables via call script. (How to use is below)   ?
? ? Get Common Event's self variables via call script. (How to use is below)   ?
????????????????????????????????????????????????????????????????????????????????
? ? How to Use                                                                 ?
?                                                                              ?
? ? Setting up a Common Event's self variable:                                 ?
?   To set a self variable for a common event, you'll need to call this script:?
?     ce_self_variable(ceid, id, value, oper)                                  ?
?       ceid: Common Event's ID                                                ?
?       id:   Common Event's Self Variable ID. Example: 'A', 'B'               ?
?       value:  Give it a value.                                               ?
?       oper:   0: Set, 1: Add, 2: Sub, 3: Mul, 4: Div, 5: Mod                 ?
?   Example: ce_self_variable(1, 'A', 5, 0) sets the first Common Event's      ?
?            variable "A" to 5.                                                ?
?                                                                              ?
? ? Getting a Common Event's self variable:                                    ?
?   To get a self variable of a Common Event, you can call this script.        ?
?     ce_self_variable(ceid, id)                                               ?
?       ceid: Common Event's ID                                                ?
?       id:   Common Event's Self Variable ID. Example: 'A', 'B'               ?
?   Example: ce_self_variable(1, 'A') gets Common Event's variable "A".        ?
?                                                                              ?
? ? Using Common Event's self variable in evented if conditions.               ?
?   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:             ?
?       ce_self_variable(ceid, id) == value   <- Equal to.                     ?
?       ce_self_variable(ceid, id) >= value   <- Greater than or Equal to.     ?
?       ce_self_variable(ceid, id) <= value   <- Less than or Equal to.        ?
?       ce_self_variable(ceid, id) > value    <- Greater than.                 ?
?       ce_self_variable(ceid, id) < value    <- Less than.                    ?
?       ce_self_variable(ceid, id) != value   <- Not Equal to.                 ?
????????????????????????????????????????????????????????????????????????????????
? ? This aliases the following...                                              ?
? initialize - Game_Map                                                        ?
????????????????????????????????????????????????????????????????????????????????
? ? Thanks                                                                     ?
? Lowell: He mentioned creating a personal variables system for his project    ?
?         which made me catch "the scripting bug".                             ?
? Kain Nobel: I'm using Kain Nobel's modifications to the Actor & Party's Self ?
?             Switches script as a base.                                       ?
????????????????????????????????????????????????????????????????????????????????
? ? Changelog                                                                  ?
? Version 1.0 - 9/16/09: Initial Release                                       ?
????????????????????????????????????????????????????????????????????????????????
=end

#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#==============================================================================

class Game_Map
  attr_accessor :ce_self_variables
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :ceselfvariables_gmmap_initialize, :initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(*args)
    ceselfvariables_gmmap_initialize(*args)
    @ce_self_variables = Game_Map::CE_SelfVariables.new
  end
end

#==============================================================================
# ** Game_Map::CE_SelfVariables
#------------------------------------------------------------------------------
#  This handles variables. It's a wrapper for the built-in class "Array."
# The instance of this class is referenced by $game_map.ce_self_variables.
#==============================================================================

class Game_Map::CE_SelfVariables
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @data = {}
  end
  #--------------------------------------------------------------------------
  # * Get Self Variable of Common Event
  #     key : key
  #--------------------------------------------------------------------------
  def [](key)
    if @data[key] == nil
      return 0
    else
      return @data[key]
    end
  end
  #--------------------------------------------------------------------------
  # * Set Self Variable of Common Event
  #     key   : key
  #     value : 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
  #--------------------------------------------------------------------------
  # * Control Common Event Self variable
  #--------------------------------------------------------------------------
  def ce_self_variable(ceid, id, value = nil, oper = nil)
    if $data_common_events[ceid].id > 0 and $data_common_events[ceid] != nil
      key = [$data_common_events[ceid].id, id]
      if value != nil
        case oper
        when nil, 0, 'equal', 'set', '='                     # Setting
          $game_map.ce_self_variables[key] = value
        when 1, 'add', '+'                                   # Adding
          $game_map.ce_self_variables[key] += value
        when 2, 'sub', 'subtract', '-'                       # Subtracting
          $game_map.ce_self_variables[key] -= value
        when 3, 'mul', 'multiply', 'x', '*'                  # Multiplying
          $game_map.ce_self_variables[key] *= value
        when 4, 'div', 'divide', '/'                         # Dividing
          $game_map.ce_self_variables[key] /= value if value != 0
        when 5, 'mod', 'modular', '%'                        # Modulating
          $game_map.ce_self_variables[key] %= value if value != 0
        end
      else
        return $game_map.ce_self_variables[key]
      end
    end
    $game_map.need_refresh = true
    return true
  end
end

Instructions
Instructions on how to use it is in the script.

FAQ
Awaiting question.

Compatibility
Aliases initialize of Game_Map.

Credits and Thanks
Lowell: He mentioned creating a personal variables system for his project which made me catch "the scripting bug".
Kain Nobel: I'm using Kain Nobel's modifications to the Actor & Party's Self Switches script as a base.

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 giving COMMON EVENTS their own self variables.

Terms and Conditions
Exclusive to RMVXP?
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   ATOA CBS Equipment Set Variables Patch kyonides 0 179 10-14-2024, 12:47 AM
Last Post: kyonides
   Event Spawner Fixes DerVVulfman 8 16,945 01-02-2018, 05:48 AM
Last Post: DerVVulfman
   SDK DVV Add-On: Event Comment Supplemental DerVVulfman 5 11,814 09-25-2016, 09:20 PM
Last Post: DerVVulfman
   ELSA (Event Layering Script Advance) JayRay 0 5,983 02-25-2015, 04:15 AM
Last Post: JayRay
   Permanent Event Erase DerVVulfman 2 6,203 04-09-2013, 03:53 AM
Last Post: DerVVulfman
   Event Transparency DerVVulfman 5 11,896 03-09-2013, 05:42 AM
Last Post: DuongCool
   [Unsupported] PK8's Self Variables XP PK8 4 10,365 03-08-2012, 01:54 PM
Last Post: LilyKnight
   Call Map Event DerVVulfman 0 5,327 12-06-2011, 04:42 AM
Last Post: DerVVulfman
   Skills That Use Variables DerVVulfman 2 7,329 01-06-2010, 09:44 AM
Last Post: Queue
   Group Variables v1.1 PK8 1 6,748 11-12-2009, 05:35 AM
Last Post: earthboy



Users browsing this thread: 1 Guest(s)