SA-MP Forums Archive
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: Loop (/showthread.php?tid=581920)



Loop - nezo2001 - 16.07.2015

Will this decrease MaxPass variable for each player effects by the code or only one time?
PHP код:
        for(new =0MAX_PLAYERS;i++)
        {
            if(
PilotID[i] == playerid && city[i] == 1)
            {
                
SetPlayerPos(i,1983.5895,-2496.0449,13.5391);
                
SetPlayerInterior(i0);
                
SetPlayerVirtualWorld(i0);
                
PilotID[i] = -1;
                
RequestPilot[i] = false;
                
city[i] = 0;
                
MaxPass[playerid]--;
            }
        } 



Re: Loop - Lajko1 - 16.07.2015

I think it should work


AW: Loop - Mencent - 16.07.2015

Hello!

MaxPass decrease the whole time so far the loop is finished.
If MAX_PLAYERS is 500, MaxPass will be going 500 decreasing.

(Sorry for my very bad english...)


- Mencent


Re: Loop - admantis - 16.07.2015

It will decrease MaxPass for playerid many times. If you want to decrease it by 1 for each player in the loop, change "playerid" to "i" to affect the player in the iteration:
Код:
MaxPass[i]--;



Re: Loop - nezo2001 - 16.07.2015

But I want to deacrease MaxPass for playerid not the other players


Re: Loop - Mauzen - 16.07.2015

It will only decrease for playerid. Unless playerid can be in PilotID[i] multiple times, the if condition will only be met once. You could then add
break;
at the end of the if clause, so the loop will stop and wont continue unneccessarily.


Re: Loop - admantis - 16.07.2015

If you want to affect the playerid once, just place MaxPass(playerid)-- outside of the loop. I think it's pretty obvious.