AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Find player using find_ent_in_sphere (https://forums.alliedmods.net/showthread.php?t=216380)

Kia 05-20-2013 10:41

Find player using find_ent_in_sphere
 
Hello,

I'd like to find a player(2) using. find_ent_in_sphere and hurt the player(1) when the other player(2) has a boolean on true.
Anyone knows how to do that?

didoWEE 05-20-2013 11:55

Re: Find player using find_ent_in_sphere
 
PHP Code:

new Float:origin[3];
entity_get_vector(player1EV_VEC_originorigin);

new 
player2 = -1;
    
while((
player2 find_ent_in_sphere(player2originTHE_RADIUS_YOU_WANT)) != 0)
{
    if(!
is_user_connected(player2)) continue;
    if(!
is_user_alive(player2)) continue;
    if(!
g_bTHE_BOOL_YOU_WANT[player2]) continue;
    
    
ExecuteHam(Ham_TakeDamageplayer10player2THE_DAMAGE_YOU_WANT);
}

/**************************************
*** Easier way to understand ***
**************************************/

new Float:origin[3];
entity_get_vector(player1EV_VEC_originorigin);

new 
player2 = -1;
    
while((
player2 find_ent_in_sphere(player2originTHE_RADIUS_YOU_WANT)) != 0)
{
    if(
is_user_connected(player2))
    {
        if(
is_user_alive(player2))
        {
            if(
g_bTHE_BOOL_YOU_WANT[player2])
            {
                
ExecuteHam(Ham_TakeDamageplayer10player2THE_DAMAGE_YOU_WANT);
            }
        }
    }



Kia 05-20-2013 12:29

Re: Find player using find_ent_in_sphere
 
Thanks.


//EDIT : Doesn't work for me :(

Kia 05-20-2013 16:52

AW: Find player using find_ent_in_sphere
 
My bad, had a typo, it's working.

ConnorMcLeod 05-20-2013 17:28

Re: Find player using find_ent_in_sphere
 
Use find_sphere_class is far more efficient.
It's like using get_players instead of looping all possible players.

PHP Code:

HurtPlayersInUserSphere(idFloat:radiusdamageetc...)
{
    new 
players[32], playernum find_sphere_class(id"player"radiusplayerssizeof(players));
    for(--
numnum>=0num--)
    {
        
player players[num];
        if( 
player != id )
        {
            
// hurt player
        
}
    }



didoWEE 05-21-2013 04:34

Re: Find player using find_ent_in_sphere
 
@Connor
Isn't find_ent_by_class better than find_sphere_class?

Edit: Hehe, you missed get_players(); :D

hornet 05-21-2013 09:53

Re: Find player using find_ent_in_sphere
 
Quote:

Originally Posted by didoWEE (Post 1955577)
@Connor
Isn't find_ent_by_class better than find_sphere_class?

Edit: Hehe, you missed get_players(); :D

find_sphere_class() is better because it only checks entities in the given radius whereas find_ent_by_class() checks for all entities of that classname.

get_players() is not needed because find_sphere_class() outputs an array of found entities, and returns the number found.

ConnorMcLeod 05-21-2013 12:37

Re: Find player using find_ent_in_sphere
 
Quote:

Originally Posted by didoWEE (Post 1955577)
@Connor
you missed get_players(); :D

Was only making a comparaison.

didoWEE 05-23-2013 14:45

Re: Find player using find_ent_in_sphere
 
Yes, yes... you haven't forgotten get_maxplayers();
And the values of players[0] to players[31] and the value of player aren't 0.
No, no... they aren't.

.Dare Devil. 05-23-2013 19:35

Re: Find player using find_ent_in_sphere
 
Quote:

Originally Posted by ConnorMcLeod (Post 1955348)
Use find_sphere_class is far more efficient.
It's like using get_players instead of looping all possible players.

PHP Code:

HurtPlayersInUserSphere(idFloat:radiusdamageetc...)
{
    new 
players[32], playernum find_sphere_class(id"player"radiusplayerssizeof(players));
    for(--
numnum>=0num--)
    {
        
player players[num];
        if( 
player != id )
        {
            
// hurt player
        
}
    }



find_sphere_class is still looping all players and checking their origins right?


All times are GMT -4. The time now is 16:19.

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