Raised This Month: $12 Target: $400
 3% 

[HOWTO] Finding Entites


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-24-2006 , 21:37   [HOWTO] Finding Entites
Reply With Quote #1

This is a duplicate of the thread I made in AMWiki located here: http://wiki.tcwonline.org/index.php/...28AMX_Mod_X%29

Introduction

It is sometimes necessary to find an entity in the world for some reason. For example, you may need to find a button in the world, and then remove it (this example will be covered later). This article will explain how to do so.


Functions

There are a number of functions built into AMX Mod X / AMXX Modules that allow you to find entities. For a complete list, please consult this page: http://www.amxmodx.org/funcwiki.php?..._ent&go=search
(As of last edit, these are the functions included):
  • find_ent_by_class
  • find_ent_by_model
  • find_ent_by_owner
  • find_ent_by_target
  • find_ent_by_tname
  • find_ent_in_sphere
  • find_sphere_class

find_ent_by_class

<Function is included in Engine>
This function allows you to find an entity based on it's classname. All entities have classnames. For example, a player's classname is "player", while a button is either "func_button" or "func_rot_button".
To find an entity using this, one would simply use the following:

Code:
find_ent_by_class(-1,"classname_to_find");

find_ent_by_model

<Function is included in Engine>
This function can be used to find an entity based on its model. Some entities do not have models, meaning they cannot be found using this method. Also, it is, most of the time, better to use another type of ent finding, as this can be highly inaccurate and be broken by something as simple as a model changing plugin. This function also takes into account the class name, and is generally used more for isolating a certain model from a set of classnames (ex you have 3 grenades, with different models, and want to find 1 of them)
To find an entity using this, one would use the following:

Code:
find_ent_by_model(-1,"classname_to_find","model_to_find")

find_ent_by_owner

<Function is included in Engine>
This function can be used to find an entity based on an owner. For example, if there is a player in the world, and you want to find if he has thrown a grenade out, you would use this and check for "grenade" entities that's owner is the player. Note: planted C4 (in CS) also have "grenade" classname.
To find an entity using this, one would use the following:

Code:
find_ent_by_owner(-1,"classname_to_find",owner_id,0);
Notice the last parameter. This is a mode to find in. To see a full list, consult this page: http://www.amxmodx.org/funcwiki.php?go=func&id=345


find_ent_by_target

<Function is included in Engine>
This function allows one to find an entity based on its target. This function also checks for classname.
To find an entity using this, one would use the following:

Code:
find_ent_by_target(-1,"classname_to_find");

find_ent_by_tname

<Function is included in Engine> This essentially functions the same as find_ent_by_target.


find_ent_in_sphere

<Function is included in Engine>
This function can be used to find an entity within a certain distance of another entity. This can be quite handy to, for example, see if a player is around another player, and then deal damage or slap that player. This is effectively a shortcut to using find_ent_by_class and get_distance(_f) together.
To find an entity using this, one would use the following:

Code:
find_ent_in_sphere(-1,location_of_ent_vector,radius_float);

find_sphere_class

This function is probably the most complex of all the find_ent functions. This allows you to find an entity inside a certain radius of another entity, with a certian classname. This is effectively a shortcut to using find_ent_by_class & get_distance & entity_get_string(ent,EV_SZ_classname... or find_ent_in_sphere & entity_get_string(ent,EV_SZ_classname...
To find an entity using this, one would use the following:

Code:
new entlist[513]; find_sphere_class(0,"classname_to_find",radius_float,entlist,512,origin_vector);
Also, note that origin_vector and the first parameter (_aroundent) should not both be specified. If _aroundent is specified as 0, origin_vector is used. If origin_vector is not specified, or is 0, then _aroundent is used.


Looping

If, for example, one wants to loop one of these, it is quite simple to do so.
Example:

Code:
while((ent = find_ent_by_class(ent,"classname_to_find") != 0) {     // do whatever }
This will find every entity with classname "classname_to_find" and then execute the "// do whatever" code every time it finds one.


Wrap Up

For complete usage, please consult the Engine Module page at: http://www.amxmodx.org/funcwiki.php?go=module&id=3
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 06-24-2006 , 23:49   Re: Finding Entites
Reply With Quote #2

Nice..thanks for the tut..gunna use in my plugins.
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Old 08-14-2006, 15:39
Hawk552
This message has been deleted by Hawk552.
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-14-2006 , 17:59   Re: Finding Entites
Reply With Quote #3

there is no way to scan with aroundent 0 and origin 0, unless you want to search from origin 0,0,0, which I can't imagine you'd want to do

find_sphere_class is probably not the function you want, you probably want find_ent_by_class.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-14-2006 , 20:01   Re: Finding Entites
Reply With Quote #4

...no. Origin is a vector. That means that it's a coordinate on the map somewhere.

A vector is represented through 3 cells, usually as floats. When dealing with coordinates, it basically looks like this:

Code:
new Float:Vector[3] Vector[0] // this is the x value (left/right) Vector[1] // this is the y value (forward/back) Vector[2] // this is the z value (up/down)

It isn't exactly like that per se (since if you're looking in different directions they're not really left/right and forward/back) but that's as close a representation I can give with text.

Here's how you represent a static vector:
Code:
Float:{100.0,-300.0,400.0}

which means x is 100, y is -300, z is 400, etc.

This param in the function find_sphere_class is used when you want to search around a location where there is no ent, such as the point a player is aiming at. I've only used this function like twice before, and once was to make an explosion effect around a location that a player was looking (using origin and not _aroundent), and another was finding players around a player when they used a command (using _aroundent and not origin).
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-15-2006 , 21:14   Re: Finding Entites
Reply With Quote #5

For some reason, the user who I was talking to felt the urge to delete all of his posts. I'm just posting this so it doesn't look like I was either bumping this thread or talking to myself.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 08-15-2006 , 22:28   Re: Finding Entites
Reply With Quote #6

Quote:
Originally Posted by Hawk552 View Post
For some reason, the user who I was talking to felt the urge to delete all of his posts. I'm just posting this so it doesn't look like I was either bumping this thread or talking to myself.
lmao, I thought you were talking to yourself when I saw all that.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 08-16-2006 , 02:02   Re: Finding Entites
Reply With Quote #7

Quote:
Originally Posted by Hawk552 View Post
For some reason, the user who I was talking to felt the urge to delete all of his posts. I'm just posting this so it doesn't look like I was either bumping this thread or talking to myself.
And you are "the other user" ?
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-16-2006 , 11:01   Re: Finding Entites
Reply With Quote #8

Quote:
Originally Posted by gangstatothecore View Post
no BAILOPAN decided to delete his posts . How about a section on setting entities and origons for entitys and all that good stuff?
No, for 3 reasons:

1) That's not what this tutorial is for.
2) That's simple to learn.
3) You're probably raphero.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
hmrsmpsn
Senior Member
Join Date: Nov 2005
Location: sWeDeN YEEAAAH!!!
Old 08-17-2006 , 17:05   Re: Finding Entites
Reply With Quote #9

i like those reasons
__________________



new Float:second = 1.0
new Float:minute = 60*second
new Float:hour = 60*minute
new Float:day = 24*hour
new Float:year = 365*day
set_task(10.0*years,"clean_my_room")
hmrsmpsn is offline
Old 09-22-2006, 01:27
k007
This message has been deleted by k007. Reason: nvm someone else showed me how
Reply


Thread Tools
Display Modes

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 00:38.


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