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)

Obbi 05-28-2008 10:33

[Request] Access Entities via targetname
 
I could need some help with the Entity I/O System. I'd like to send Inputs to an Entity with a predefined targetname. Is there any way to do this? Something that does the same as this example: ent_fire blobb kill Problem is, dedicated Server don't support ent_fire and the Sourcemod Entity Input System is kinda weird. It requires an Index, but I cannot figure it out, how to get it.

L. Duke 05-28-2008 11:03

Re: [Request] Access Entities via targetname
 
In general terms, you need to loop through all of the entities (up to GetEntityCount) and check the targetname of the each entity. I believe you can use GetEntPropString to find the the m_target property. If the string returned matches your name (example: blobb) then use the AcceptEntityInput function to send the input (such as kill).

Obbi 05-28-2008 13:03

Re: [Request] Access Entities via targetname
 
Thx Duke, i am goin try this ;)

Fredd 05-28-2008 14:56

Re: [Request] Access Entities via targetname
 
you will still only be limited to edicts....

Obbi 05-28-2008 15:53

Re: [Request] Access Entities via targetname
 
What's the difference? And it seems, that it doesn't work. Maybe i am to stupid to compare the strings... :( Its really frustrating...

Fredd 05-28-2008 16:33

Re: [Request] Access Entities via targetname
 
edicts are networked entities just like players and most visible entities you could see in a game, there is entities like env_fog_controller which is not networked there for it doesn't have an edict, if it doesn't have an index then it doesn't have an index(integer #) therefor you can't really find that type of entities for now until the sourcemod dev team adds the feature to be able deal with non-networked entities...

Obbi 05-28-2008 16:42

Re: [Request] Access Entities via targetname
 
D'oh! Okay then I'll have to wait for this. I need access to an logic_relay and I am really sure that I cannot access these by now. So far, thx for ur help.

L. Duke 05-28-2008 18:08

Re: [Request] Access Entities via targetname
 
You can use my extension to add events to the event queue (basically exactly what ent_fire does): http://forums.alliedmods.net/showthread.php?t=69658

logic_auto has an entity index, but as Fredd said, I don't think logic_relays do.

You can easily do inputs on entities with the extension, something like:
Code:

dhEntFire("blobb", "kill", "", 0.0);
would remove all entities with a targetname of "blobb." You can also target entity types such as "player" or "logic_relay" (yes logic_relay works in this instance even if you can't reference it for SM functions).

Obbi 05-28-2008 20:43

Re: [Request] Access Entities via targetname
 
Thx :) But i may not be able to use it. I am working on hl2mp...

Obbi 07-04-2008 10:11

Re: [Request] Access Entities via targetname
 
I dont want to annoy but... It is important. Anybody? btw. LDuke, could u pls upload the sources 4 your Dukehacks?! Maybe there's a way to use the code for hl2mp.

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.