SA-MP Forums Archive
Timers not working properly - 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: Timers not working properly (/showthread.php?tid=652823)



Timers not working properly - JaskaranSingh - 19.04.2018

Everything that contains timer on my server is not working properly. It works well for the first player. Then everything gets doubled for the second and triple for the third.

A health timer from my server:

PHP код:
new healthtimer[MAX_PLAYERS]; 
PHP код:
public OnPlayerConnect(playerid)
{
    
healthtimer[playerid] = SetTimerEx("DecreaseHealth"300001"i"playerid);
    return 
1;

PHP код:
public DecreaseHealth(playerid// Decreases player health by 1
{
    new 
Float:health;
    
GetPlayerHealth(playeridhealth);
    
SetPlayerHealth(playeridhealth 1.0);
    return 
1;

PHP код:
public OnPlayerDisconnect(playeridreason)
{
    
KillTimer(healthtimer[playerid]);
    
SaveAccount(playerid);
    return 
1;

This should decrease 1 HP after every 30 seconds. But when the second player joins, his health decreases at double speed and triple for the third. I have fuel system and payday system which are written the same way and giving same problem.


Re: Timers not working properly - AlamoTR - 19.04.2018

Код:
public OnPlayerDisconnect(playerid, reason)
{
	KillTimer(healthtimer[playerid]);
	return 1;
}



Re: Timers not working properly - JaskaranSingh - 19.04.2018

Quote:
Originally Posted by AlamoTR
Посмотреть сообщение
Код:
public OnPlayerDisconnect(playerid, reason)
{
	KillTimer(healthtimer[playerid]);
	return 1;
}
I have that already in my code. I am sorry, I forgot to put that in this post. Can you help?


Re: Timers not working properly - Hunud - 19.04.2018

Learn the proper use of timers: https://sampwiki.blast.hk/wiki/SetTimerEx


Re: Timers not working properly - JaskaranSingh - 19.04.2018

I read that whole article twice. Can you specifically point out the mistake or make the change? I am really frustrated since this week.


Re: Timers not working properly - UFF - 20.04.2018

Код:
public OnPlayerConnect(playerid) 
{ 
    KillTimer(healthtimer[playerid]); 
    healthtimer[playerid] = SetTimerEx("DecreaseHealth", 30000, 1, "i", playerid); 
    return 1; 
}
Try this


Re: Timers not working properly - GTLS - 20.04.2018

Try Setting Repeat to false in SetTimerEx. and set a new timer inside DecreaseHealth function.