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=476541)
Loop help -
Blast3r - 18.11.2013
Alright, hello. So I'm trying to create a system which gives the item to a slot if it's free. Like if slot 2 is taken it'll set it to 3 etc. However, this sets all my slots to the amount I put, so I'm wondering how do I make it that if slot 1 is taken it just sets it to slot 2?
The code I made:
pawn Код:
for(new i = 0; i < 10; i++)
{
if(i != 10)
{
if(PlayerInfo[playerid][pSlot][i] == 0)
{
PlayerInfo[playerid][pSlot][i] = item;
}
}
else
{
SendClientMessage(playerid, COLOR_RED, "ERROR:{FFFFFF} Your inventory is full.");
}
}
AW: Loop help -
Littl3j0hNy - 18.11.2013
do you mean:
Код:
new items;
for(new i = 0; i < 10; i++)
{
if(items < 10)
{
if(PlayerInfo[playerid][pSlot][i] == 0)
{
PlayerInfo[playerid][pSlot][i] = item;
items++;
}
}
else
{
SendClientMessage(playerid, COLOR_RED, "ERROR:{FFFFFF} Your inventory is full.");
break;
}
}
Re: Loop help -
Loot - 18.11.2013
I do not promise anything, and this might not work at all but try:
pawn Код:
stock GetNextSlot(playerid)
{
for(new i = 0; i < 10; i++)
{
if(i == 10) break;
if(!PlayerInfo[playerid][pSlot][i]) // is slot empty
{
return i; // return empty slot
}
}
return -1; // couldn't find an empty slot
}
// usage -> couldn't find
if(GetNextSlot(playerid) == -1) return SendClientMessage(playerid, COLOR_RED, "ERROR:{FFFFFF} Your inventory is full.");
// usage -> found an empty slot
if(GetNextSlot(playerid))
{
// do something here, ...
}
Re: Loop help -
Blast3r - 20.11.2013
Quote:
Originally Posted by Loot
I do not promise anything, and this might not work at all but try:
pawn Код:
stock GetNextSlot(playerid) { for(new i = 0; i < 10; i++) { if(i == 10) break; if(!PlayerInfo[playerid][pSlot][i]) // is slot empty { return i; // return empty slot } } return -1; // couldn't find an empty slot }
// usage -> couldn't find if(GetNextSlot(playerid) == -1) return SendClientMessage(playerid, COLOR_RED, "ERROR:{FFFFFF} Your inventory is full.");
// usage -> found an empty slot if(GetNextSlot(playerid)) { // do something here, ... }
|
Tried, didn't work, maybe I was doing something wrong while adding it into my stock. But yeah, still need help....
Re: Loop help -
DaRk_RaiN - 20.11.2013
Just return after setting it.
pawn Код:
for(new i = 0; i < 10; i++)
{
if(PlayerInfo[playerid][pSlot][i] == 0)
{
PlayerInfo[playerid][pSlot][i] = item;
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "ERROR:{FFFFFF} Your inventory is full.");
}
}
Re: Loop help -
Konstantinos - 20.11.2013
pawn Код:
new
bool: isfull
;
for(new i = 0; i < 10; i++)
{
if(!PlayerInfo[playerid][pSlot][i])
{
PlayerInfo[playerid][pSlot][i] = item;
isfull = true;
break;
}
}
if(!isfull) SendClientMessage(playerid, COLOR_RED, "ERROR:{FFFFFF} Your inventory is full.");
// You may return the message, that depends on what you want.