Inventory function help - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Inventory function help (
/showthread.php?tid=292862)
Inventory function help -
sim_sima - 25.10.2011
Hi guys.
Im currently working on my inventory system.
It has to work like this: Every player has a bag with 5 slots (Max 5 items)
Every slot has a variable (PlayerInfo[playerid][pBagSlot1], PlayerInfo[playerid][pBagSlot2], PlayerInfo[playerid][pBagSlot3], PlayerInfo[playerid][pBagSlot4] and PlayerInfo[playerid][pBagSlot5]).
When an item is added to the bag, the item will be in slot 1. If slot 1 is occupied, the item will come in slot 2 and so on.
I made this function:
pawn Код:
forward AddItemToBag(playerid, itemid);
public AddItemToBag(playerid, itemid)
{
if(PlayerInfo[playerid][pBagSlot1] = 0) PlayerInfo[playerid][pBagSlot1] = itemid;
else if(PlayerInfo[playerid][pBagSlot2] = 0) PlayerInfo[playerid][pBagSlot2] = itemid;
else if(PlayerInfo[playerid][pBagSlot3] = 0) PlayerInfo[playerid][pBagSlot3] = itemid;
else if(PlayerInfo[playerid][pBagSlot4] = 0) PlayerInfo[playerid][pBagSlot4] = itemid;
else if(PlayerInfo[playerid][pBagSlot5] = 0) PlayerInfo[playerid][pBagSlot5] = itemid;
else return SendClientMessage(playerid, COLOR_NORMALRED, "( ! ) Your Bag is full");
return 1;
}
Example:
AddItemToBag(playerid, 2);
If itemid 2 is a cheque, then the player will reveive a cheque in his bag.
This function doesn't work. Hope you can help me. Thanks.
Re: Inventory function help -
sim_sima - 06.11.2011
Nevermind - I got it working now
Re: Inventory function help -
CyNiC - 06.11.2011
This should work.
pawn Код:
forward AddItemToBag(playerid, itemid);
public AddItemToBag(playerid, itemid)
{
if(PlayerInfo[playerid][pBagSlot1] == 0)
{
PlayerInfo[playerid][pBagSlot1] = itemid;
return 1;
}
else if(PlayerInfo[playerid][pBagSlot2] == 0)
{
PlayerInfo[playerid][pBagSlot2] = itemid;
return 1;
}
else if(PlayerInfo[playerid][pBagSlot3] == 0)
{
PlayerInfo[playerid][pBagSlot3] = itemid;
return 1;
}
else if(PlayerInfo[playerid][pBagSlot4] == 0)
{
PlayerInfo[playerid][pBagSlot4] = itemid;
return 1;
}
else if(PlayerInfo[playerid][pBagSlot5] == 0)
{
PlayerInfo[playerid][pBagSlot5] = itemid;
return 1;
}
return SendClientMessage(playerid, COLOR_NORMALRED, "( ! ) Your Bag is full");
}
Re: Inventory function help -
sim_sima - 08.11.2011
Quote:
Originally Posted by CyNiC
This should work.
pawn Код:
forward AddItemToBag(playerid, itemid); public AddItemToBag(playerid, itemid) { if(PlayerInfo[playerid][pBagSlot1] == 0) { PlayerInfo[playerid][pBagSlot1] = itemid; return 1; } else if(PlayerInfo[playerid][pBagSlot2] == 0) { PlayerInfo[playerid][pBagSlot2] = itemid; return 1; } else if(PlayerInfo[playerid][pBagSlot3] == 0) { PlayerInfo[playerid][pBagSlot3] = itemid; return 1; } else if(PlayerInfo[playerid][pBagSlot4] == 0) { PlayerInfo[playerid][pBagSlot4] = itemid; return 1; } else if(PlayerInfo[playerid][pBagSlot5] == 0) { PlayerInfo[playerid][pBagSlot5] = itemid; return 1; } return SendClientMessage(playerid, COLOR_NORMALRED, "( ! ) Your Bag is full"); }
|
I already got it working. However, thanks