Raised This Month: $32 Target: $400
 8% 

find_ent_in_sphere


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nacho312
Member
Join Date: Mar 2020
Old 03-12-2021 , 22:09   find_ent_in_sphere
Reply With Quote #1

Hi.

I'm a little bit confused
Code:
new origin[3]
    get_user_origin(id, origin, 0)
    new ent = -1
    ent = find_ent_in_sphere(ent,origin,50.0)
So basically "ent" here
Code:
 ent = find_ent_in_sphere(ent
means that we're searching for "ent" in a sphere whose radius is equal to 50?
Also, please what does this mean and why do we even have to make it "-1"
Code:
new ent = -1

Last edited by nacho312; 03-12-2021 at 22:15.
nacho312 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-12-2021 , 23:16   Re: find_ent_in_sphere
Reply With Quote #2

According to the documentation, the first argument is what entity index to start from for the search. So, setting it to -1 tells it to search all entities.
__________________
fysiks is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-13-2021 , 02:02   Re: find_ent_in_sphere
Reply With Quote #3

The last parameter is the origin to search around so you could set ent = -1 and instead do a search around an origin, not around an entity.
__________________
HamletEagle is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-13-2021 , 03:27   Re: find_ent_in_sphere
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
The last parameter is the origin to search around so you could set ent = -1 and instead do a search around an origin, not around an entity.
Huh, what? I don't think anything in that statement is true.
__________________

Last edited by fysiks; 03-13-2021 at 03:28.
fysiks is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-13-2021 , 05:01   Re: find_ent_in_sphere
Reply With Quote #5

Basically this function will iterates entity by entity depending on the given start position corresponding to the entity index will search entities distance and return the first entity that's in range.


Actually setting ent to -1 telling it to start the search from 0 which is worldspawn default entity id

If there are no entities nearby the radius it will return 0 on failure
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-13-2021 at 05:06.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 03-13-2021 , 09:28   Re: find_ent_in_sphere
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
Huh, what? I don't think anything in that statement is true.
hes thinking of find_sphere_class() which is better to use in most cases

OP what are you trying to do exactly?
jimaway is offline
nacho312
Member
Join Date: Mar 2020
Old 03-13-2021 , 10:33   Re: find_ent_in_sphere
Reply With Quote #7

Thanks alot to all of you! much appreciated guys
nacho312 is offline
nacho312
Member
Join Date: Mar 2020
Old 03-13-2021 , 10:36   Re: find_ent_in_sphere
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
According to the documentation, the first argument is what entity index to start from for the search. So, setting it to -1 tells it to search all entities.
That's exactly the thing that confuses me, what does "start from" mean? Does it mean that we are searching for it?
nacho312 is offline
nacho312
Member
Join Date: Mar 2020
Old 03-13-2021 , 11:05   Re: find_ent_in_sphere
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
The last parameter is the origin to search around so you could set ent = -1 and instead do a search around an origin, not around an entity.
Ah, that makes sense, so for example, when we set "-1", we can set a "ct player" as an origin and search around him for a "Terrorist" player?
nacho312 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-13-2021 , 11:22   Re: find_ent_in_sphere
Reply With Quote #10

If you're looking for real players within a radius you'd better just loop through all alive players with get_players and check the distance between the "center" of the sphere, origin in your case and the player current position. Off the top of my head:

Code:
new players[32], count get_players(players, count, "ah") new Float:sphere_center_pos[3] new Float:sphere_radius for (new i = 0, player, Float:pos[3]; i < count; i++) {     player = players[i]     entity_get_vector(player, EV_VEC_origin, pos)     if (get_distance_f(sphere_center_pos, pos) > sphere_radius)         continue     // player is within the radius, do something }
__________________









Last edited by CrazY.; 03-13-2021 at 11:23.
CrazY. 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 01:16.


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