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

Solved [HELP] Finding Players Around Point


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 09-06-2019 , 13:38   [HELP] Finding Players Around Point
Reply With Quote #1

I'm looking for a way of finding players around a point where a shot has landed, much like the find_sphere_class function. However, that function uses an entity instead of coordinates, which I plan to get from Ham_TraceAttack.

Anyone know a way? Been searching for 2 days now but all I get are normal get_players functions, nothing relevant...
__________________

Last edited by hellmonja; 09-10-2019 at 08:51.
hellmonja is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 09-06-2019 , 13:59   Re: [HELP] Finding Players Around Point
Reply With Quote #2

https://www.amxmodx.org/api/amxmodx/get_user_origin mode = 4
https://www.amxmodx.org/api/engine/find_ent_in_sphere
__________________
My English is A0
E1_531G is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 09-06-2019 , 14:01   Re: [HELP] Finding Players Around Point
Reply With Quote #3

You could try hooking FM_TraceLine with get_tr2 and retrieving the end vector (TR_vecEndPos), and then checking in the radius of the float that you stored the result of get_tr2.
__________________

Last edited by edon1337; 09-06-2019 at 14:05.
edon1337 is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 09-06-2019 , 14:06   Re: [HELP] Finding Players Around Point
Reply With Quote #4

Wait, I've seen find_ent_in_sphere before. But what I don't get is what use start_from_ent if you already have an origin to base something around? And should the start_from_ent the shooter?...
__________________
hellmonja is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 09-06-2019 , 14:09   Re: [HELP] Finding Players Around Point
Reply With Quote #5

Quote:
Originally Posted by edon1337 View Post
You could try hooking FM_TraceLine with get_tr2 and retrieving the end vector (TR_vecEndPos), and then checking in the radius of the float that you stored the result of get_tr2.
Thank you. I can't honestly say I understand it. I would like some sample codes but if that's too much spoon-feeding in your opinion, I will try to study the method. Either way, I very much appreciate the lead...
__________________
hellmonja is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-06-2019 , 14:16   Re: [HELP] Finding Players Around Point
Reply With Quote #6

Hook Ham_TraceAttack, get the TR_vecEndPos and use the following code to search for players within a radius.

PHP Code:
#include <engine>

...

#if !defined MAX_PLAYERS
    #define MAX_PLAYERS 32
#endif

...

get_players_in_radius(players[MAX_PLAYERS], &num, const Float:origin[3], const Float:radius)
{
    
// a - Do not include dead players
    // h - Do not include HLTV proxies
    
new _players[MAX_PLAYERS], _num;
    
get_players(_players_num"ah");

    
num 0;

    for (new 
0playerFloat:_origin[3]; _numi++)
    {
        
player _players[i];
        
entity_get_vector(playerEV_VEC_origin_origin);

        if (
vector_distance(origin_origin) > radius)
            continue;

        
players[num] = player;
        
num++;
    }
}

...

// Usage example
new players[MAX_PLAYERS], numFloat:origin[3];
get_players_in_radius(playersnumorigin240.0); 
__________________









Last edited by CrazY.; 09-06-2019 at 14:19.
CrazY. is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 09-06-2019 , 14:25   Re: [HELP] Finding Players Around Point
Reply With Quote #7

Quote:
Originally Posted by CrazY. View Post
Hook Ham_TraceAttack, get the TR_vecEndPos and use the following code to search for players within a radius.

PHP Code:
#include <engine>

...

#if !defined MAX_PLAYERS
    #define MAX_PLAYERS 32
#endif

...

get_players_in_radius(players[MAX_PLAYERS], &num, const Float:origin[3], const Float:radius)
{
    
// a - Do not include dead players
    // h - Do not include HLTV proxies
    
new _players[MAX_PLAYERS], _num;
    
get_players(_players_num"ah");

    
num 0;

    for (new 
0playerFloat:_origin[3]; _numi++)
    {
        
player _players[i];
        
entity_get_vector(playerEV_VEC_origin_origin);

        if (
vector_distance(origin_origin) > radius)
            continue;

        
players[num] = player;
        
num++;
    }
}

...

// Usage example
new players[MAX_PLAYERS], numFloat:origin[3];
get_players_in_radius(playersnumorigin240.0); 
I will try this next, thank you. Right after I've fiddled enough with what E1_531G suggested. I think he meant using both functions. I'm still new to vectors, origins, velocities and all that so I want to experiment with as much methods as I can...
__________________
hellmonja is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 09-06-2019 , 15:35   Re: [HELP] Finding Players Around Point
Reply With Quote #8

Quote:
Originally Posted by hellmonja View Post
Wait, I've seen find_ent_in_sphere before. But what I don't get is what use start_from_ent if you already have an origin to base something around? And should the start_from_ent the shooter?...
For the first search you use start_from_ent = -1, but when you need to find more than one ent you have to use start_from_ent = index-of-the-previous-ent for the 2nd and next searches. (if not doing this, it will find the same ent every time).

And yes, get_user_origin() wint mode = 4 will return the position (origin) of last bullet hit.
__________________
My English is A0
E1_531G is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-06-2019 , 15:54   Re: [HELP] Finding Players Around Point
Reply With Quote #9

find_ent_by_sphere loop through all entities in the game and mine only through players. Not a big deal but it takes less process.
__________________








CrazY. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-06-2019 , 18:33   Re: [HELP] Finding Players Around Point
Reply With Quote #10

Take a look at this. It's not entirely what you're doing, but maybe you can take something from it.

https://forums.alliedmods.net/showthread.php?t=318524
__________________
Bugsy is offline
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 04:01.


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