|
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
|
10-06-2017
, 02:13
Re: Invalid Timer Handle
|
#17
|
Quote:
Originally Posted by Bacardi
Here my example...
Two Handle to handle two timers.
Warmup timer start on round start, and if this timer is still active while player kill another player, timer reset.
If warmuptimer still active when round start, timer reset.
When warmup timer time reach end, it create repeated smoketimer.
If smoketimer is active, it stop on round start.
PHP Code:
Handle hWarmuptimer;
Handle hSmoketimer;
public void OnPluginStart()
{
HookEventEx("round_start", round_start);
HookEventEx("player_death", player_death);
}
public void round_start(Event event, const char[] name, bool dontBroadcast)
{
// SmokeTimer currently running, active!
// Lets clear this repeated timer Handle, it will stop itself :D
if(hSmoketimer != null) hSmoketimer = null;
// If Warmuptimer still running, active!
// Kill timer
if(hWarmuptimer != null) KillTimer(hWarmuptimer);
hWarmuptimer = CreateTimer(20.0, warmuptimer_cb); // create new on round start
}
public void player_death(Event event, const char[] name, bool dontBroadcast)
{
int victim = GetClientOfUserId(event.GetInt("userid"));
int attacker = GetClientOfUserId(event.GetInt("attacker"));
// killer not world or player suicide (no teamkill check here now)
if(attacker == 0 || attacker == victim) return;
// Timer is currently running, active! We will reset timer.
if(hWarmuptimer != null)
{
KillTimer(hWarmuptimer); // Remove current timer
hWarmuptimer = CreateTimer(20.0, warmuptimer_cb); // Create new timer in this same Handle
}
}
public Action warmuptimer_cb(Handle timer)
{
// Ok, this timer reach end and callback has triggered.
// Lets also clear (null) this timer Handle to make sure that this timer is not active anymore. Like as message to othe code blocks.
hWarmuptimer = null;
// There is no way, smoketimer supposed to runnig in this point. But double check.
if(hSmoketimer != null) KillTimer(hSmoketimer);
// Create repeated smoke timer
hSmoketimer = CreateTimer(0.5, smoketimer_cb, _, TIMER_REPEAT);
return Plugin_Continue;
}
public Action smoketimer_cb(Handle timer)
{
// Check Handle is it null, stop timer if it is.
if(hSmoketimer == null) return Plugin_Stop
// Do your smoke exec() here!
// for example, print chat message smoke alive players
for(int i = 1; i <= MaxClients; i++)
{
if(!IsClientInGame(i) || !IsPlayerAlive(i)) continue;
PrintToChat(i, "smoke!");
}
// Let timer continue
return Plugin_Continue;
}
*edit
I skipped this part. I made example to loop all alive players and print chat message "smoke" :/
|
Thank you for this! I will try it all tonight after work
__________________
|
|
|
|