I wrote this function to do the job:
PHP Code:
stock FindEntityByTargetname(const String:targetname[], const String:classname[])
{
decl String:namebuf[32];
new index = -1;
namebuf[0] = '\0';
while(strcmp(namebuf, targetname) != 0
&& (index = FindEntityByClassname(index, classname)) != -1)
GetEntPropString(index, Prop_Data, "m_iName", namebuf, sizeof(namebuf));
return(index);
}
Should be pretty efficient.
However, I have a slight guess that StrEqual is faster than strcmp for checking if strings are equal, so if anyone can confirm this please, as I am too lazy to benchmark them
The function returns either the index of the first entity found by that targetname, or -1 if not found.
And of course this is also limited to entities that have an index, but it works well for stuff like physics objects or triggers...