Organizing Inventory Items -
MafiaOink - 16.03.2018
Hello whoever is viewing this post, I have encountered a strange problem whenever I try to reorganize my inventory items, The inventory is organized right after giving the player the item so because of some certain problem, the item goes away which I cannot identify, I've tried to rewrite out my way of reorganizing but still no success.
Can someone tell me the problem why do I not get item?
Here is my code:
Updating Inventory (reorganizing etc and stacking items)
Код:
UpdatePlayerInventory(playerid)
{
if(PlayerInfo[playerid][LoggedIn] == false) return -1;
for(new mi = 0; mi < MAX_PLAYER_ITEMS; mi++)
{
if(PlayerInfo[playerid][iAmount][mi] < 1 && PlayerInfo[playerid][iItem] != 0) PlayerInfo[playerid][iItem] = 0;
if(PlayerInfo[playerid][iItem][mi] == 0)
{
for(new miex = 0; miex < MAX_PLAYER_ITEMS; miex++)
{
if(PlayerInfo[playerid][iItem][miex] != 0)
{
if(miex > mi)
{
PlayerInfo[playerid][iItem][mi] = PlayerInfo[playerid][iItem][miex];
PlayerInfo[playerid][iAmount][mi] = PlayerInfo[playerid][iAmount][miex];
PlayerInfo[playerid][iSpecial][mi] = PlayerInfo[playerid][iSpecial][miex];
PlayerInfo[playerid][iItem][miex] = 0;
PlayerInfo[playerid][iAmount][miex] = 0;
PlayerInfo[playerid][iSpecial][miex] = 0;
}
}
}
}
else
{
for(new miex = 0; miex < MAX_PLAYER_ITEMS; miex++)
{
if(miex != mi)
{
if(PlayerInfo[playerid][iItem][mi] == PlayerInfo[playerid][iItem][miex])
{
if(PlayerInfo[playerid][iSpecial][miex] == PlayerInfo[playerid][iSpecial][mi])
{
if(miex > mi)
{
PlayerInfo[playerid][iAmount][mi] += PlayerInfo[playerid][iAmount][miex];
PlayerInfo[playerid][iItem][miex] = 0;
PlayerInfo[playerid][iAmount][miex] = 0;
PlayerInfo[playerid][iSpecial][miex] = 0;
}
else if(mi > miex)
{
PlayerInfo[playerid][iAmount][miex] += PlayerInfo[playerid][iAmount][mi];
PlayerInfo[playerid][iItem][mi] = 0;
PlayerInfo[playerid][iAmount][mi] = 0;
PlayerInfo[playerid][iSpecial][mi] = 0;
}
}
}
}
}
}
}
return 1;
}
Giving items:
Код:
GetFreeInventorySlot(playerid)
{
if(PlayerInfo[playerid][LoggedIn] == false) return -1;
new slot = -1;
UpdatePlayerInventory(playerid);
for(new z = 0; z < MAX_PLAYER_ITEMS; z++)
{
if(PlayerInfo[playerid][iItem][z] == 0) slot = z;
}
return slot;
}
GivePlayerItem(playerid, item, amount = 1, special = -1)
{
if(PlayerInfo[playerid][LoggedIn] == false) return -1;
UpdatePlayerInventory(playerid);
new slot = GetFreeInventorySlot(playerid);
if(slot == -1) return 0;
PlayerInfo[playerid][iItem][slot] = item;
PlayerInfo[playerid][iAmount][slot] = amount;
PlayerInfo[playerid][iSpecial][slot] = special;
UpdatePlayerInventory(playerid);
return 1;
}
Without update playeri nventory part, the item I give comes to last slot and if I try to give again the item replaces the last slot so only the last slot is working without updating inventory.
This is my giveitem cmd:
Код:
CMD:giveitem(playerid, params[])
{
if(PlayerInfo[playerid][Admin] < 3) return SFM(playerid, COLOR_RED, "You are not allowed to use that command!");
new target, itemid, amount, special;
if(sscanf(params, "dddd", target, itemid, amount, special)) return SFM(playerid, COLOR_GREY, "[USAGE] giveitem [target-id] [itemid] [amount] [special(leave as -1)]");
if(!IsPlayerConnected(target)) return SFM(playerid, COLOR_RED, "Target is not connected!");
if(PlayerInfo[target][LoggedIn] == false) return SFM(playerid, COLOR_RED, "Target is not logged in!");
if(!strcmp("Unknown Item", GetItemName(itemid))) return SFM(playerid, COLOR_RED, "Invalid item id!");
if(special < -1) return SFM(playerid, COLOR_RED, "Special cannot be less than -1 and please set it -1 if you dont know what your doing!");
if(amount < 0) return SFM(playerid, COLOR_RED, "If you wish to remove an item then use /removeitem instead of /giveitem!");
new success = GivePlayerItem(target, itemid, amount, special);
if(success == 0) return SFM(playerid, COLOR_RED, "Target does not have any free inventory space!");
new inStr[128];
format(inStr, 128, "%s has given you a %s (%d) (/inv).", RPName(playerid), GetItemName(itemid), amount);
AdminMsgToPlayer(target, inStr);
format(inStr, 128, COLOR_ADMINCOMMAND"You have given %s a %s (%d).", RPName(target), GetItemName(itemid), amount);
SFM(playerid, 1, inStr);
return 1;
}
My inventory cmd:
Код:
CMD:inv(playerid, params[])
{
new stringa[512], stringtoo[64];
format(stringa, 512, "");
for(new zx = 0; zx < MAX_PLAYER_ITEMS; zx++)
{
if(PlayerInfo[playerid][iAmount][zx] > 1)
format(stringtoo, 64, "%s (%d)\n", GetItemName(PlayerInfo[playerid][iItem][zx]), PlayerInfo[playerid][iAmount][zx]);
else
format(stringtoo, 64, "%s\n", GetItemName(PlayerInfo[playerid][iItem][zx]));
strcat(stringa, stringtoo);
}
ShowPlayerDialog(playerid, DIALOG_INVENTORY, DIALOG_STYLE_LIST, "Inventory", stringa, "Select", "Close");
return 1;
}
btw if your wondering, yes my inventory is full of unknown items as I am using a newly registered account with no items and give item keeps changing the item back to the unknown item
also sometimes when I give more than 1 amount of items, the unknown item value can be seen like Unknown Item (10) which indicates the itemID was changed not the amount and special etc.
Re: Organizing Inventory Items -
MafiaOink - 16.03.2018
BUMP
Re: Organizing Inventory Items -
MadeMan - 16.03.2018
pawn Код:
if(PlayerInfo[playerid][iAmount][mi] < 1 && PlayerInfo[playerid][iItem] != 0) PlayerInfo[playerid][iItem] = 0;
Indexes missing ?
pawn Код:
PlayerInfo[playerid][iItem][mi]
Re: Organizing Inventory Items -
MafiaOink - 16.03.2018
Thanks, I'm so dumb that even after rewriting I forgot this.
side effects of scripting with stress.