Commands: /inventory
|
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#define MAX_INV_SLOTS 5
#define MAX_INV_ITEMS 15
#define MAX_DROP_OBJ 50
// Store item ID inside of this
new pInv_Item[MAX_PLAYERS][MAX_INV_SLOTS];
new pInv_Value[MAX_PLAYERS][MAX_INV_SLOTS];
new DroppedItemsObj[MAX_DROP_OBJ];
new Text3D: DroppedItemsLab[MAX_DROP_OBJ];
new DroppedItemsVal[MAX_DROP_OBJ];
new DroppedItemsItem[MAX_DROP_OBJ];
new DroppedItemsTime[MAX_DROP_OBJ];
new InventoryItems[MAX_INV_ITEMS][] = {
// ID, "Name of Item"
{0, "Untitled"}, // Can't be given
{1, "Untitled"},
{2, "Untitled"},
{3, "Untitled"},
{4, "Untitled"},
{5, "Untitled"},
{6, "Untitled"},
{7, "Untitled"},
{8, "Untitled"},
{9, "Untitled"},
{10, "Untitled"},
{11, "Untitled"},
{12, "Untitled"},
{13, "Untitled"},
{14, "Untitled"}
};
public OnFilterScriptExit()
{
for(new i = 0; i < MAX_DROP_OBJ ; i ++)
{
DestroyObject(DroppedItemsObj[i]);
Delete3DTextLabel(DroppedItemsLab[i]);
}
return 1;
}
CMD:inventory(playerid, params[])
{
new string[128];
for(new i = 0; i < MAX_INV_SLOTS; i ++)
{
if(pInv_Item[playerid][i] > 0)
{
format(string, sizeof(string), "Item Slot %d: {549E63}%s{FFFFFF} (V: %d)", i, InventoryItems[pInv_Item[playerid][i]][1], pInv_Value[playerid][i]);
SendClientMessage(playerid, -1, string);
}
else if(pInv_Item[playerid][i] == 0)
{
format(string, sizeof(string), "Item Slot %d: {BF5050}EMPTY{FFFFFF}", i);
SendClientMessage(playerid, -1, string);
}
}
return 1;
}
CMD:useitem(playerid, params[])
{
new slot, value, string[128];
if(sscanf(params, "i", slot, value)) return SendClientMessage(playerid, -1, "/useitem [slot]");
if(slot > 4) return SendClientMessage(playerid, -1, "There are only {50A0BF}five{FFFFFF} slots you can use! (0-4)");
if(pInv_Item[playerid][slot] == 0) return SendClientMessage(playerid, -1, "There's nothing in that inventory slot!");
if(pInv_Value[playerid][slot] < value) return SendClientMessage(playerid, -1, "The value you specified is incorrect! You don't have that much of the item you selected!");
format(string, sizeof(string), "You used item {50A0BF}ID %d{FFFFFF} ({50A0BF}%s{FFFFFF}) {50A0BF}(%d){FFFFFF} from {50A0BF}slot %d{FFFFFF}.", InventoryItems[pInv_Item[playerid][slot]][0], InventoryItems[pInv_Item[playerid][slot]][1], pInv_Value[playerid][slot], slot);
SendClientMessage(playerid, -1, string);
pInv_Value[playerid][slot] -= value;
if(pInv_Value[playerid][slot] == 0) pInv_Item[playerid][slot] = 0;
return 1;
}
CMD:pickupitem(playerid, params[])
{
new Float: X, Float: Y, Float: Z, string[128], item;
if(sscanf(params, "i", item)) return SendClientMessage(playerid, -1, "/pickupitem [id]");
GetObjectPos(DroppedItemsObj[item], X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, 3.0, X, Y, Z))
{
for(new i = 0; i < MAX_INV_SLOTS; i ++)
{
if(pInv_Item[playerid][i] == 0)
{
pInv_Item[playerid][i] = DroppedItemsItem[item];
pInv_Value[playerid][i] = DroppedItemsVal[item];
format(string, sizeof(string), "Picked up item {50A0BF}ID (%d){FFFFFF} ({50A0BF}%s{FFFFFF}) {50A0BF}(%d){FFFFFF}. Stored in {50A0BF}slot %d{FFFFFF}.", item, InventoryItems[DroppedItemsItem[item]][1], DroppedItemsVal[item], i);
SendClientMessage(playerid, -1, string);
break;
}
}
DestroyObject(DroppedItemsObj[item]);
Delete3DTextLabel(DroppedItemsLab[item]);
DroppedItemsObj[item] = 0;
DroppedItemsVal[item] = 0;
DroppedItemsItem[item] = 0;
}
else SendClientMessage(playerid, -1, "You're not near that object!");
return 1;
}
CMD:dropitem(playerid, params[])
{
new slot, string[128], labstring[128], Float: X, Float: Y, Float: Z;
GetPlayerPos(playerid, X, Y, Z);
if(sscanf(params, "i", slot)) return SendClientMessage(playerid, -1, "/dropitem [slot]");
if(slot > 4) return SendClientMessage(playerid, -1, "There are only {50A0BF}five{FFFFFF} slots you can use! (0-4)");
if(pInv_Item[playerid][slot] == 0) return SendClientMessage(playerid, -1, "There's nothing in that inventory slot!");
for(new i = 0; i < MAX_DROP_OBJ; i ++)
{
if(DroppedItemsObj[i] == 0)
{
format(labstring, sizeof(labstring), "[{B2E66E}LOOTABLE ITEM{FFFFFF}]\n %s (%d)\n[{B2E66E}/pickupitem{FFFFFF} ID: {B2E66E}%d{FFFFFF}]", InventoryItems[pInv_Item[playerid][slot]][1], pInv_Value[playerid][slot], i);
DroppedItemsLab[i] = Create3DTextLabel(labstring, 0xFFFFFFFF, X +0.1, Y, Z -0.4, 15.0, GetPlayerVirtualWorld(playerid), 1);
DroppedItemsObj[i] = CreateObject(3014, X, Y, Z -0.8, 0.00, 0.00, 0.00);
SetPlayerPos(playerid, X, Y, Z +0.9);
DroppedItemsVal[i] = pInv_Value[playerid][slot];
DroppedItemsItem[i] = pInv_Item[playerid][slot];
DroppedItemsTime[i] = 300;
format(string, sizeof(string), "You dropped item {50A0BF}ID %d{FFFFFF} ({50A0BF}%s{FFFFFF}) {50A0BF}(%d){FFFFFF} from {50A0BF}slot %d{FFFFFF}.", InventoryItems[pInv_Item[playerid][slot]][0], InventoryItems[pInv_Item[playerid][slot]][1], pInv_Value[playerid][slot], slot);
SendClientMessage(playerid, -1, string);
break;
}
}
pInv_Item[playerid][slot] = 0;
pInv_Value[playerid][slot] = 0;
return 1;
}
// ADMIN COMMANDS
CMD:giveitem(playerid, params[])
{
new targetid, slot, item, value, string[128];
if(sscanf(params, "uiii", targetid, slot, item, value)) return SendClientMessage(playerid, -1, "/additem [targetid] [slot] [item] [value]");
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be an RCON admin in order to use this command!");
if(item > 15 || item < 1) return SendClientMessage(playerid, -1, "The item ID you entered does not exist. For a list of items, type: {50A0BF}/itemlist{FFFFFF}.");
if(slot > 4) return SendClientMessage(playerid, -1, "There are only {50A0BF}five{FFFFFF} slots you can use! (0-4)");
pInv_Item[playerid][slot] = item;
pInv_Value[playerid][slot] = value;
format(string, sizeof(string), "Item {50A0BF}ID %d{FFFFFF} ({50A0BF}%s{FFFFFF}) {50A0BF}(%d){FFFFFF} added to {50A0BF}slot %d{FFFFFF}.", item, InventoryItems[item][1], value, slot);
SendClientMessage(playerid, -1, string);
return 1;
}
CMD:itemlist(playerid, params[])
{
new string[128];
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be an RCON admin in order to use this command!");
for(new i = 1; i < MAX_INV_ITEMS; i ++)
{
format(string, sizeof(string), "Item ID: {50A0BF}''%d''{FFFFFF} - Name: {50A0BF}''%s''{FFFFFF}", InventoryItems[i][0], InventoryItems[i][1]);
SendClientMessage(playerid, -1, string);
}
return 1;
}
This is very interesting for me too as im working on an inventory system right now.
i took a look at your 'CMD:inventory' wich checks out if a slot is empty or not. How would you do this within a dialog ? i actually want to show the word EMPTY in the dialog instead of leaving it blanc. and BTW: you did very well its good to see simple basics. Many people can learn from it. Maybe you could put the itemvalues in an enum instead. |