09.04.2013, 18:35
Hi there. I got it working, but it has been a while. I still have the script. The code I made looks like this:
Well first off I made this function. This function adds an "item" to the player's bag, adding it to any free slot. I made a function to check if the bag is full or not, which has to be used before this function, otherwise it will be buggy. Just insert this code into your script above all callbacks.
(Remember that the "PlayerInfo[playerid][pBagSlot1-5]" is just my variable. You can make your variable just as you want to.)
This is the function to check if the player's bag is full. Important to use this function and check if the player's bag is full BEFORE adding an item to it. Here is the code:
This function is used to remove an item from the a player's bag. It is important to check if the item is in the bag first! (Function for checking player's bag is below). Here is the code:
This function is used to check whether a certain item is in the player's bag or not. It is importand to use this function BEFORE removing a certain item from a player's bag! Here is the code:
So actually, when you add an item to a player's bag, you are actually adding a number. For example could an AK-47 be number 2. You will have to make your code read that number, and labeel them with item names for the players.
Hope this helps you. Feel free to ask if you have any other questions.
Well first off I made this function. This function adds an "item" to the player's bag, adding it to any free slot. I made a function to check if the bag is full or not, which has to be used before this function, otherwise it will be buggy. Just insert this code into your script above all callbacks.
pawn Код:
AddPlayerBagItem(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;
}
This is the function to check if the player's bag is full. Important to use this function and check if the player's bag is full BEFORE adding an item to it. Here is the code:
pawn Код:
IsPlayerBagFull(playerid)
{
if(PlayerInfo[playerid][pBagSlot1] == 0 || PlayerInfo[playerid][pBagSlot2] == 0 || PlayerInfo[playerid][pBagSlot3] == 0 || PlayerInfo[playerid][pBagSlot4] == 0 || PlayerInfo[playerid][pBagSlot5] == 0)
{
return false;
}
else return true;
}
pawn Код:
RemoveItemFromPlayerBag(playerid, itemid)
{
if(PlayerInfo[playerid][pBagSlot1] == itemid) PlayerInfo[playerid][pBagSlot1] = 0;
else if(PlayerInfo[playerid][pBagSlot2] == itemid) PlayerInfo[playerid][pBagSlot2] = 0;
else if(PlayerInfo[playerid][pBagSlot3] == itemid) PlayerInfo[playerid][pBagSlot3] = 0;
else if(PlayerInfo[playerid][pBagSlot4] == itemid) PlayerInfo[playerid][pBagSlot4] = 0;
else if(PlayerInfo[playerid][pBagSlot5] == itemid) PlayerInfo[playerid][pBagSlot5] = 0;
}
pawn Код:
IsItemInPlayerBag(playerid, itemid)
{
if(PlayerInfo[playerid][pBagSlot1] == itemid || PlayerInfo[playerid][pBagSlot2] == itemid || PlayerInfo[playerid][pBagSlot3] == itemid || PlayerInfo[playerid][pBagSlot4] == itemid || PlayerInfo[playerid][pBagSlot5] == itemid)
{
return true;
}
else return false;
}
Hope this helps you. Feel free to ask if you have any other questions.