#pragma semicolon 1
static const iColor[][] =
{
{255, 64, 64}, // террористы
{153, 204, 255} // контр-террористы
};
public Plugin:myinfo =
{
name = "Spawn Protect",
author = "wS / Schmidt (mod by Grey83)",
version = "1.1.1",
url = "http://world-source.ru/"
};
new Handle:hProtectTimer[MAXPLAYERS+1],
Float:fProtectTimer;
public OnPluginStart()
{
new Handle:CVar;
HookConVarChange((CVar = CreateConVar("spawn_protect_sec", "2", "Сколько сек защищать игрока после рождения (<1 - отключено)", _, true, 0.0)), CVarChanged);
fProtectTimer = GetConVarFloat(CVar);
HookEvent("player_spawn", Event_Spawn);
}
public CVarChanged(Handle:CVar, const String:oldValue[], const String:newValue[])
{
fProtectTimer = GetConVarFloat(CVar);
}
public Event_Spawn(Handle:event, const String:name[], bool:silent)
{
if(fProtectTimer < 1) return;
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(!client) return;
new team = GetClientTeam(client);
if(team < 2) return;
team -= 2;
SetNewColor(client, iColor[team][0], iColor[team][1], iColor[team][2], 75);
Kill_Protect_Timer(client);
SetEntProp(client, Prop_Data, "m_takedamage", 0);
hProtectTimer[client] = CreateTimer(fProtectTimer, StopProtect, GetClientUserId(client));
}
public Action:StopProtect(Handle:timer, any:client)
{
if((client = GetClientOfUserId(client)) && IsPlayerAlive(client))
{
SetEntProp(client, Prop_Data, "m_takedamage", 2);
SetNewColor(client, 255, 255, 255, 255);
}
hProtectTimer[client] = INVALID_HANDLE;
}
SetNewColor(client, r, g, b, a)
{
SetEntityRenderMode(client, RENDER_TRANSCOLOR);
SetEntityRenderColor(client, r, g, b, a);
}
public OnClientDisconnect(client)
{
Kill_Protect_Timer(client);
}
Kill_Protect_Timer(client)
{
if(hProtectTimer[client] != INVALID_HANDLE)
{
KillTimer(hProtectTimer[client]);
hProtectTimer[client] = INVALID_HANDLE;
}
}