DasMoony 11 Posted January 18, 2012 (edited) Loosing some words about first: When I started to mess aroudn with new weapons and other stuff I had to find out that I need add them for example to the $data_weapons array. If I want to have run everything fine I also noticed that I would have to save the $data_weapons back to Weapons.rvdata2. Everything no problem and all except that it ends up in a real pain for me as developer. Everytime a project is saved are the *.rvdata2 files set back to the original ones without my modifications of course. Now I made this script to address these issues and since I guess I'm not the only one who will gets troubled by this I decided also to share it Features: â— Provides an array $xdata to add customized items â— Provides another rvdata2 File for storing these manipulations â— Plug & Play - no configuration needed at all. â— Gives the items automatically a fitting ID. â— Very High compatibility How to use Follow the instrcutions in the script. To use the script do not edit $data_weapons, $data_armors or any other $data_* array. Use $xdata instead. Also please note, that $xdata contains only items you have added. So $xdata[10] will most likely NOT be your $data_weapon[10]. Also this time I commented every single method in a hopefully exemplary manner. So I recommend to look over the script for best usage of it It also provides a very useful method: $xdata.get_data(obj) - calling this will return you the corresponding $data_* array for items,actors,etc. If you still have any questions left, feel free to ask. Known Problems Uh... if you don't want the XData.rvdata2 in the main folder it's easy to achieve that:(Around line 104): $xdata = DMO::XDATA.new("anyfolder/filename") But make sure to use a folder that won't get encrypted... Script #============================================================================== #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # â– DMO - XDATA # â— Version: 1.1 # â— Author: DasMoony # â— Date: January 18th, 2012 # â— Credits: DasMoony # â— LastEdit: January 18th, 2012 # #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # â– Features (or 5 reasons why to use this one): # â— Provides an array $xdata to add customized items # â— Provides another rvdata2 File for storing these manipulations # â— Plug & Play - no configuration needed at all. # â— Gives the items automatically a fitting ID. # â— High compatibility (aliases only DataManager.init) # #============================================================================== # â– Description # You may have discovered that any manipulations to any of the $data_ arrays # usually won't save. If you found out how you could save them you will most # likely run in the next problem: As soon as you save your project you'll # discard your manipulations again. # With this script you have not to worry any longer about these problems. # It creates a single File where it saves all these manipulations, merges # them automatically at the game start and also takes care of the ID-naming. # #============================================================================== # â– Credits and Terms of use # â— Credits: # DasMoony # â— This script is made for free use in commercial and non-commercial # projects but credits are required # â— Do not post direct links to the download file, instead link the page that # contains it # â— You're not allowed without the authors permission to distribute this # script. Of course you're allowed to distribute the script within your # project. # â— If you're allowed to distribute the script you can't require any rights # about the script # â— If this script is used in commercial projects, I demand a free copy of # it. Contact me for the details. # #============================================================================== # â– Instructions # â— Plug the script in # Put this script to the Materials-Section. # â— Configurations # There are no configurations needed. # â— How to use # Instead adding something to any $data_* array use $xdata. # (Example: instead of $data_weapons.push(weapon) us $xdata.push(weapon). # There are several methods within the XDATA-Object you are supposed to # work with. Check technical aspects for a list of them. # Your manipulated objects will be saved everytime you save a game. # #============================================================================== # â– FAQ # â— No questions yet # #============================================================================== # â– Support # â— Currently this script is supported on rpgmakervxace.net # #============================================================================== # â– Technical Aspects (this section is thought for other scripters) # â— aliases # â— DataManager # â— init # â— save_game # â— New methods # â— DMO::XDATA # â— initialize([name]) Initialize # â— load Loads Data # â— save Saves Data # â— check_file Check if File exists # â— get_data(object) returns corresponding $data_* array of object # â— push_to_data(object) pushes object to $data_* # do NOT use this one since it won't save # use push(object) instead! # â— [](id) Like Array # â— []=(id,value) Like Array # â— push(object) Like Array # use this to add something # â— clear Like Array # â— delete(object) Like Array # â— reset_ids(data) Resets all ID's of a $data_* array # â— include?(object) Like Array # â— index(object) Like Array # #============================================================================== # â– Contact Information # â— Email: # sid.dasmoony@gmail.com # #============================================================================== #============================================================================== #============================================================================== # â– DataManager #============================================================================== module DataManager class << self alias dmo_al_init init def init dmo_al_init $xdata = DMO::XDATA.new end alias dmo_al_save_game save_game def save_game(index) ret = dmo_al_save_game(index) $xdata.save if ret return ret end end end #============================================================================== # â– XDATA - Expanded Data for Database #============================================================================== module DMO #============================================================================== # â– XDATA - Class # Provides the methods to handle additional *.rvdata2's merging with the # known ones # Also takes care for the objects IDs #============================================================================== class XDATA #------------------------------------------------------------------------ # â— initialize # Initializes the XDATA-Object. # (path : path of the *.rvdata - without the extension) #------------------------------------------------------------------------ def initialize(path="XData") @data = [] @name = path load end #------------------------------------------------------------------------ # â— load # Loads XData-Object and merges the data with the corresponding. # $data_* #------------------------------------------------------------------------ def load return unless check_file xdata = load_data("#{@name}.rvdata2") xdata.each{|obj| push(obj) } end #------------------------------------------------------------------------ # â— save # Saves the XData-Object. #------------------------------------------------------------------------ def save File.open("#{@name}.rvdata2","wb") do |file| Marshal.dump(@data,file) end end #------------------------------------------------------------------------ # â— check_file # Checks if there is already a file to load. #------------------------------------------------------------------------ def check_file return FileTest.exists?("#{@name}.rvdata2") end #------------------------------------------------------------------------ # â— get_data # Returns the corresponding $data_* of the object. # obj : object #------------------------------------------------------------------------ def get_data(obj) return $data_weapons if obj.is_a?(RPG::Weapon) return $data_armors if obj.is_a?(RPG::Armor) return $data_items if obj.is_a?(RPG::Item) return $data_actors if obj.is_a?(RPG::Actor) return $data_skills if obj.is_a?(RPG::Skill) return $data_classes if obj.is_a?(RPG::Class) return $data_enemies if obj.is_a?(RPG::Enemy) return $data_troops if obj.is_a?(RPG::Troop) return $data_states if obj.is_a?(RPG::State) return $data_animations if obj.is_a?(RPG::Animation) return $data_tilesets if obj.is_a?(RPG::Tileset) return $data_common_events if obj.is_a?(RPG::CommonEvent) return nil end #------------------------------------------------------------------------ # â— push_to_data # Pushes the object to @data as to the $data_*. # Please note that a object added this way will not save! Use # push(object) instead. # obj : object #------------------------------------------------------------------------ def push_to_data(obj) obj.id = get_data(obj).size get_data(obj).push(obj) end #------------------------------------------------------------------------ # â— [] # Object at @data[id]. # id : id #------------------------------------------------------------------------ def [](id) @data[id] end #------------------------------------------------------------------------ # â— []= # Sets object at @data[id] to obj. # Calls push if id is not existent yet. # id : id # obj : object #------------------------------------------------------------------------ def []=(id,obj) if id >= @data.size push(obj) else get_data(obj)[obj.id] = obj @data[id] = obj end end #------------------------------------------------------------------------ # â— push # Pushes the object to the XDATA-Object and to $data_* # obj : object #------------------------------------------------------------------------ def push(obj) @data.push(obj) push_to_data(obj) end #------------------------------------------------------------------------ # â— clear # Clears all objects in the XDATA-Object out of XDATA and $data_* # obj : object #------------------------------------------------------------------------ def clear @data.each{|obj| get_data(obj).delete(obj) } @data = [] end #------------------------------------------------------------------------ # â— delete # Deletes all object. Calls reset_ids afterwards. # obj : object #------------------------------------------------------------------------ def delete(obj) @data.delete(obj) get_data(obj).delete(obj) reset_ids(get_data(obj)) end #------------------------------------------------------------------------ # â— reset_ids # Reset IDs of $data_* # data : $data_* #------------------------------------------------------------------------ def reset_ids(data) i = 0 data.each{|obj| obj.id = i i+= 1 } end #------------------------------------------------------------------------ # â— include? # Does @data include object? # obj : object #------------------------------------------------------------------------ def include?(obj) return @data.include?(obj) end #------------------------------------------------------------------------ # â— index # Index of object in @data # obj : object #------------------------------------------------------------------------ def index(obj) return @data.index(obj) end end end Credits & Terms of use â— Credits: DasMoony â— This script is made for free use in commercial and non-commercial projects but credits are required â— Do not post direct links to the download file, instead link the page that contains it â— You're not allowed without the authors permission to distribute this script. Of course you're allowed to distribute the script within your project. â— If you're allowed to distribute the script you can't require any rights about the script â— If this script is used in commercial projects, I demand a free copy of it. Contact me for the details. For this, look at contact informations or send me a pm on the forum About Support, Redistribution, etc. This is what this thread is for At the moment this script is exclusive shared at rpgmakervxace.net and that's my full intention until I set up a script section on my own homepage. So, if you see it somewhereelse please inform me. Thanks in advance for this. Updates â— Removed auto_save feature after each manipulation. Please use a at least script version 1.1 to avoid 'data corpses'. â— The current version will save the manipulations when you save a game. You still can save manually with the save-method. Future Intentions to this Script The scripts runs fine at the time and I'm happy about that. If you find any bugs or encounter any problems, I'd be happy for your hint. Rather to have concrete intentions to this itself I may update some of my others script with the options to use this one. Edited January 18, 2012 by DasMoony Share this post Link to post Share on other sites