AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [HELP] Finding Players Around Point (https://forums.alliedmods.net/showthread.php?t=318548)

hellmonja 09-06-2019 13:38

[HELP] Finding Players Around Point
 
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...

E1_531G 09-06-2019 13:59

Re: [HELP] Finding Players Around Point
 
https://www.amxmodx.org/api/amxmodx/get_user_origin mode = 4
https://www.amxmodx.org/api/engine/find_ent_in_sphere

edon1337 09-06-2019 14:01

Re: [HELP] Finding Players Around Point
 
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.

hellmonja 09-06-2019 14:06

Re: [HELP] Finding Players Around Point
 
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 09-06-2019 14:09

Re: [HELP] Finding Players Around Point
 
Quote:

Originally Posted by edon1337 (Post 2666089)
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...

CrazY. 09-06-2019 14:16

Re: [HELP] Finding Players Around Point
 
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); 


hellmonja 09-06-2019 14:25

Re: [HELP] Finding Players Around Point
 
Quote:

Originally Posted by CrazY. (Post 2666095)
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...

E1_531G 09-06-2019 15:35

Re: [HELP] Finding Players Around Point
 
Quote:

Originally Posted by hellmonja (Post 2666092)
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.

CrazY. 09-06-2019 15:54

Re: [HELP] Finding Players Around Point
 
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.

Bugsy 09-06-2019 18:33

Re: [HELP] Finding Players Around Point
 
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


All times are GMT -4. The time now is 06:34.

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