Raised This Month: $ Target: $400
 0% 

[Request] Access Entities via targetname


Post New Thread Reply   
 
Thread Tools Display Modes
Forlix
Senior Member
Join Date: Dec 2008
Location: Hamburg, Germany
Old 01-11-2009 , 08:59   Re: [Request] Access Entities via targetname
Reply With Quote #11

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
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...

Last edited by Forlix; 01-11-2009 at 09:04.
Forlix is offline
Send a message via ICQ to Forlix Send a message via MSN to Forlix
Fredd
Veteran Member
Join Date: Jul 2007
Old 01-11-2009 , 15:12   Re: [Request] Access Entities via targetname
Reply With Quote #12

that's almost the same thing....non networked entities usually don't have an index that's the whole point of it.
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:35.


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