View Single Post
Author Message
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 05-17-2020 , 19:44   [l4d1] Problem finding an entity by classname and targetname
Reply With Quote #1

Hello,

Im working with multiple entities, I scan all of them and I work with specific entities I need.
I filter them by classname and targetname when needed but this method is not working always.
I have no problem finding "func_door" and "func_button".
But I am having problems finding "logic_relay" and "prop_dynamic".

About prop_dynamic, I solved it using: GetEntPropString(entity, Prop_Data, "m_iName", targetname, sizeof(targetname));

PHP Code:
char classname[32], targetname[32];
    
int entity;
//scan all entities...
    
int count GetEntityCount();
    for ( 
entity=1entity<=countentity++ )
    {
        if ( 
IsValidEntity(entity) )
        {
            
GetEntityClassname(entityclassnamesizeof(classname));
            
Entity_GetTargetName(entitytargetnamesizeof(targetname));
            if ( 
strlen(targetname)==)
                
GetEntPropString(entityProp_Data"m_iName"targetnamesizeof(targetname));
        }
        else
            continue;
        
        if ( 
strcmp(classname"logic_relay")==)
        {
            
PrintToServer("STEP 0/4: logic_relay OK - - - - - - - - - - - - - - - - -");
            
GetEntPropString(entityProp_Data"m_iName"targetnamesizeof(targetname));
            if ( 
strcmp(targetname"elevator_bottom_relay")==)
            {
                
//lock doors temporary, so they dont open automatically...
                
SetVariantString("OnTrigger door_elev*:Lock::1.0:-1");
                
AcceptEntityInput(entity"AddOutput");
                
PrintToServer("STEP 1/4: elevator_bottom_relay OK - - - - - - - - - - - - - - - - -");
            }
        }
        else if ( 
strcmp(classname"func_door")==)
        {    
            
//open doors whenever they try to close...
            
SetVariantString("OnClose !self:Open::1.8:-1");
            
AcceptEntityInput(entity"AddOutput");
            
            
//prepare a horde/special infected...
            
HookSingleEntityOutput(entity"OnOpen"OnOpenFirstTimetrue);
            
PrintToServer("STEP 2/4: func_door OK - - - - - - - - - - - - - - - - -");
        }
        
//------------------------------------------------------------------------------------------------------
        
else if ( strcmp(classname"func_button")==)
        {
            if ( 
strcmp(classname"elevator_button")==)
                continue;
            
            
//we need to respawn button to make it usable again...
            //but we will Lock it to prevent firing extra panic events...
            
AcceptEntityInput(entity"Lock");
            
DispatchKeyValue(entity"wait""-1");
            
DispatchSpawn(entity);
            
            
//unlock doors...
            
SetVariantString("OnUseLocked door_elev*:Unlock::0.0:-1");
            
AcceptEntityInput(entity"AddOutput");
            
            
//open doors manually...
            
SetVariantString("OnUseLocked door_elev*:Open::0.3:-1");
            
AcceptEntityInput(entity"AddOutput");
            
PrintToServer("STEP 3/4: func_button OK - - - - - - - - - - - - - - - - -");
        }
        
//------------------------------------------------------------------------------------------------------
        
else if ( strcmp(classname"prop_dynamic")==)
        {
            
GetEntPropString(entityProp_Data"m_iName"targetnamesizeof(targetname));
            if ( 
strcmp(targetname"elevator_model")==)
            {
                
RemoveEntity(entity);
                
PrintToServer("STEP 4/4: prop_dynamic::elevator_model OK - - - - - - - - - - - - - - - - -");
            }
            
/*else
            {
                PrintToServer("STEP 4/4 FAIL: TEST: %s - - - - - - - - - - - - - - - - -", test);
            }*/
        
}
        else
            continue;    
    } 
PHP Code:
stock char[] Entity_GetTargetName(int entitychar[] bufferint size)
{
    return 
GetEntPropString(entityProp_Data"m_target"buffersize);

But I am not able to get logic_relay with this method.
I can only get it like this:
PHP Code:
entity INVALID_ENT_REFERENCE;
    while ( (
entity=FindEntityByClassname(entity"logic_relay"))!=INVALID_ENT_REFERENCE )
    {
        
GetEntPropString(entityProp_Data"m_iName"classnamesizeof(classname));
        if ( 
strcmp(classname"elevator_bottom_relay")==)
        {
            
//lock doors temporary, so they dont open automatically...
            
SetVariantString("OnTrigger door_elev*:Lock::1.0:-1");
            
AcceptEntityInput(entity"AddOutput");
            break;
        }
    } 
This is the only way I could find logic_relay. But I don't think it is the best way because I am scanning all entities twice. Does logic_relay have an special prop for classname and targetname?? m_iName didn't work.

NOTE: In this example, m_iName is set for logic_relay. But if I try to find it on above example, m_iName is never set to elevator_bottom_relay

Last edited by axelnieves2012; 05-17-2020 at 21:53.
axelnieves2012 is offline