Advertisement
LiTTleDRAgo

[RGSS/2/3] Advanced Game Variables

Jan 29th, 2012
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.90 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # [Xp/Vx/Vx-A] Advanced Game Variables
  3. # Version: 1.01
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. #
  7. # Example use :
  8. #
  9. # You can use it as usual
  10. #
  11. #  $game_variables[1] = 1
  12. #  $game_variables[1] += 45
  13. #
  14. # Or you can use it as self variable
  15. #
  16. #  $game_variables[[@map_id,@event_id,"A"]] = 1
  17. #  $game_variables[[@map_id,@event_id,"B"]] = "LiTTleDRAgo"
  18. #
  19. # You can also use it like this
  20. #
  21. #  $game_variables[["Number of cats"]] = 108
  22. #  $game_variables[["Name of the cat 1"]] = "Meong"
  23. #  $game_variables[["Owner of the cats"]] = $game_actors[1].name.to_s
  24. #
  25. # Etc
  26. #
  27. # Enjoy~
  28. #
  29. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  30. #==============================================================================
  31. # ** Game_Variables
  32. #------------------------------------------------------------------------------
  33. #  This class handles variables. It's a wrapper for the built-in class "Array."
  34. #  Refer to "$game_variables" for the instance of this class.
  35. #==============================================================================
  36.  
  37. class Game_Variables
  38.   #--------------------------------------------------------------------------
  39.   # * Get Variable
  40.   #--------------------------------------------------------------------------
  41.   def [](id)
  42.     (id.is_a?(Integer) ? @data : (@data_ex||={}))[id] || 0
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # * Set Variable
  46.   #--------------------------------------------------------------------------
  47.   def []=(id, val)
  48.     (id.is_a?(Integer) ? @data : (@data_ex||={}))[id] = on_change && val
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● On change
  52.   #--------------------------------------------------------------------------
  53.   def on_change
  54.     $game_map ? $game_map.need_refresh = true : true
  55.   end
  56. end
  57.  
  58. #==============================================================================
  59. # ** Self Variable Interpreter
  60. #------------------------------------------------------------------------------
  61. # This class handles the translation of $game_self_variables into an array
  62. # so that any individual event can treat its own self_variables as such.  It's
  63. # pretends to be an Array, so far as the interaction requires.
  64. #==============================================================================
  65.  
  66. class SelfVarInterpreter
  67.   #---------------------------------------------------------------------------
  68.   # * Data
  69.   #---------------------------------------------------------------------------
  70.   define_method(:initialize){|mid,eid| @key = [mid,eid]}
  71.   define_method(:"[]")      {|vid| $game_variables[[@key[0],@key[1],vid]]}
  72.   define_method(:"[]=") {|vid,val| $game_variables[[@key[0],@key[1],vid]] = val}
  73. end
  74.  
  75. #==============================================================================
  76. # ** Interpreter
  77. #------------------------------------------------------------------------------
  78. #  This interpreter runs event commands. This class is used within the
  79. #  Game_System class and the Game_Event class.
  80. #==============================================================================
  81. Klass = defined?(Window_ActorCommand) ? Game_Interpreter : Interpreter
  82. class Klass
  83.   #--------------------------------------------------------------------------
  84.   # ● Alias Listing
  85.   #--------------------------------------------------------------------------
  86.   alias_sec_method :ds_svar_setup,  :setup
  87.   #---------------------------------------------------------------------------
  88.   # * Setup
  89.   #---------------------------------------------------------------------------
  90.   def setup(*args)
  91.     ds_svar_setup(*args)
  92.     @self_variables = SelfVarInterpreter.new(@map_id, @event_id)
  93.   end
  94. end
  95.  
  96. $drago_game_variable = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement