Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ============================================================================
- # EVENT SELF VARIABLES
- # AUTHOR : TheoAllen ~
- # Contact : www.rpgmakerid.com
- # ============================================================================
- $imported = {} if $imported.nil?
- $imported[:THEO_EventVariable] = true
- # ============================================================================
- =begin
- PENGENALAN :
- Script ini memberikan fitur tiap event punya individual variable sendiri
- PENGGUNAAN :
- Panggil dalam script call :
- - variables[index] = angka >> contoh pengesetan. index bisa berapa aja
- - variables[index] > angka >> contoh dalam conditional branch
- Untuk pemanggilan jarak jauh, gunakan script call kek gini
- array = [map_id,event_id]
- variables(array)[index] >> terusin ndiri
- BONUS FEATURE :
- ~ Self-switch
- Panggil >> variables["A"] = true << untuk ganti self_switch A
- TERMS OF SERVICES :
- - Kamu boleh edit dan redistribusi dengan versi editanmu sendiri. Hanya saja
- kamu harus tetap tulis credit ke gw "TheoAllen".
- - Penggunaan untuk komersil terserah. Tapi gwa lebih suka kalo dikasi
- gratisan projectnya ~
- - Semisal ada error gara2 u edit2 sendiri. Gw ga tanggung jawab :v
- =end
- # =============================================================================
- # ♫ Module DataManager ~ ♫
- # =============================================================================
- module DataManager
- #--------------------------------------------------------------------------
- # ♫ Aliasing lists
- #--------------------------------------------------------------------------
- class << self
- alias ama_create_game_obj create_game_objects
- alias ama_save_contents make_save_contents
- alias ama_load_contents extract_save_contents
- end
- #--------------------------------------------------------------------------
- # ♫ Bikin object $game_self_variables
- #--------------------------------------------------------------------------
- def self.create_game_objects
- ama_create_game_obj
- $game_self_variables = Game_SelfVariables.new
- end
- #--------------------------------------------------------------------------
- # ♫ Bikin save contents. Masukin $game_self_variables
- #--------------------------------------------------------------------------
- def self.make_save_contents
- contents = ama_save_contents
- contents[:selfvariable] = $game_self_variables
- contents
- end
- #--------------------------------------------------------------------------
- # ♫ Ngeload save contents. Termasuk $game_self_variables
- #--------------------------------------------------------------------------
- def self.extract_save_contents(contents)
- ama_load_contents(contents)
- $game_self_variables = contents[:selfvariable]
- end
- end
- # =============================================================================
- # ♫ Game Variable Hashes ~ ♫
- # =-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- # NOTE :
- # Class ini yang ngurus penyimpanan data-data dan semacemnya beserta indexnya.
- # Class ini berada sebagai value dari object Game_SelfVariable
- # =-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- # - def link_to_self_switch >> update nilai self switch
- # - def [](key) >> dapetin nilai
- # - def []=(key,value) >> ngubah nilai
- # - def on_change(key,value) >> refresh kalo berubah
- # - def self_switch >> refers ke $game_self_switches
- # =============================================================================
- class Game_VariableHashes
- attr_reader :event_key
- #--------------------------------------------------------------------------
- # ♫ Inisialisasi
- #--------------------------------------------------------------------------
- def initialize(event_key)
- @data = {}
- @event_key = event_key
- end
- #--------------------------------------------------------------------------
- # ♫ Refresh nilai self switch
- #--------------------------------------------------------------------------
- def link_to_self_switches
- @data["A"] = self_switches[event_key + ["A"]]
- @data["B"] = self_switches[event_key + ["B"]]
- @data["C"] = self_switches[event_key + ["C"]]
- @data["D"] = self_switches[event_key + ["D"]]
- end
- #--------------------------------------------------------------------------
- # ♫ Buat dapetin nilai
- #--------------------------------------------------------------------------
- def [](key)
- link_to_self_switches
- @data[key] = 0 if @data[key].nil?
- @data[key]
- end
- #--------------------------------------------------------------------------
- # ♫ Buat ngeset nilai
- #--------------------------------------------------------------------------
- def []=(key,value)
- @data[key] = value
- on_change(key)
- end
- #--------------------------------------------------------------------------
- # ♫ Refresh kalo berubah
- #--------------------------------------------------------------------------
- def on_change(key)
- if key.class == String
- value = @data[key]
- check1 = (key == "A" || key == "B" || key == "C" || key == "D")
- check2 = (value.class == TrueClass || value.class == FalseClass)
- return unless check1 && check2
- switch_key = event_key + [key]
- self_switches[switch_key] = value
- else
- link_to_self_switches
- $game_map.need_refresh = true
- end
- end
- #--------------------------------------------------------------------------
- # ♫ Ngambil self switch
- #--------------------------------------------------------------------------
- def self_switches
- $game_self_switches
- end
- #--------------------------------------------------------------------------
- # ♫ End
- #--------------------------------------------------------------------------
- end
- # =============================================================================
- # ♫ Game Self Variable ~ ♫
- # =-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- # NOTE :
- # Class ini gunanya buat nentuin alamat tempat variable-variable disimpen
- # Misalnya kek {[map_id,event_id] => {[1] => 3}} (Hash)
- # =============================================================================
- class Game_SelfVariables
- def initialize
- @data = {}
- end
- def [](key)
- @data[key] = Game_VariableHashes.new(key) if @data[key].nil?
- @data[key]
- end
- end
- # =============================================================================
- # ♫ Game Map ~ ♫
- # - def id >> Get map ID
- # =============================================================================
- class Game_Map
- def id
- @map_id
- end
- end
- # =============================================================================
- # ♫ Game Interpreter ~ ♫
- # - def event_key >> ngambil array yg isinya [map_id, event_id]
- # - def variable >> refers ke $game_self_variables (return Hash)
- # =============================================================================
- class Game_Interpreter
- def event_key
- [$game_map.id,event_id]
- end
- def variables(key = event_key)
- return variables[event_key] unless key.class == Array
- return variables[event_key] unless key.size == 2
- $game_self_variables[key]
- end
- end
- # =============================================================================
- #
- # ♫ End of Script ♫
- #
- # =============================================================================
Advertisement
Add Comment
Please, Sign In to add comment