Loop Problem
#1

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;
}
Reply
#2

Put SetTimerEx("IgracGladan",10000,1,"i",playerid); in OnPlayerConnect.
Reply
#3

i put that and that is working
i am confused why the first part of the code isn't working
Reply
#4

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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)