Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Permanent Switches & Variables v. 1.2
- # VX Ace version
- # by mikb89
- # Dettagli:
- # Questo script permette di memorizzare determinate switch e variabili in un
- # file a parte, facendo sì che i loro valori rimangano gli stessi per ogni
- # nuova partita e caricamento.
- # Utile per esempio se si vuole aggiungere un Nuovo gioco +, cambiando una
- # switch appena finito il gioco, oppure un sistema di punteggio alto tramite
- # variabile o magari per memorizzare delle opzioni.
- # Configurazioni:
- module PERMASV
- PERMANENT_SWITCHES = [1...10, 20]
- PERMANENT_VARIABLES = [50..10]
- # Elencare le switch e variabili che si vogliono conservare.
- # È possibile separare i valori con virgole (1, 2, 30) oppure scegliere un
- # range di valori multipli usando due o tre puntini:
- # 1...10 -> (3 puntini) prende tutti i valori da 1 a 9;
- # 50..100 -> (2 puntini) prende tutti i valori da 50 a 100.
- # Come mostrato sopra i tre metodi sono combinabili fra loro ^^
- FILE_NAME = "Data.rvdata2"
- # Qui il nome del file salvato con switch e variabili permanenti.
- # Mantenendo l'estensione .rvdata2, si confonderà di più con gli altri file
- # di salvataggio.
- # Attenti a non mettere Save nel nome perché altrimenti lo considererà come
- # un salvataggio normale e abiliterà il comando Continua dal menu anche se
- # non sono effettivamente presenti salvataggi tradizionali.
- end
- #Codename: permasv
- ($imported ||= {})[:mikb89_permasv] = true
- # License:
- # - You can ask me to include support for other scripts as long as these scripts
- # use the $imported[script] = true;
- # - You can modify and even repost my scripts, after having received a response
- # by me. For reposting it, anyway, you must have done heavy edit or porting,
- # you can't do a post with the script as is;
- # - You can use my scripts for whatever you want, from free to open to
- # commercial games. I'd appreciate by the way if you let me know about what
- # you're doing;
- # - You must credit me, if you use this script or part of it.
- module DataManager
- def self.save_permasv
- File.open(PERMASV::FILE_NAME, "wb") do |file|
- Marshal.dump(make_save_permasv, file)
- end
- end
- def self.load_permasv
- begin
- File.open(PERMASV::FILE_NAME, "rb") do |file|
- extract_save_permasv(Marshal.load(file))
- end
- rescue
- end
- end
- def self.make_save_permasv
- cont = {}
- for sw in PERMASV::PERMANENT_SWITCHES
- cont["s#{sw}".to_sym] = $game_switches[sw]
- end
- for va in PERMASV::PERMANENT_VARIABLES
- cont["v#{va}".to_sym] = $game_variables[va]
- end
- return cont
- end
- def self.extract_save_permasv(cont)
- for sw in PERMASV::PERMANENT_SWITCHES
- $game_switches[sw] = (cont["s#{sw}".to_sym] rescue false)
- end
- for va in PERMASV::PERMANENT_VARIABLES
- $game_variables[va] = (cont["v#{va}".to_sym] rescue 0)
- end
- end
- end
- class Game_Switches
- alias_method(:getS_b4_permasv, :[]) unless method_defined?(:getS_b4_permasv)
- alias_method(:setS_b4_permasv, :[]=) unless method_defined?(:setS_b4_permasv)
- def [](switch_id)
- DataManager.load_permasv
- getS_b4_permasv(switch_id)
- end
- def []=(switch_id, value)
- setS_b4_permasv(switch_id, value)
- DataManager.save_permasv
- end
- end
- class Game_Variables
- alias_method(:getV_b4_permasv, :[]) unless method_defined?(:getV_b4_permasv)
- alias_method(:setV_b4_permasv, :[]=) unless method_defined?(:setV_b4_permasv)
- def [](variable_id)
- DataManager.load_permasv
- getV_b4_permasv(variable_id)
- end
- def []=(variable_id, value)
- setV_b4_permasv(variable_id, value)
- DataManager.save_permasv
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement