loop help
#1

Hey guys, so this loop below loops 10 slots and checks if any is empty. When it is empty it won't send a message, however to be user friendly I want to be able to send a message that the player doesn't have an empty slot. So the codes are:

This code always sends the message even if I have an empty slot, without the else return it works fine but without a message.
pawn Код:
for(new x = 0; x <10; x++)
    {
        if(PlayerInventory[playerid][piSlot][x] == 0)
        {
            if(gunid == 1)
            {
                if(PlayerInfo[playerid][pMaterials] < 1000) return SendClientMessage(playerid,COLOR_GREY,"** You don't have enough materials. **");
                format(string,sizeof(string),"** {C2A2DA}%s creates a Desert Eagle out of materials. {FF8000}**",GPN(playerid));
                SendRadiusMessage(30,playerid,string,COLOR_ORANGE);
                SendClientMessage(playerid,COLOR_GREY,"** The gun is now in your inventory. **");
                PlayerInventory[playerid][piSlot][x] = 348;
                break;
            }
          }
          else return SendClientMessage(playerid,COLOR_GREY,"You don't have an empty slot.");
     }
Reply
#2

Add a new variable before the loop
pawn Код:
new gunAdded = 0;
then modify the loop like this:
pawn Код:
// [...]
PlayerInventory[playerid][piSlot][x] = 348;
gunAdded = 1;
break;
// [...]
After the loop, so under it, add:
pawn Код:
if(gunAdded == 0) return SendClientMessage(playerid,COLOR_GREY,"You don't have an empty slot.");
Of course, you will have to remove the "else return ..." from inside the loop.
Reply
#3

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)