SA-MP Forums Archive
Foreach return problem - 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: Foreach return problem (/showthread.php?tid=600067)



Foreach return problem - DusanInfinity - 03.02.2016

I have this public:
Код:
forward Plata();
public Plata()
{
new payday[830];
foreach(Player, i)
    {
    if(gPlayerLogged[i] == 1)
      {
		if(PlayerInfo[i][pPayDay] < 5) return SCM(i, -1, "*Niste igrali dovoljno dugo da bi dobili platu.");
                SCM(i, -1, "You get money!");
code code code...
      }
   }
return true;
}
And like you see, if PlayerInfo[i][pPayDay] < 5 it will return for that player.

And problem is in that line. When payday come, if playerid 0 have PlayerInfo[0][pPayDay] < 5, next player who is id 1 won't get anything(he had PlayerInfo[1][pPayDay] > 5, but he dont receive any message)

What is problem? Do this line return for all players or what is problem??


And i create command for that public:
Код:
YCMD:pokreniplatu(playerid, params[], help)
{
Plata();
SCM(playerid, COLOR_WHITE, "Payday started!");
return 1;
}
And when it return "*Niste igrali dovoljno dugo da bi dobili platu.", i dont receive this message "Payday started!" from command!


Re: Foreach return problem - Sew_Sumi - 03.02.2016

NVM, Bless ****** translate.


Re: Foreach return problem - ball - 03.02.2016

Delete return from the loop

Код:
if(PlayerInfo[i][pPayDay] < 5) SCM(...);



Re: Foreach return problem - povargek - 03.02.2016

CrashDetect does not issue error?

Quote:
Originally Posted by ball
Посмотреть сообщение
Delete return from the loop

Код:
if(PlayerInfo[i][pPayDay] < 5) SCM(...);
The problem is not only in this, if there was a problem only in the return of the he seen message "Payday started!".


Re: Foreach return problem - DusanInfinity - 03.02.2016

Quote:
Originally Posted by ball
Посмотреть сообщение
Delete return from the loop

Код:
if(PlayerInfo[i][pPayDay] < 5) SCM(...);
I need that return..



Crashdetect - i test this on online linux server...(Crashdetect only on home server)


Re: Foreach return problem - povargek - 03.02.2016

Quote:
Originally Posted by DusanInfinity
Посмотреть сообщение
I need that return..



Crashdetect - i test this on online linux server...(Crashdetect only on home server)
You can use a conutine.

Код:
forward Plata();
public Plata()
{
new payday[830];
foreach(Player, i)
    {
    if(gPlayerLogged[i] == 1)
      {
		if(PlayerInfo[i][pPayDay] < 5)
                {
                  SCM(i, -1, "*Niste igrali dovoljno dugo da bi dobili platu.");
                  conutine;
                }
                SCM(i, -1, "You get money!");
code code code...
      }
   }
return true;
}



Re: Foreach return problem - Sew_Sumi - 03.02.2016

Confirm they are over 5 hours and process their pay. Avoids the return all together.

I don't think CrashDetect is for this at all.


Re: Foreach return problem - DusanInfinity - 03.02.2016

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Confirm they are over 5 hours and process their pay. Avoids the return all together.
When all players have payday > 5, there is no problem, all get pay. But when just 1 player have payday < 5, and if that playerid is 200, all players who are 200+ id won't get pay...


Re: Foreach return problem - Sew_Sumi - 03.02.2016

Then it's obviously because you are returning within the foreach.


Re: Foreach return problem - DusanInfinity - 03.02.2016

Okey i found one way, it must work good. Thank you all guys!