12.11.2015, 13:16
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.
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
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 }
};
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 ( playerid, itemid ) {
new itemtype = itemArray [ pExaminingItem { playerid } ] [ itemType ];
switch ( itemtype ) {
// Consumable example
case ITEM_TYPE_CONSUMABLE: {
// Check for item quanity
if ( pInventoryItemQty [ playerid ] [ itemid ] < 1 ) {
return SendClientMessage ( playerid, -1, "You don't have enough of this item to use!");
}
pInventoryItemQty [ playerid ] [ itemid ] --;
SendClientMessage ( playerid, -1, " * Consumed item ");
}
}
}
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.