19.09.2010, 21:13
Hello
I have a problem with my timer and loop
The code is affecting only playerid 0
Timer is added under ongameinit()
but when change the code a little and add it under onpayerconnect, then it is working:
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;
}
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;
}

