Tsukihime 1,489 Posted May 18, 2012 (edited) Custom Database Author: Tsukihime Overview This script provides a set of methods that allow you to add new objects to the database and update existing objects in database. It abstracts all of the details for you and provides a set of simple-to-use methods for interacting with the database. The script uses a custom database to record any changes to the database in your current game, and is stored with the savefile so that any changes in one game does not affect any other game. The custom database only supports adding and updating at the moment. Download Get it at Hime Works Usage Creating objects A set of "add" methods have been provided for you in the script. Suppose you wanted to make a new weapon. It would look something like # create your weapon w = RPG::Weapon.new w.wtype_id = 1 w.params = [999] * 8 # make it overpowered # now add it to the database id = CustomData.add_weapon(w) # you can do something with the ID The general process is to create the RPG object, add it to the database, and then use that ID somewhere. Updating objects To update an object, you would call the appropriate `update` method provided by the script. For example, if you wanted to update a skill's MP cost, you might do something like # Updating skill 51 s = $data_skills[51] # change its mp cost s.mp_cost = 20 # now update the database CustomData.update_skill(s) Edited February 18, 2014 by Tsukihime 3 Share this post Link to post Share on other sites
Kodi123 5 Posted May 18, 2012 Well.. This looks pretty interesting and might come handy. Thank you very much for making these scripts. Seen your "Monster Hunter" Demo. Both of your scripts are awesome and hope to see more from you! Share this post Link to post Share on other sites
Syndicate 20 Posted May 18, 2012 Good stuff as always Tsuk! Share this post Link to post Share on other sites
Jun33 1 Posted January 3, 2013 Hi, one memeber said me that your script could help me but I didn't get why: My question : http://www.rpgmakervxace.net/topic/9610-solved-damage-skill-formula-access-and-saving/If I get it correctly, your script makes changes in the database and saves them in game, no? But, if I have two saves and in one I arribe a point where the skill formula is changed, then this change would affect to the other save also no? Share this post Link to post Share on other sites
Tsukihime 1,489 Posted January 4, 2013 (edited) No, the script does the opposite: only additions to the database are stored in custom data arrays and are stored in the save files. That means data from one save file does not affect data from another save file, despite using the same game data (the rvdata2 files in the data folder) It is basically an extension to the game's database. Edited January 4, 2013 by Tsukihime Share this post Link to post Share on other sites
Jun33 1 Posted January 4, 2013 Then, if it's an extension, to do the example that I said first I would need to do create a new skill that would be stored on that new database and I could use it freedomly; but I can't change the damage formula from the database directly because that information is not new, is not an extension and won't be save. I'm correct now? Share this post Link to post Share on other sites
Tsukihime 1,489 Posted January 4, 2013 Yes, the game's original database is never modified by the game, or should not be. Share this post Link to post Share on other sites
Tsukihime 1,489 Posted January 19, 2013 (edited) I have begun to make this script easier to use. The main focus is on encapsulation. The newest version provides a CustomData module with several methods that should make it easier to create new stuff. For example, suppose we wanted to make a new weapon. It would look like this w = RPG::Weapon.new w.wtype_id = 1 w.params = [999] * 8 # make it overpowered # now add it to the database id = CustomData.add_weapon(w) # you can do something with the ID Notice that all you needed to do was specify the object attributes, and then just add it to the database. Once you call the `add` method, it will return an ID. This is the database ID that the game assigns to you; you no longer need to manually calculate this yourself. At this point, you don't need to know anything about the database: you just need to tell the script to add your object and then it will give you the ID. I am thinking about the prospects of deleting an object from the database, or perhaps replacing...but those are questionable since you may have references to the "old" data which will screw up your game. So...for now you cannot delete stuff, you can only add stuff. This means your database may become arbitrarily large. Edited January 19, 2013 by Tsukihime Share this post Link to post Share on other sites
Kayzee 4,033 Posted January 19, 2013 I kind of think when it comes to items, that your FP Inventory Plus works better if you want to make lots of items with different instance variables. You know it might work better for the custom database if you assigned ID based on inventory slot. You can just overwrite the slot with nil or a new object. That would make it a lot easier to do stuff. Also remember, ruby's garbage collector works to automatically clean up objects that are not referenced anywhere, so you should have no problems if you nil a slot. Share this post Link to post Share on other sites
Tsukihime 1,489 Posted January 19, 2013 I think it is safer to just keep the object, because people might have scripts that reference objects by ID and then suddenly an object changes but the script still uses the same ID. Share this post Link to post Share on other sites
Kayzee 4,033 Posted January 19, 2013 Hmmm, maybe so... this is another reason I like Inventory Plus better I guess, but as far as compatibility goes that might be even worse in some ways... I am not sure. Ether way, it might be safer, but it's bound to cause problems in the long run. Share this post Link to post Share on other sites
Tsukihime 1,489 Posted January 19, 2013 (edited) The way I see it is that you have your database that contains all the data, and everything else simply asks for something by giving it an ID and the DB gives you something in return. If I were to change how the database works, then I would have to change how the default database works as well for consistency. Edited January 19, 2013 by Tsukihime Share this post Link to post Share on other sites
Kayzee 4,033 Posted January 20, 2013 And that is more or less why I like your Inventory Plus. It changes items to use a whole different structure, and using item IDs to refer to "prototype" objects instead. It obviously isn't a perfect solution compatibility wise, but it's probably the best way to do custom items. On the other hand, custom database would probably work better for enemies, actors, and other stuff, as long as you had a enumerable way to set IDs. Or really I guess I could say, if you have short lists that you don't really need to delete anything from. Items I think would flood the array much too quickly without a way to clean them up. Here is a thought, maybe you can erase unused items in the custom database only when saving the game? That might reduce the number of times you need to worry about being referenced somewhere unexpected. Share this post Link to post Share on other sites
HellKiteChaoS 36 Posted January 20, 2013 Added to the new Master Script List - Creator Tools. Share this post Link to post Share on other sites
eshra 53 Posted January 21, 2013 Here is a thought, maybe you can erase unused items in the custom database only when saving the game? That might reduce the number of times you need to worry about being referenced somewhere unexpected. How do you determine if an item is currently being used? How would I go about checking to see if there was an additional reference to a database object aside from the actual reference in the array? Sure I can check the inventory and each actor's equipment but someone else might have a reference to it somewhere else. Maybe I'm missing something idk. 1 Share this post Link to post Share on other sites
harvard1932 1 Posted January 23, 2013 how do you add your own icon to the new item? Share this post Link to post Share on other sites
Tsukihime 1,489 Posted January 23, 2013 how do you add your own icon to the new item? When you create your item, you would assign it an icon index (look it up in your icon manager) w = RPG::Weapon.new w.icon_index = 29 Share this post Link to post Share on other sites
Tsukihime 1,489 Posted January 25, 2013 (edited) I have added support for updating objects, and have also changed the script internally, so hopefully people are using the methods provided by the interface rather than accessing $custom data directly. Changes Previously, all custom data was stored as arrays similar to the original database. Now, custom data is stored in a hash, where the keys are object ID's and values are the objects themselves. This provides a one-to-one correspondence between the database array indices and the custom data. Two methods are provided by the script at the moment using the new design: Create (add). This creates a new entry in the hash (and array), assigning an ID to the object that you pass in. Update. This modifies an entry in the hash (and array), using the ID of the object that you pass in. A quick example of updating data: suppose you strengthened your weapon and its attack increased by 200. Oh, and the weapon now has a +1 attached to its name You would do something like def upgrade_weapon_attack(id) w = $data_weapons[id] w.name += " +1" w.params[2] += 200 CustomData.update_weapon(w) end This will update the entry in the Custom database, and also update the currently loaded database so that changes are reflected in real-time. As usual, the custom database is stored with the current save file, and will be merged upon loading. Edited January 25, 2013 by Tsukihime Share this post Link to post Share on other sites
Shadowfiend 0 Posted February 24, 2013 First off, let me say that I love your script, and it is exactly what I need. I'm trying to use your script for skill/spell making, and so far it works. A problem I ran into is that I don't know all of the "s.mp_cost" things. Is there a place that has all of these in it already for an example, like a script or something? Also, on the subject of skills/spells, how I change something that appears, in the database, in a drop menu, like "Skill Type"? Thank You. Share this post Link to post Share on other sites
Tsukihime 1,489 Posted February 24, 2013 In the help manual if you go to RGSS Reference Manual -> Game Library -> RPGVXAce data structures you will find all of the things you need. If you go to the Terms tab in the database you can add more data types. Share this post Link to post Share on other sites
Shadowfiend 0 Posted February 24, 2013 (edited) Thank you very much. How would I re-write the formula for a skill/spell? For example, if I want to change "150 + a.mat * 2 - b.mdf * 2" <== to this ==> "200 + a.mat * 9 - b.mdf * 3", just as an example. Also, are the lowercase letters (w = weapon, s = skill; example, w.params ) necessary in the script call? Edited February 24, 2013 by Shadowfiend Share this post Link to post Share on other sites
Tsukihime 1,489 Posted February 24, 2013 (edited) They are just variable names. The damage formula is stored in a RPG::UsableItem::Damage object as a string so you should be able to just directly access the damage object stored with the skill and change it. s = $data_skills[2] s.damage.formula = your_new_formula Or something. Edited February 24, 2013 by Tsukihime Share this post Link to post Share on other sites
Shadowfiend 0 Posted February 24, 2013 Alright...Thanks. I am using this ===> http://www.rpgmakervxace.net/topic/4238-simple-text-input/ so the player can input variables for the spells. I guess this is the question I wanted to ask, but, how would I use this Text Input script to change the formula to something else? Sorry for not getting to the point. Share this post Link to post Share on other sites
Tsukihime 1,489 Posted February 24, 2013 You will need to somehow get the input and figure out what to do with the input. I believe that script stores the player's input into a variable that you choose, so you can fetch the data from the variable. Share this post Link to post Share on other sites
Shadowfiend 0 Posted February 24, 2013 (edited) I know that much, but I tried it and got an error message. Script 'Window_SkillList' line 99: ArgumentError occured. comparison of String with 0 failed This is what I got for the error. Edited February 24, 2013 by Shadowfiend Share this post Link to post Share on other sites