View Single Post
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 04-23-2020 , 02:14   Re: [L4D1] Door-less elevator at No Mercy [APRIL/2020]
Reply With Quote #7

The code is very non-optimized.

I would suggest to hook "player_use" only when map is "l4d_hospital04_interior" instead of checking it constantly.
You can use OnMapStart forward to do that.

Anyway, "player_use" is also fire too often. It's inefficient to make the check everytime.
Instead you could just hook exactly that entity. If you decide to follow this way, some entities could not initialize yet at map start stage so "round_freeze_end" is preferrable.

PHP Code:
public void OnPluginStart()
{
    
HookEvent("round_freeze_end",         Event_RoundFreezeEnd,    EventHookMode_PostNoCopy);
}

public 
void Event_RoundFreezeEnd(Event event, const char[] namebool dontBroadcast)
{
    static 
char sMap[32], sName[64];
    
int entity = -1;
    
    
GetCurrentMap(sMapsizeof(sMap));
    
    if (
strcmp(sMap"l4d_hospital04_interior") == 0)
    {
        while (-
!= (entity FindEntityByClassname(entity"func_button")))
        {
            
GetEntPropString(entityProp_Data"m_iName"sNamesizeof(sName));
            if (
strcmp(sName"elevator_button") == 0)
            {
                
HookSingleEntityOutput(entity"OnPressed"OnButtonActiontrue);
                break;
            }
        }
    }
}

void OnButtonAction(const char[] outputint callerint activatorfloat delay)
{
    
// some code

__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline