#pragma semicolon 1
#include <sourcemod>
public Plugin:myinfo =
{
name = "Spawn Protect",
author = "wS / Schmidt",
version = "1.1",
url = "http://world-source.ru/"
};
new Handle:spawn_protect_timer[MAXPLAYERS + 1];
new Handle:spawn_protect_sec;
public OnPluginStart()
{
spawn_protect_sec = CreateConVar("spawn_protect_sec", "2", "Сколько сек защищать игрока после рождения", _, true, 1.0);
HookEvent("player_spawn", player_spawn);
}
///
public player_spawn(Handle:event, const String:name[], bool:silent)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
Kill_Protect_Timer(client);
SetEntProp(client, Prop_Data, "m_takedamage", 0);
SetNewColor(client, 0, 255, 0, 75);
spawn_protect_timer[client] = CreateTimer(GetConVarFloat(spawn_protect_sec), StopProtect, client);
}
SetNewColor(client, r, g, b, a)
{
SetEntityRenderMode(client, RENDER_TRANSCOLOR);
SetEntityRenderColor(client, r, g, b, a);
}
public Action:StopProtect(Handle:timer, any:client)
{
spawn_protect_timer[client] = INVALID_HANDLE;
if (IsPlayerAlive(client))
{
SetEntProp(client, Prop_Data, "m_takedamage", 2);
SetNewColor(client, 255, 255, 255, 255);
}
return Plugin_Stop;
}
///
public OnClientDisconnect(client)
{
Kill_Protect_Timer(client);
}
Kill_Protect_Timer(client)
{
if (spawn_protect_timer[client] != INVALID_HANDLE)
{
KillTimer(spawn_protect_timer[client]);
spawn_protect_timer[client] = INVALID_HANDLE;
}
}