do while loop not working - 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: do while loop not working (
/showthread.php?tid=650705)
do while loop not working -
insus100 - 04.03.2018
Hello everybody! So Im using this loop:
PHP код:
new sorte;//This is the random player we are choosing.
//now the loop:
do
{
sorte = Iter_Random(Player);//I use foreach.
}
while(!Logado[sorte] || pInfo[sorte][pIdade] == 1);
//While he isnt logged OR he is Jailed (Using pIdade for Jailed, yeah) Repeat the loop.
fInfo[sorte][fBandit] = 1;//Here I set the faction to spawn
foreach(Player, i)
if(i != sorte || pInfo[i][pIdade] == 1 || pInfo[i][pAviso] > 0)// If player isnt bandit and he isnt jailed.
{
fInfo[i][fPolice] = 1; //Then, he is a cop.
}
So The problem is that if you are jailed, you still spawn to the game (being a cop) and it's so annoying damn.
I have tried using a simple:
PHP код:
while(!Logado[sorte] || pInfo[sorte][pIdade] == 1 || pInfo[sorte][pAviso] > 0) //If he isnt logged in OR he is jailed.
{
sorte = Iter_Random(Player); //Pick random player(foreach)
}
Doesnt work, I have used if too. Thanks for your help guys..
Re: do while loop not working -
AdamsLT - 05.03.2018
I think the problem here is with your second loop logic. Replace all of the ORs to ANDs and modify the check a bit because you need for all of the checks to pass to succesfully declare a cop. Now I think pAviso (whatever that is) > 0 might be true for the bandits so they all become cops.
Change
PHP код:
foreach(Player, i)
if(i != sorte || pInfo[i][pIdade] == 1 || pInfo[i][pAviso] > 0)// If player isnt bandit and he isnt jailed.
{
fInfo[i][fPolice] = 1; //Then, he is a cop.
}
To
PHP код:
foreach(Player, i)
if(i != sorte && pInfo[i][pIdade] != 1 && pInfo[i][pAviso] > 0)// If player isnt bandit and he isnt jailed.
{
fInfo[i][fPolice] = 1; //Then, he is a cop.
}
Re: do while loop not working -
insus100 - 05.03.2018
I thought about that, I will try it. pAviso is jail time, so it would act the same as pIdade (pJailed) so I Will remove it. Ill change the Ors for ands
Re: do while loop not working -
insus100 - 05.03.2018
Fixed..