/*****************************************************************************************
* - Cutted the code from l4dinfectedbots plugin by djromero (SkyDavid, David) and MI 5 *
*****************************************************************************************/
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#define DEBUGCLIENTS 0
#define TEAM_SPECTATOR 1
#define TEAM_SURVIVORS 2
#define TEAM_INFECTED 3
static ConVar h_idletime_b4slay;
static Handle FightOrDieTimer[MAXPLAYERS + 1]; // kill idle bots
public void OnPluginStart()
{
h_idletime_b4slay = CreateConVar("l4d_infectedbots_lifespan", "30", "Amount of seconds before a special infected bot is kicked", FCVAR_SPONLY);
// Such as PlayerSpawn and PlayerHurt.
// We hook some events ...
HookEvent("player_spawn", evtPlayerSpawn);
HookEvent("player_hurt", evtInfectedHurt);
}
public Action evtPlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
// We get the client id and time
int client = GetClientOfUserId(GetEventInt(event, "userid"));
// If client is valid
if (client > 0 && IsClientInGame(client) && GetClientTeam(client) == TEAM_INFECTED && IsFakeClient(client))
{
if (FightOrDieTimer[client])
{
delete(FightOrDieTimer[client]);
FightOrDieTimer[client] = null;
}
FightOrDieTimer[client] = CreateTimer(GetConVarFloat(h_idletime_b4slay), DisposeOfCowards, client, TIMER_FLAG_NO_MAPCHANGE);
}
return Plugin_Continue;
}
public Action evtInfectedHurt(Event event, const char[] name, bool dontBroadcast)
{
// The life of a regular special infected is pretty transient, they won't take many shots before they
// are dead (unlike the survivors) so we can afford to refresh the HUD reasonably quickly when they take damage.
int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if (attacker > 0 && FightOrDieTimer[attacker])
{
delete(FightOrDieTimer[attacker]);
FightOrDieTimer[attacker] = null;
FightOrDieTimer[attacker] = CreateTimer(GetConVarFloat(h_idletime_b4slay), DisposeOfCowards, attacker);
}
}
public Action DisposeOfCowards(Handle timer, any coward)
{
if (coward > 0 && IsClientInGame(coward) && IsFakeClient(coward) && GetClientTeam(coward) == TEAM_INFECTED && IsPlayerAlive(coward) && !IsClientInKickQueue(coward))
{
// Check to see if the infected thats about to be slain sees the survivors. If so, kill the timer and make a new one.
int threats = GetEntProp(coward, Prop_Send, "m_hasVisibleThreats");
if (threats)
{
FightOrDieTimer[coward] = null;
FightOrDieTimer[coward] = CreateTimer(GetConVarFloat(h_idletime_b4slay), DisposeOfCowards, coward);
#if DEBUGCLIENTS
PrintToChatAll("%N saw survivors after timer is up, creating new timer", coward);
#endif
return;
}
else
{
KickClient(coward);
}
}
FightOrDieTimer[coward] = null;
}