Loop 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Loop Problem (
/showthread.php?tid=177933)
Loop Problem -
Gigi-The-Beast - 19.09.2010
Hello
I have a problem with my timer and loop
The code is affecting only playerid 0
Код:
public Eating()
{
new Float:Hp[MAX_PLAYERS];
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetProgressBarValue(hungrybar[i]) == 0)
{
GetPlayerHealth(i,Hp[i]);
SetPlayerHealth(i,Hp[i] - 20);
return 1;
}
else
{
hungryammount[i] -= 2;
SetProgressBarValue(hungrybar[i], hungryammount[i]);
UpdateProgressBar(hungrybar[i]);
return 1;
}
}
}
return 1;
}
Timer is added under ongameinit()
but when change the code a little and add it under onpayerconnect, then it is working:
Код:
SetTimerEx("IgracGladan",10000,1,"i",playerid);
forward IgracGladan(playerid);
public IgracGladan(playerid)
{
new Float:Hp[MAX_PLAYERS];
if(IsPlayerConnected(playerid))
{
if(GetProgressBarValue(hungrybar[playerid]) == 0)
{
GetPlayerHealth(playerid,Hp[playerid]);
SetPlayerHealth(playerid,Hp[playerid] - 20);
return 1;
}
else
{
hungryammount[playerid] -= 2;
SetProgressBarValue(hungrybar[playerid], hungryammount[playerid]);
UpdateProgressBar(hungrybar[playerid]);
return 1;
}
}
return 1;
}
Re: Loop Problem -
Conroy - 19.09.2010
Put SetTimerEx("IgracGladan",10000,1,"i",playerid); in OnPlayerConnect.
Re: Loop Problem -
Gigi-The-Beast - 19.09.2010
i put that and that is working
i am confused why the first part of the code isn't working
Re: Loop Problem -
Gigi-The-Beast - 20.09.2010
hmm, i removed the returns in the first code and now it is working.
but i really don't get is why, why the second code is working even with returns?
can you tell me that?