#include <sdkhooks>
new sm_invisibility_time;
new Handle:g_hTimer[MAXPLAYERS+1];
new bool:activation[MAXPLAYERS+1];
public OnPluginStart()
{
RegConsoleCmd("sm_inviz", PlayerInvizion);
new Handle:Cvar = CreateConVar("sm_invisibility_time", "5", "Invisibility time");
HookConVarChange(Cvar, InvisibilityTime);
sm_invisibility_time = GetConVarInt(Cvar);
CloseHandle(Cvar);
HookEvent("player_death", Event_PlayerDeath);
}
public OnMapStart()
{
for (new client = 1; client<=MAXPLAYERS; client++)
activation[client] = false;
}
public InvisibilityTime(Handle:cvar, const String:oldVal[], const String:newVal[]) sm_invisibility_time = GetConVarInt(cvar);
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
OnClientDisconnect(GetClientOfUserId(GetEventInt(event, "userid")));
public Action:PlayerInvizion(client, args)
{
if(client > 0 && IsPlayerAlive(client) && g_hTimer[client] == INVALID_HANDLE)
{
if (activation[client]) {
PrintToChat(client, "Включить невидимость невозможно: вы уже включали её ранее.");
return Plugin_Handled;
}
PrintToChat(client, "Невидимость включена");
SetAlpha(client, 0);
SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost);
g_hTimer[client] = CreateTimer(float(sm_invisibility_time), removeinvis, client);
activation[client] = true;
}
return Plugin_Handled;
}
public Action:removeinvis(Handle:timer, any:client)
{
SetAlpha(client, 255);
PrintToChat(client, "Невидимость отключена");
SDKUnhook(client, SDKHook_PostThinkPost, OnPostThinkPost);
g_hTimer[client] = INVALID_HANDLE;
}
public OnClientDisconnect(client)
{
if(g_hTimer[client] != INVALID_HANDLE)
{
activation[client] = false;
KillTimer(g_hTimer[client]);
g_hTimer[client] = INVALID_HANDLE;
SDKUnhook(client, SDKHook_PostThinkPost, OnPostThinkPost);
}
}
SetAlpha(target, alpha)
{
SetWeaponsAlpha(target,alpha);
SetEntityRenderMode(target, RENDER_TRANSCOLOR);
SetEntityRenderColor(target, 255, 255, 255, alpha);
}
SetWeaponsAlpha(target, alpha)
{
if(IsPlayerAlive(target))
{
new m_hMyWeapons = FindSendPropOffs("CBasePlayer", "m_hMyWeapons");
for(new i = 0, weapon; i < 47; i += 4)
{
weapon = GetEntDataEnt2(target, m_hMyWeapons + i);
if(weapon > -1 )
{
SetEntityRenderMode(weapon, RENDER_TRANSCOLOR);
SetEntityRenderColor(weapon, 255, 255, 255, alpha);
}
}
}
}
public OnPostThinkPost(client) SetEntProp(client, Prop_Send, "m_iAddonBits", 0);