Return in a for()-loop - 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: Return in a for()-loop (
/showthread.php?tid=452408)
Return in a for()-loop -
XCarBOn - 21.07.2013
Following question:
I've made a serversided anti-weapon hack. Sometimes it's kinda buggy, because it detects player, who have no guns. So I've tried to skip players without guns in the weapon-check for the specific slot (Like Player1 has in slot 0 no guns -> The check skips this slot and continue checking for slot 1, and so on..).
Код:
public ACSUpdate(playerid)
{
if(GetPVarInt(playerid, "Spawned") == 1)
{
for(new slot; slot < 11; slot++)
{
GetPlayerWeaponData(playerid, slot, WeaponCheck[playerid][slot], WeaponAmmoCheck[playerid][slot]);
if(WeaponCheck[playerid][slot] == 0 && WeaponAmmoCheck[playerid][slot] == 0) return 0; // Here is the problem..
if(Weapon[playerid][slot] != WeaponCheck[playerid][slot] || WeaponAmmo[playerid][slot] - WeaponAmmoCheck[playerid][slot] < 0 || WeaponAmmoCheck[playerid][slot] < 0)
{
ACSKick(playerid, "Waffen/Ammo Hack");
}
}
}
return 1;
}
How can I return to the for()-loop without stopping the whole function?
Thanks for help
Re: Return in a for()-loop -
Misiur - 21.07.2013
Quote:
Originally Posted by XCarBOn
and continue checking
|
pawn Код:
//change
return 0;
//to
continue;
Re: Return in a for()-loop -
XCarBOn - 21.07.2013
So it skips slot 0 and continue with slot 1..?
Re: Return in a for()-loop -
Misiur - 21.07.2013
1. Try the code
2.
https://sampwiki.blast.hk/wiki/Control_Structures#continue
Re: Return in a for()-loop -
XCarBOn - 21.07.2013
Tested it, works fine. Thanks!