Fix output hooks when caller/activator are flipped (#1411)

Co-authored-by: Asher Baker <[email protected]>
This commit is contained in:
Vladimir
2021-07-17 15:30:09 +01:00
committed by GitHub
co-authored by Asher Baker
parent 4d6b9895d3
commit 54364d213d
3 changed files with 103 additions and 19 deletions
+51 -8
View File
@@ -1,7 +1,7 @@
#include <sourcemod>
#include <sdktools>
public Plugin:myinfo =
public Plugin myinfo =
{
name = "Entity Output Hook Testing",
author = "AlliedModders LLC",
@@ -10,32 +10,70 @@ public Plugin:myinfo =
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
public void OnPluginStart()
{
HookEntityOutput("point_spotlight", "OnLightOn", OutputHook);
HookEntityOutput("point_spotlight", "OnLightOff", OutputHook);
HookEntityOutput("func_door", "OnOpen", OutputHook);
HookEntityOutput("func_door_rotating", "OnOpen", OutputHook);
HookEntityOutput("prop_door_rotating", "OnOpen", OutputHook);
HookEntityOutput("func_door", "OnClose", OutputHook);
HookEntityOutput("func_door_rotating", "OnClose", OutputHook);
HookEntityOutput("prop_door_rotating", "OnClose", OutputHook);
if (GetEngineVersion() == Engine_CSGO) {
// The server library calls with output names from Activator (from "plated_c4" activator entity in current example).
HookEntityOutput("planted_c4", "OnBombBeginDefuse", OutputHook);
HookEntityOutput("planted_c4", "OnBombDefuseAborted", OutputHook);
// Never fired for planted_c4, only planted_c4_training.
HookEntityOutput("planted_c4", "OnBombDefused", OutputHook);
}
}
public OutputHook(const String:name[], caller, activator, Float:delay)
public void OutputHook(const char[] name, int caller, int activator, float delay)
{
LogMessage("[ENTOUTPUT] %s", name);
char callerClassname[64];
if (caller >= 0 && IsValidEntity(caller)) {
GetEntityClassname(caller, callerClassname, sizeof(callerClassname));
}
char activatorClassname[64];
if (activator >= 0 && IsValidEntity(activator)) {
GetEntityClassname(activator, activatorClassname, sizeof(activatorClassname));
}
LogMessage("[ENTOUTPUT] %s (caller: %d/%s, activator: %d/%s)", name, caller, callerClassname, activator, activatorClassname);
}
public OnMapStart()
public void OnMapStart()
{
new ent = FindEntityByClassname(-1, "point_spotlight");
int ent = FindEntityByClassname(-1, "point_spotlight");
if (ent == -1)
{
LogError("Could not find a point_spotlight");
LogMessage("[ENTOUTPUT] Could not find a point_spotlight");
ent = CreateEntityByName("point_spotlight");
DispatchSpawn(ent);
}
LogMessage("[ENTOUTPUT] Begin basic");
AcceptEntityInput(ent, "LightOff");
AcceptEntityInput(ent, "LightOn");
AcceptEntityInput(ent, "LightOff", .caller = ent);
AcceptEntityInput(ent, "LightOn", .caller = ent);
AcceptEntityInput(ent, "LightOff", .activator = ent);
AcceptEntityInput(ent, "LightOn", .activator = ent);
AcceptEntityInput(ent, "LightOff", ent, ent);
AcceptEntityInput(ent, "LightOn", ent, ent);
LogMessage("[ENTOUTPUT] End basic, begin once");
HookSingleEntityOutput(ent, "OnLightOn", OutputHook, true);
HookSingleEntityOutput(ent, "OnLightOff", OutputHook, true);
@@ -44,16 +82,21 @@ public OnMapStart()
AcceptEntityInput(ent, "LightOff", ent, ent);
AcceptEntityInput(ent, "LightOn", ent, ent);
LogMessage("[ENTOUTPUT] End once, begin single");
HookSingleEntityOutput(ent, "OnLightOn", OutputHook, false);
HookSingleEntityOutput(ent, "OnLightOff", OutputHook, false);
AcceptEntityInput(ent, "LightOff", ent, ent);
AcceptEntityInput(ent, "LightOn", ent, ent);
AcceptEntityInput(ent, "LightOff", ent, ent);
AcceptEntityInput(ent, "LightOn", ent, ent);
//Comment these out (and reload the plugin heaps) to test for leaks on plugin unload
// Comment these out (and reload the plugin heaps) to test for leaks on plugin unload
UnhookSingleEntityOutput(ent, "OnLightOn", OutputHook);
UnhookSingleEntityOutput(ent, "OnLightOff", OutputHook);
LogMessage("[ENTOUTPUT] End single");
}