Questions about player timers
#1

Hi

1. Do I need to kill player timers on onplayerdisconnect,or they are killed automatic?
2. Do I need to kill player timers which are not repeat on onplayerdisconnect?
3. In my script(I edit an mode) have in many Timer function Killtimer which are not repeat.It's needed?
For example
Код:
LoginTimer[playerid] = SetTimerEx("LoginCheck", 120000, false, "i", playerid);
Код:
forward LoginCheck(playerid);
public LoginCheck(playerid)
{
        //
	KillTimer(LoginTimer[playerid]);
	//
	return 1;
}
Reply
#2

You need to kill the timers if they are continuing, yes on disconnect. Timers that execute after a given amount of time will need to be killed in instances when the player disconnects, when you want to cancel the timer. If you give a timer a time and a player disconnects the timer will execute and might cause errors if no further checks were applied. You have to know what you're doing before you start dealing with timers, they can cause a lot of troubles.

There are a lot of threads with questions and answers about timers, take your time to read them.
Reply
#3

Timers will be killed when exiting the gamemode, but var who hold the timer, (in your case LoginTimer[playerid]), will not reset.

I recommend to kill the repetitive timers, even on OnPlayerDisconnect(), and to initialization the var timer with -1.

Nothing will not happens if u don't kill a non-repetitive timer, but i suggest you to do this if u don't want mess up the server performance.

It's like you have a car, u drive it to the shop, and u let the engine running, while u are in magazine, for some time...
This it's a good example.

I hope i helped u.
Reply
#4

Thank you guys!
Reply
#5

Also, don't store all timers in one array, if you do - kill timers in an array index before starting them there again.

I had this very interesting glitch in some old code I was asked to fix - GasOrder[ MAX_PLAYERS ]; stored the timers for filling up the gas in a vehicle.
Well, a cheater came, decided he doesn't want to way to fuel up, teleported several fuel pump pickups near himself and picked them up at the same time. Several timers were created in one index and only the last timer got killed when the gas was filled up, while the other 3 timers kept repeating without stopping. It rendered that player slot completely useless (everyone that connected to it would have gas filling up a vehicle with no way to stop that) until the server was restarted and some precautions were taken for the future.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)