[FilterScript] Inventory System Framework
#1


Made this ages ago. It's pretty much a textdraw inventory framework which is (to my knowledge) fully functionable. There are some quirks about it but I don't remember them. Either way I recall fixing every bug I've come across, so there shouldn't be many. This is pretty much finished. A list of features:

Code:
FEATURE LIST:
 - Inventory is entirely textdraw based. Pressing "H" will open it, and ESC or the "close" button will close it.
 - Inventory works in a flexible way, it's refreshed whenever you move a page / click a tile / etc to ensure all shown variables are up to date.
 - Items loaded from an array (id, item name, item object, and item type: equipable / usable / consumable / miscalleneous).
 - Items are loaded into preview model tiles which are dynamically loaded based on whether a item is valid or not.
 - You can have a maximum of 24 items (which is 2 full pages), and every page can have a maximum of 12 visible tiles.
 - Every item can be "examined". This is done by clicking on the preview tile. Based on an item's type, you will get different usage options.
 - Script consists 99% of custom functions, only SA-MP callbacks used are OnPlayerKeyStateChange and OnPlayerClickTextDraws.
Some information on how to add / remove inventory items:

In this script, I added inventory items in an array. Per player items use two player variables:

PHP Code:
new pInventoryItem         MAX_PLAYERS ] [ MAX_INV_ITEMS ]; // Item ID
new pInventoryItemQty     MAX_PLAYERS ] [ MAX_INV_ITEMS ]; // Item Quanity 
MAX_INV_ITEMS is used for the inventory slot. The item ID is stored in the variable itself. A list of items can be found and altered @ the "itemArray" array. Very self explanatory, but as an example (taken from the script)

PHP Code:
new const itemArray [ ] [ invItems ] = {
// id, name, model, type
    
0,         "One",         1337,         ITEM_TYPE_MISCALLENEOUS },
    { 
1,         "Two",         1338,         ITEM_TYPE_EQUIPABLE },
    { 
2,         "Three",         1336,         ITEM_TYPE_USABLE },
    { 
3,         "Four",         1339,         ITEM_TYPE_CONSUMABLE }
}; 
Adding a item is super easy and there can be an unlimited amount of items. My friend had an idea in mind for item types, which will be explained after this. The model is the model that's shown inside the inventory textdraw, name is self explanatory and the ID is the item's unique ID. There's probably a more efficient way to do this but we had no need for it as we weren't dynamically adjusting items. They were meant to be static.

Some information on how to make inventory items usable:

In the code you'll find this function, which you can adjust to your needs and add more or remove some inventory types. I've added a consumable example to show you what you can do with it. This code is also elaborated inside the actual script, so don't worry about copy and pasting this.

PHP Code:
UseInventoryItem playeriditemid ) {
    new 
itemtype itemArray pExaminingItem playerid } ] [ itemType ];
    switch ( 
itemtype ) {
        
// Consumable example
        
case ITEM_TYPE_CONSUMABLE: {
            
// Check for item quanity
            
if ( pInventoryItemQty playerid ] [ itemid ] < ) {
                return 
SendClientMessage playerid, -1"You don't have enough of this item to use!");
            }
        
            
pInventoryItemQty playerid ] [ itemid ] --;
            
SendClientMessage  playerid, -1" * Consumed item ");
        }
    }

Other than that I don't think anything else needs much covering. It's written in a (imo) very obvious method. My noob friend who doesn't know how to script at all altered this to his needs without any problem so I'm confident that it's not that hard to use.

Either way, if you do find issues using the script or if something isn't clear feel free to reply. There shouldn't be any bugs, just quirks. I probably won't ever look back on this so it is pointless to reply with bugs, fix them yourself. I've fixed the major ones.

Download: http://pastebin.com/s7vQ6AVw

zZzZzZz.
Reply
#2

Well done, +REPed
Reply
#3

Nice one!
Reply
#4

This is not really much of a framework more like a prototype design.
Reply
#5

Everything is made on Player textdraws. A very bad practice because most of the design could be done on Global textdraws.

The background, tiles, model previews, buttons should all be global because they don't require a dynamic string or per player based strings. I use player textdraws only when i have to make different strings for different players.

Hooking in a filterscript (and partially hooking few callbacks!)?
Reply
#6

Thanks for the feedback everyone

Quote:
Originally Posted by Gammix
View Post
Hooking in a filterscript (and partially hooking few callbacks!)?
This was meant to be a module. I completely forgot to get rid of them. Welp.
Reply
#7

Looks good might use this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)