diff --git a/PlayerVisibility/scripting/PlayerVisibility.sp b/PlayerVisibility/scripting/PlayerVisibility.sp index ec36bd27..766a12ca 100644 --- a/PlayerVisibility/scripting/PlayerVisibility.sp +++ b/PlayerVisibility/scripting/PlayerVisibility.sp @@ -1,5 +1,4 @@ #include -#include #include #undef REQUIRE_PLUGIN #include @@ -19,6 +18,7 @@ public Plugin myinfo = // bool CBaseEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID ) Handle g_hAcceptInput; +Handle g_hThinkTimer; ConVar g_CVar_MaxDistance; ConVar g_CVar_MinFactor; @@ -73,12 +73,25 @@ public void OnPluginStart() AutoExecConfig(true, "plugin.PlayerVisibility"); HookEvent("player_spawn", Event_Spawn, EventHookMode_Post); + HookEvent("player_death", Event_Death, EventHookMode_Post); for(int client = 1; client <= MaxClients; client++) { if(IsClientInGame(client)) OnClientPutInServer(client); } + + g_hThinkTimer = CreateTimer(0.2, Timer_Think, _, TIMER_REPEAT); +} + +public Action Timer_Think(Handle timer) +{ + for(int client = 1; client <= MaxClients; client++) + { + if(IsClientInGame(client)) + DoClientThink(client); + } + return Plugin_Continue; } public void OnAllPluginsLoaded() @@ -88,6 +101,8 @@ public void OnAllPluginsLoaded() public void OnPluginEnd() { + KillTimer(g_hThinkTimer); + for(int client = 1; client <= MaxClients; client++) { if(IsClientInGame(client)) @@ -118,7 +133,6 @@ public void OnClientPutInServer(int client) g_Client_Alpha[client] = 255; g_Client_bEnabled[client] = true; - SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost); DHookEntity(g_hAcceptInput, false, client); } @@ -227,6 +241,15 @@ public void Event_Spawn(Event event, const char[] name, bool dontBroadcast) CreateTimer(0.1, Timer_SpawnPost, client, TIMER_FLAG_NO_MAPCHANGE); } +public void Event_Death(Event event, const char[] name, bool dontBroadcast) +{ + int client = GetClientOfUserId(GetEventInt(event, "userid")); + if(!client) + return; + + g_Client_bEnabled[client] = false; +} + public Action Timer_SpawnPost(Handle timer, int client) { if(!IsClientInGame(client) || !IsPlayerAlive(client)) @@ -252,7 +275,7 @@ public void ZR_OnClientHumanPost(int client, bool respawn, bool protect) g_Client_bEnabled[client] = true; } -public void OnPostThinkPost(int client) +public void DoClientThink(int client) { if(!g_Client_bEnabled[client]) return;