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[] name, bool dontBroadcast)
{
static char sMap[32], sName[64];
int entity = -1;
GetCurrentMap(sMap, sizeof(sMap));
if (strcmp(sMap, "l4d_hospital04_interior") == 0)
{
while (-1 != (entity = FindEntityByClassname(entity, "func_button")))
{
GetEntPropString(entity, Prop_Data, "m_iName", sName, sizeof(sName));
if (strcmp(sName, "elevator_button") == 0)
{
HookSingleEntityOutput(entity, "OnPressed", OnButtonAction, true);
break;
}
}
}
}
void OnButtonAction(const char[] output, int caller, int activator, float delay)
{
// some code
}
__________________