SA-MP Forums Archive
Problem with timer - 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: Problem with timer (/showthread.php?tid=651779)



Problem with timer - wallen - 27.03.2018

Top:
PHP код:
new statstimer
OnPlayerSpawn:
PHP код:
    statstimer SetTimerEx("statsrefresh"1001"i"playerid); 
OnPlayerDisconnect:
PHP код:
KillTimer(statstimer); 
So the timer works correctly, but it doesnt kill the timer for the ID that disconnected..


Re: Problem with timer - kovac - 27.03.2018

PHP код:
// At the top of your script
new statstimer[MAX_PLAYERS];
// --
statstimer[playerid] = SetTimerEx("statsrefresh"1001"i"playerid);
KillTimer(statstimer[playerid]); 
Edited:
Whenever the player spawns, another timer for the same player will activate.. so you will have tons of timers running and it may cause lag. You should consider moving this on player connect.

But why do you refresh stats like this at all?


Re: Problem with timer - wallen - 27.03.2018

Quote:
Originally Posted by kovac
Посмотреть сообщение
PHP код:
// At the top of your script
new statstimer[MAX_PLAYERS];
// --
statstimer[playerid] = SetTimerEx("statsrefresh"1001"i"playerid);
KillTimer(statstimer[playerid]); 
Edited:
Whenever the player spawns, another timer for same player will activate.. so you will have tons of timers running, you may consinder moving this on player connect.

But why do you refresh stats like this at all?
A timer is the way since OnPlayerUpdate can be easily gets corrupted and lag the server, i wont show it on the connection because


Re: Problem with timer - kovac - 27.03.2018

Why don't you simply save the player statistic on player disconnect and load it on player connect/login? You don't need any timers nor anything similar.


Re: Problem with timer - wallen - 27.03.2018

Quote:
Originally Posted by kovac
Посмотреть сообщение
Why don't you simply save the player statistic on player disconnect and load it on player connect/login?
These are TD's refreshing showing your stats on screen, i save it throught mysql and load it aswell with these 2 callbacks