AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Find players near given origin?> (https://forums.alliedmods.net/showthread.php?t=223905)

AwesomeMan 08-18-2013 09:36

Find players near given origin?>
 
Hey, I'm just wondering How would I find players (i dont need index, just amount is enough) within given origin. Basically, let's say the origin is 0.0.0 and I want to find if there is any players within 500m near the origin. So, if the origin is 0.0.0 but a player is at 499.0.0 it would detect him, but if he would be at 501.0.0 it wouldnt. How can i do that?

Arkshine 08-18-2013 09:51

Re: Find players near given origin?>
 
Well, there is several ways.

- Using one native :

new playersList[32];
new playersCount = find_sphere_class( 0, "player", RADIUS, playersList, sizeof playersList, ORIGIN );

- Possible to loop with find_ent_in_sphere() and counting.
-There is also looping among all players and checking each origin distance.

The first is probably the most efficient.

AwesomeMan 08-18-2013 10:07

Re: Find players near given origin?>
 
Thank you Arkshine :D
I will try it, if I get any problems I will reply back :D
Cheers!

AwesomeMan 08-18-2013 11:00

Re: Find players near given origin?>
 
new playersCount = find_sphere_class( 0, "player", 500.0, playersList, sizeof playersList, origin );

It gives me tag mismatch error when compiling.

Arkshine 08-18-2013 11:17

Re: Find players near given origin?>
 
what is "origin" ? It should be a Float.

AwesomeMan 08-18-2013 11:23

Re: Find players near given origin?>
 
It location that is read from file.
set_user_origin(id, origin)
works.

origin[0] = str_to_num(a)
origin[1] = str_to_num(b)
origin[2] = str_to_num(c)

this is what i use to get the origin

How can I transform the origin[0/1/2] to a float?

Arkshine 08-18-2013 11:47

Re: Find players near given origin?>
 
Make origin a float.

new Float:origin[3];

and use str_to_float(a) etc.

AwesomeMan 08-18-2013 12:02

Re: Find players near given origin?>
 
new float:porigin[3];
porigin[0] = str_to_float(a);
porigin[1] = str_to_float(b);
porigin[2] = str_to_float(c);

It gives me tag mismatch error on porigin[*] = str_to_float(*);
For each one. What am I doing wrong here, can't seem to figure out

Arkshine 08-18-2013 12:03

Re: Find players near given origin?>
 
Float: not float:

Case is sensitive.

AwesomeMan 08-18-2013 12:10

Re: Find players near given origin?>
 
That fix the issue. Thank you very much!


All times are GMT -4. The time now is 15:54.

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