![]() |
Item System
3 Attachment(s)
Included Classes: functions_items (credits to me), functions_cached_database (credits to DrakilorP2P)
Included Database NPC's: ItemCache (credits to me & DrakilorP2P) Disclaimer: While the addItem() function might mention quantity's, I never got around actually implementing them, so they currently don't exist. Notes: Join functions_items to players in onActionPlayerOnline(). Purpose of system? To provide servers with an easy to use, flexible, powerful and most importantly a secure way of handling items. How does it work? All items are stored in .arc files (yes, laugh away Chris and Inverness) which are just normal .txt files with a fancy extension. Doesn't matter which you use, I use it just because it's what I've been used to for years. The system loads the players .arc data into player.items which is a serversided TStaticVar placeholder for the items, so that you don't have to read their data directly from the .arc files everytime you need it. It's automatically updated whenever a players data changes. If you're implementing an inventory with this system, you'll have to make it grab the data from serverside to clientside ONCE and store it in a this. variable clientsided (see the function triggerToClient() in functions_items class to see how I did it). The moveItem() function is currently calling it on both sender and retriever to refresh the clientsided data every time an item is moved to/from a TServerPlayer object. But what about item creation and 'trading'? You never answer that in How does it work! You're right, I didn't, since it was cluttered enough as it is, but at least now I got your attention right? addItem(id, quantity, obj) - Adds the item with the item id of 'id' from 'obj' to the current object. Simply put anyways, however it's not that easy. First it makes sure that 'obj' isn't nothing at all, and if it is, it sets it to ItemCache which is where ALL items appear when created. That's right, an item must physically exist on 'obj' before they can be added. After that it checks to ensure that 'obj' isn't itself, and if so, aborts. If the item exists, it'll be moved - more on that soon. itemExists(id, obj) - Checks if the item physically exists on 'obj' and returns true/false according to those results. moveItem(id, from, to) - Moves the actual item from 'from' to 'to' - which is set to the current object if NULL. This function also updates the .arc data, and triggers triggerToClient() to refresh clientsided data. But dude, I wanna know how to create items! Yeah yeah, I get it. It's rather simple, just trigger the createItem(arc, [itemname]) function! If 'arc' is a valid arc name, the item will be created and put on the ItemCache database NPC for safekeeping until it's grabbed. When that's done, it triggers ItemCache's saveItem(obj) function (obj equals the actual temp.item TStaticVar). Item's have a constantly increasing variable as id if the .arc have uniqueID set to true, otherwise it uses it's item name as id. Common ways of doing it: PHP Code:
PHP Code:
That's really all you have to know to be able to use/alter the functions. Now to the final part - arc creation. For that, you'll have to manually edit the database NPC ItemCache whenever you want to make a new one. I'll go over a few of it's basic vars first though. this.directory - Folder name of saved .arc files. Defaults to levels/MUDLIB/archtypes/ this.subfolders - Optional. Turn it into an array of subfolders if you'd prefer using that. this.newEntryFunction - Name of the function handling new entries. Check the debugArcCreation() function to see how you actually create the .arc files and set their data. What rights do I need to give my NPC-Server? PHP Code:
I more then likely missed a couple of things, but just ask if there's anything you're curious about. I don't mind anyone using or altering it, but if anyone asks you about it, please redirect them to this thread. If you do use it, please, do tell :), and if you alter it don't be shy to show your modifications or additions! |
Very interesting system you got there, I must say.
It's very well done and I like the way you're synchronizing data between client and server. Requires a bit of experience with objects to handle the system though, but that isn't a bad thing. I also like the cache system. Well done ;) |
I was impressed the first time you showed it to me. It's a very very nice system, I wish I had time to script something to replicate it because it looks so fun to script.
|
Very nice, good job!
|
Very nice my friend, although I'd say I enjoy the RPG system I'm planning more, this is very awesome!
|
Thanks guys. :)
Quote:
|
Quote:
|
Nice script. Open source is win.
Quote:
By the way, I have a few notes after looking through the script. First, if the npc name is ItemCache then you can simply use ItemCache.varname rather than findnpc("ItemCache").varname. Second, would be a bit more efficient to check if an object is existing by using varname.type() == 2 rather than varname.objecttype() == "TStaticVar". Third, Stefan made it so you can use var = {} rather than var = new[0] |
Quote:
Quote:
|
Quote:
|
Quote:
|
Quote:
|
posting something I wrote without asking first? :o theft!
lol j/k jsut kiddin. ^^ Quote:
Quote:
|
Quote:
I personally believe Stefan shouldn't have added var = {}; - it's quite bad style. |
Quote:
Quote:
|
| All times are GMT +2. The time now is 08:11 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.