View Single Post
Author Message
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 10-05-2020 , 15:12   [CS:GO] OnEntityCreated + SDKSpawn
Reply With Quote #1

PHP Code:

public void OnEntityCreated(int entity, const char[] classname)
{
    
SDKHook(entitySDKHook_SpawnSDK_OnEntitySpawn);
}

public 
Action SDK_OnEntitySpawn(int entity)
{
    if (
entity < -1)
    {
        
entity EntRefToEntIndex(entity);
        if (
entity == INVALID_ENT_REFERENCE)
        {
            return 
Plugin_Continue;
        }
    }

    
// here for func_door, door_rotating and movelinear I do this: 
t    // there are some validations, I removed them for this example
    
HookSingleEntityOutput(entity"OnFullyOpen"Output_OnDoorStateChange);
}

public 
void Output_OnDoorStateChange(const char[] outputint callerint activatorfloat delay)
{
    
// here print something for testing purpose

So for func_door, Output_OnDoorStateChange prints the message in most cases, but sometimes it doesn't print anything.
I think there's a problem with entity validation, maybe it's not valid here? Maybe the entity is a reference and if (entity == INVALID_ENT_REFERENCE) return true?

How can I hook entity spawn for every entity? OnEntityCreated doesn't work with func_brushes, I did some testing with it, and I had to do an iteration on round_start.

Also I replaced HookSingleEntityOutput with HookEntityOutput, I hope it will work for my entities and will not trigger different ones (for func_button, HookEntityOutput - OnPressed triggers another entity as well).
__________________
Ilusion9 is offline