Inventory -
GoldenLion - 07.10.2016
Hi, I'm trying to create an inventory system right now, it works well but the GiveItem function doesn't work. Like if I give myself an item then the name is blank, but everything else works (count, etc).
Enum:
Код:
enum inventoryInfo
{
ItemName[32],
ItemCount
}
new InventoryInfo[MAX_PLAYERS][25][inventoryInfo];
GiveItem function:
Код:
GiveItem(playerid, item[], amount)
{
printf("%s", item); // <---- I checked if the item is blank here, but it's not. :P
for (new i; i < 25; i++) //this part should check if player already has the item and just add the amount to the item's count
if (!strcmp(InventoryInfo[playerid][i][ItemName], item)) return InventoryInfo[playerid][i][ItemCount] += amount;
for (new i; i < 25; i++) if (!InventoryInfo[playerid][i][ItemCount]) //if player doesn't have the item already then it should find a free slot and give him the item
{
format(InventoryInfo[playerid][i][ItemName], 32, item);
InventoryInfo[playerid][i][ItemCount] = amount;
return 1;
}
return 0;
}
ShowInventory function (works like it's supposed to)
Код:
ShowInventory(playerid)
{
new inventory[1250], item[50];
for (new i; i < 25; i++)
{
if (InventoryInfo[playerid][i][ItemCount])
{
if (InventoryInfo[playerid][i][ItemCount] == 1) format(item, sizeof(item), "{FFFFFF}%d. %s\n", i + 1, InventoryInfo[playerid][i][ItemName]);
else format(item, sizeof(item), "{FFFFFF}%d. %s (%d)\n", i + 1, InventoryInfo[playerid][i][ItemName], InventoryInfo[playerid][i][ItemCount]);
}
else format(item, sizeof(item), "{999999}%d. Empty Slot\n", i + 1);
strcat(inventory, item);
}
ShowPlayerDialog(playerid, DIALOG_INVENTORY, DIALOG_STYLE_LIST, "Inventory", inventory, "Select", "Cancel");
return 1;
}
This is what it looks like in-game:
https://gyazo.com/54524c83e6ea7a5ebf2b792f71d399d6
As you can see the inventory system works itself, but GiveItem not. I gave myself a Cellphone by setting ItemName and ItemCount manually in a command. What's the problem?
Re: Inventory -
Luicy. - 07.10.2016
Are you saving the inventory data? If so, is the names saving? If you're not saving the data, please try using printf("%s", the variable); and tell me what it returns.
Re: Inventory -
SickAttack - 07.10.2016
It's only obvious, because your code has no logic to it.
Re: Inventory -
Pearson - 07.10.2016
Sooo WTF is this?

DDDDDDD
Re: Inventory -
GoldenLion - 07.10.2016
As I told you, the GiveItem function works itself, but the item's name is blank. That's something with the format function.
Re: Inventory -
GoldenLion - 08.10.2016
Anyone? I updated the post with some explainations.
Re: Inventory -
SickAttack - 08.10.2016
pawn Код:
GiveItem(playerid, item[], amount)
{
for(new i; i < 25; i++)
{
if(!strcmp(InventoryInfo[playerid][i][ItemName], item))
{
return InventoryInfo[playerid][i][ItemCount] += amount;
}
}
for(new i; i < 25; i++)
{
if(!InventoryInfo[playerid][i][ItemCount])
{
format(InventoryInfo[playerid][i][ItemName], 32, item);
return InventoryInfo[playerid][i][ItemCount] = amount;
}
}
return 0;
}
If it doesn't give you the item, then "InventoryInfo[playerid][i][ItemCount]" is not 0.
Re: Inventory -
GoldenLion - 08.10.2016
Quote:
Originally Posted by SickAttack
pawn Код:
GiveItem(playerid, item[], amount) { for(new i; i < 25; i++) { if(!strcmp(InventoryInfo[playerid][i][ItemName], item)) { return InventoryInfo[playerid][i][ItemCount] += amount; } } for(new i; i < 25; i++) { if(!InventoryInfo[playerid][i][ItemCount]) { format(InventoryInfo[playerid][i][ItemName], 32, item); return InventoryInfo[playerid][i][ItemCount] = amount; } } return 0; }
If it doesn't give you the item, then "InventoryInfo[playerid][i][ItemCount]" is not 0.
|
It does give me the item, but the item's name is always blank.
Re: Inventory -
SickAttack - 08.10.2016
Oh, yeah....
format(InventoryInfo[playerid][i][ItemName], 32, "%s", item);
Or
strcat(InventoryInfo[playerid][i][ItemName], item);
If you use strcat, equal the string to end of string "e.g. string[0] = EOS;" when removing the item.
Re: Inventory -
GoldenLion - 08.10.2016
Quote:
Originally Posted by SickAttack
Oh, yeah....
format(InventoryInfo[playerid][i][ItemName], 32, "%s", item);
Or
strcat(InventoryInfo[playerid][i][ItemName], item);
If you use strcat, equal the string to end of string "e.g. string[0] = EOS;" when removing the item.
|
None of them work.