View Single Post
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 08-14-2020 , 14:25   Re: Hook one entity button
Reply With Quote #4

There's a lot of methods to determine entity index.
You can use FindEntityByClassname but this can find ANY entity with specified classname (you should put some additional checks to limit your searching).
You can also retrieve entity's targetname (or HammerID) and then do a loop to find specific entity:
Code:
#define TARGETNAME "PUT TARGETNAME HERE"

char sName[50];
int iEntity = MaxClients + 1;
while ( ( iEntity = FindEntityByClassname( iEntity, "func_button" ) ) != -1 ) {
	GetEntPropString( iEntity, Prop_Data, "m_iName", sName, sizeof( sName) );
	if ( strcmp( sName, TARGETNAME ) == 0 ) {
		HookSingleEntityOutput( iEntity, "OnPressed", MyCallback );
		break;
	}
}
__________________

Last edited by MAGNAT2645; 08-14-2020 at 14:29.
MAGNAT2645 is offline