loop 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: loop help (
/showthread.php?tid=558359)
loop help -
TonyII - 16.01.2015
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.");
}
Re: loop help -
HazardouS - 16.01.2015
Add a new variable before the loop
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.
Re: loop help -
TonyII - 16.01.2015
Thanks