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:
temp.item = createItem(arc);
addItem(temp.item);
PHP Code:
addItem(createItem(arc));
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:
rw levels/MUDLIB/archtypes/*.arc
rw levels/MUDLIB/archtypes/*/*.arc
rw levels/MUDLIB/itemdb/*.arc
rw levels/MUDLIB/itemdb/*/*.arc
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!