Inventory function help
#1

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.
Reply
#2

Nevermind - I got it working now
Reply
#3

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");
}
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)