Having a problem getting my timer to work properly. I'm trying to create chain kill system. If a player kills tanks in less than 5 second intervals, it should add them up until the chain breaks, and then reset. In my head this should work, and it appears to work for the first time but then halts. Here is the code, i've stripped it out of the main plugin for simplicity. Thanks for any help!
Code:
int ga_Chain[MAXPLAYERS + 1];
Handle ChainTimer[MAXPLAYERS+1];
public OnPluginStart()
{
HookEvent("tank_killed", Event_TankKill);
}
public OnClientDisconnect(int client)
{
ga_Chain[client] = 0;
delete ChainTimer[client];
}
public Event_TankKill(Event event, const char[] name, bool dontBroadcast)
{
int attackerId = event.GetInt("attacker");
int client = GetClientOfUserId(attackerId);
if(!IsFakeClient(client))
{
ga_Chain[client]++;
PrintToConsole(0, "%N killed a tank, %d in chain", client, ga_Chain[client]);
delete ChainTimer[client];
ChainTimer[client] = CreateTimer(5.0, EndChain, client, TIMER_FLAG_NO_MAPCHANGE);
}
}
public Action EndChain(Handle timer, int client)
{
PrintToConsole(0, "%N chain finished, %d kills", client, ga_Chain[client]);
ga_Chain[client] = 0;
return Plugin_Stop;
}