FixPointViewcontrol: Don't disable point_viewcontrol upon player death or disconnect

There was no need to!
This commit is contained in:
xen 2022-10-25 04:46:35 +02:00
parent e99e69dfff
commit d4b13021b2

View File

@ -9,19 +9,15 @@
public Plugin myinfo = public Plugin myinfo =
{ {
name = "FixPointViewcontrol", name = "FixPointViewcontrol",
author = "xen + BotoX", author = "xen",
description = "", description = "A plugin to make disabling point_viewcontrol work properly",
version = "1.0", version = "1.1",
url = "" url = ""
} }
Handle g_hAcceptInput; Handle g_hAcceptInput;
int g_iAttachedViewControl[MAXPLAYERS + 1] = {INVALID_ENT_REFERENCE, ...};
public void OnPluginStart() public void OnPluginStart()
{ {
HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
// Gamedata. // Gamedata.
Handle hConfig = LoadGameConfigFile("sdktools.games"); Handle hConfig = LoadGameConfigFile("sdktools.games");
if (hConfig == INVALID_HANDLE) if (hConfig == INVALID_HANDLE)
@ -42,35 +38,10 @@ public void OnPluginStart()
DHookAddParam(g_hAcceptInput, HookParamType_Int); DHookAddParam(g_hAcceptInput, HookParamType_Int);
} }
public Action Event_PlayerDeath(Handle hEvent, const char[] szName, bool bDontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
DisableViewControl(client);
}
public void OnClientDisconnect(int client)
{
DisableViewControl(client);
}
void DisableViewControl(int client)
{
if (g_iAttachedViewControl[client] == INVALID_ENT_REFERENCE)
return;
int entity = EntRefToEntIndex(g_iAttachedViewControl[client]);
if (entity == INVALID_ENT_REFERENCE)
return;
AcceptEntityInput(entity, "Disable", client, entity);
}
public void OnEntityCreated(int entity, const char[] classname) public void OnEntityCreated(int entity, const char[] classname)
{ {
if (StrEqual(classname, "point_viewcontrol")) if (StrEqual(classname, "point_viewcontrol"))
{
DHookEntity(g_hAcceptInput, false, entity); DHookEntity(g_hAcceptInput, false, entity);
}
} }
public MRESReturn Hook_AcceptInput(int entity, Handle hReturn, Handle hParams) public MRESReturn Hook_AcceptInput(int entity, Handle hReturn, Handle hParams)
@ -85,16 +56,8 @@ public MRESReturn Hook_AcceptInput(int entity, Handle hReturn, Handle hParams)
if (iActivator < 1 || iActivator > MaxClients) if (iActivator < 1 || iActivator > MaxClients)
return MRES_Ignored; return MRES_Ignored;
if (StrEqual(sCommand, "Enable", false))
{
g_iAttachedViewControl[iActivator] = EntIndexToEntRef(entity);
}
else if (StrEqual(sCommand, "Disable", false)) else if (StrEqual(sCommand, "Disable", false))
{
SetEntPropEnt(entity, Prop_Data, "m_hPlayer", iActivator); SetEntPropEnt(entity, Prop_Data, "m_hPlayer", iActivator);
g_iAttachedViewControl[iActivator] = INVALID_ENT_REFERENCE;
}
return MRES_Ignored; return MRES_Ignored;
} }