View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-05-2020 , 15:34   Re: [CS:GO] OnEntityCreated + SDKSpawn
Reply With Quote #2

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[] outputint callerint activatorfloat delay)
{
    
PrintToServer("OnFullyOpen caller %i, activator %i"calleractivator);
}

public 
void round_freeze_end(Event event, const char[] namebool dontBroadcast)
{
    
char targetname[MAX_NAME_LENGTH];
    
int entity = -1;
    
    while((
entity FindEntityByClassname(entity"prop_door_rotating")) != INVALID_ENT_REFERENCE)
    {
        
GetEntPropString(entityProp_Data"m_iName"targetnamesizeof(targetname));
        
PrintToServer("%s"targetname);
        
        
// do action once and unhook
        
HookSingleEntityOutput(entity"OnFullyClosed"OnFullyClosedtrue);
    }
}

public 
void OnFullyClosed(const char[] outputint callerint activatorfloat delay)
{
    
PrintToServer("OnFullyClosed caller %i, activator %i"calleractivator);


Last edited by Bacardi; 10-05-2020 at 16:32.
Bacardi is offline