I have noticed, when map start, game flush all entities which disappear right after.
So, OnEntityCreated, take entity reference and past it to next frame (or use timer 0.0).
On the next frame, look, do you get entity index from entity reference.
If you get index, then hook entity.
And entity also have correct data, because at OnEntityCreated it is... empty
*edit
I mean OnEntityCreated. Not OnEntitySpawn
*edit
Use
HookSingleEntityOutput on every round_start (or round_freeze_end).
HookEntityOutput again will work all teh time from OnPluginStart.
PHP Code:
#include <sdktools>
public void OnPluginStart()
{
HookEntityOutput("prop_door_rotating", "OnFullyOpen", OnFullyOpen);
HookEvent("round_freeze_end", round_freeze_end);
}
public void OnFullyOpen(const char[] output, int caller, int activator, float delay)
{
PrintToServer("OnFullyOpen caller %i, activator %i", caller, activator);
}
public void round_freeze_end(Event event, const char[] name, bool dontBroadcast)
{
char targetname[MAX_NAME_LENGTH];
int entity = -1;
while((entity = FindEntityByClassname(entity, "prop_door_rotating")) != INVALID_ENT_REFERENCE)
{
GetEntPropString(entity, Prop_Data, "m_iName", targetname, sizeof(targetname));
PrintToServer("%s", targetname);
// do action once and unhook
HookSingleEntityOutput(entity, "OnFullyClosed", OnFullyClosed, true);
}
}
public void OnFullyClosed(const char[] output, int caller, int activator, float delay)
{
PrintToServer("OnFullyClosed caller %i, activator %i", caller, activator);
}