Timers not working properly
#1

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.
Reply
#2

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)