![]() |
How would you do this?
I am going to attempt at making this work. However I am rather bad at coding. I want to start a weapon system but am pretty lost in how it should be done. I am aware of the basic db setup. Every item should work differently so I know I can't use a list of variables to be sent to a master system.
So all items should have 1 thing in common , if they are primary(s key, right hand) and secondary(a key,left hand). Each item works differently then the next. Also each item can "upgrade". A shield would become stronger, sword would grow bigger/stronger. A hammer would gain the ability to break new things. Boomerang would go farther and so one. When one item is being used the other one should be disabled for that time. Now onto the Question, What would you guys, the forum suggest for this? At the moment I'm thinking having every item its own weapon script with its way of working. How that would work , I have no clue. I'm not looking for any direct help or handouts, as that would just be lame of me :P. Just merely pointers on how i should handle this. Suggestions on the best ways to preform this are greatly appreciated. -Killa Be |
There are some methods which you could take a look at instead of having each item having it's own weapon script.
Using method 2 you only need filebrowser to edit, create and remove items. This could be good for staff who don't need NC or doesn't know how to script to make adjustments to items. Should only be handles by trusted persons or a System Administrator or something of that kind. :) 1) You have a database with all the data for each item. Within this DB you create an API to include retrieving the wanted information. Something like this could work (Basic idea though) PHP Code:
I would suggest joining a class to the player. Then you access the player object by using this.var, this.function() etc player.join("itemcontrol"); <- Do this on login in Control-NPC PHP Code:
|
2)
This method includes having a textfile for each item These textfiles you want to store under the levels/ somewhere. I'll state why later. Let's choose the folder: levels/itemdata You'll probably also need to add levels/itemdata/*.txt into folder config. It's also possible to use the file prefix .arc, but this is personal preference as they are in the end, both text files. It's also possible to use .ini files, then I suggest you lookup some of Inverness' scripts in the code gallery. I will not cover that though :p In each textfile for each item you want to use a setup like this: NPC Code: This is because you can load all of the data needed by using obj.loadvars() If you saved the above file as bigsword.txt you could do: PHP Code:
Here it would be better to use TStaticVar's to store the item data Not using TStaticVar would mean extra work and opens for errors when going file -> array PHP Code:
PHP Code:
Now, the reason you want all of your text files into levels/ is because of this one event which allows you to create automatic updating of itemcache when editing files! PHP Code:
If the examples are a bit tough to follow, just give me a PM and I'll look into simplifying them :) This is just an idea of how you can do it using files and a DBNPC! :) (It's also possible to use a WNPC to cache items, just saying!) All the scripts I have written from the top of my head, so look at it as "gs2 psuedocode" :v I have not tested the scripts and they are not finished ones. The Database scripts could probably work if pasted, but these two methods are just to give you an idea of how to do it. |
What about 'enchanting' and creating dynamic items? or would you have to make all the items ahead of time and just replace the current one with the enchanted one. I've made multiple item systems but this has always baffled me.
|
Quote:
Take a look at the script I made further down on the page :cool: when storing what items the player has, store the enchant together with the BASE of the item, and parse the item with the given enchant when the player logs on etc |
What about creating random stats? I've always wondered that too?
|
Then you edit the TStaticVar of the item afterwards to add the random stats. Since these random stats are not part of the base item, you need to store these variables together with their random values somewhere along with the base of the item, and then handle it from there.
Basically the system I described in the posts above handles the base of items. If you want to alter it, you do it to the TStaticVar afterwards and store the changes as well as the base of the item. Then when you login you retrieve the base of the item and then parse the custom variables into the TStaticVar. Then you eventually synchronize the items into clientr. strings or objects on the clientside so clientside scripts like inventories can access the parsed item data. This is why TStaticVar's are more superior to arrays when you want something more flexible. |
I totally forgot about a method involving SQL -> Script
Thanks to Deas for pointing out. This is for the more advanced users though. If I recall there are documentation of how to do this already out there though, use the search function! I might write a small guide for SQL -> Script later :) List of threads which can be helpful for the more advanced users: http://forums.graalonline.com/forums...ad.php?t=76567 http://forums.graalonline.com/forums...ad.php?t=73396 http://forums.graalonline.com/forums...ad.php?t=81961 http://forums.graalonline.com/forums...ad.php?t=74162 AND FOR ALL YOU SCRIPTERS OUT THERE; DO NOT USE THE TERM MUDLIB FOR ITEM SYSTEMS http://forums.graalonline.com/forums...ad.php?t=80450 EDIT; If you're interested in using SQL, I suggest reading over these forum threads, there are probably more out there, but didn't bother to search more with this rediculous waiting time on searches. http://forums.graalonline.com/forums...hp?t=134256362 http://forums.graalonline.com/forums...ad.php?t=86173 |
alright chompy and cubical , I don't think I explained the way this should act well enought , but this does give me a general idea.
|
Quote:
|
| All times are GMT +2. The time now is 07:35 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.