#include <sdkhooks>
new Float:fTime, Handle:TimerColor[MAXPLAYERS+1];
public OnPluginStart()
{
HookEvent("player_death", Event_PlayerDeath);
HookConVarChange(TimerColor[0] = CreateConVar("protect_knife_time", "3.5", "Время защиты при первом уроне ножом.", _, true, 0.0), ChangeTime);
fTime = GetConVarFloat(TimerColor[0]);
CloseHandle(TimerColor[0]);
}
public ChangeTime(Handle:convar, String:oldValue[], String:newValue[]) fTime = GetConVarFloat(convar);
public Event_PlayerDeath(Handle:event, String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(TimerColor[client])
{
CloseHandle(TimerColor[client]);
TimerColor[client] = INVALID_HANDLE;
}
}
public OnClientPostAdminCheck(client) SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
public OnClientDisconnect(client)
{
SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage);
if(TimerColor[client])
{
CloseHandle(TimerColor[client]);
TimerColor[client] = INVALID_HANDLE;
}
}
public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
if(TimerColor[victim] != TimerColor[0]) if(0 < attacker <= MaxClients) if(attacker != victim)
{
decl String:NameWeapon[16];
GetClientWeapon(attacker, NameWeapon, sizeof(NameWeapon));
if(StrContains(NameWeapon, "knife") != -1 || strcmp(NameWeapon, "weapon_bayonet") == 0)
{
damage = 0.0;
if(TimerColor[victim] == INVALID_HANDLE)
{
SetEntityRenderMode(victim, RENDER_TRANSCOLOR);
SetEntityRenderColor(victim, 253, 141, 28, 255);
TimerColor[victim] = CreateTimer(fTime, StandartColor, victim);
}
return Plugin_Changed;
}
}
return Plugin_Continue;
}
public Action:StandartColor(Handle:timer, any:client)
{
TimerColor[client] = TimerColor[0];
SetEntityRenderMode(client, RENDER_TRANSCOLOR);
SetEntityRenderColor(client, 255, 255, 255, 255);
return Plugin_Stop;
}