AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Request] Access Entities via targetname (https://forums.alliedmods.net/showthread.php?t=71972)

Forlix 01-11-2009 08:59

Re: [Request] Access Entities via targetname
 
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(namebuftargetname) != 0
    
&& (index FindEntityByClassname(indexclassname)) != -1)
    
GetEntPropString(indexProp_Data"m_iName"namebufsizeof(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 :wink:
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...

Fredd 01-11-2009 15:12

Re: [Request] Access Entities via targetname
 
that's almost the same thing....non networked entities usually don't have an index that's the whole point of it.


All times are GMT -4. The time now is 18:08.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.