Raised This Month: $ Target: $400
 0% 

Find player using find_ent_in_sphere


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-20-2013 , 10:41   Find player using find_ent_in_sphere
Reply With Quote #1

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?
__________________
Kia is offline
didoWEE
Senior Member
Join Date: Oct 2012
Location: Bulgaria
Old 05-20-2013 , 11:55   Re: Find player using find_ent_in_sphere
Reply With Quote #2

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);
            }
        }
    }


Last edited by didoWEE; 05-20-2013 at 12:02.
didoWEE is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-20-2013 , 12:29   Re: Find player using find_ent_in_sphere
Reply With Quote #3

Thanks.


//EDIT : Doesn't work for me
__________________

Last edited by Kia; 05-20-2013 at 12:56.
Kia is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-20-2013 , 16:52   AW: Find player using find_ent_in_sphere
Reply With Quote #4

My bad, had a typo, it's working.
__________________
Kia is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-20-2013 , 17:28   Re: Find player using find_ent_in_sphere
Reply With Quote #5

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
        
}
    }

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
didoWEE
Senior Member
Join Date: Oct 2012
Location: Bulgaria
Old 05-23-2013 , 14:45   Re: Find player using find_ent_in_sphere
Reply With Quote #6

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.

Last edited by didoWEE; 05-23-2013 at 17:03.
didoWEE is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 05-23-2013 , 19:35   Re: Find player using find_ent_in_sphere
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
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?
.Dare Devil. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-24-2013 , 00:28   Re: Find player using find_ent_in_sphere
Reply With Quote #8

It is not checking origin, it loops FIND_ENTITY_IN_SPHERE internally to engine module, that's why it is more efficient and faster than looping in plugin.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
didoWEE
Senior Member
Join Date: Oct 2012
Location: Bulgaria
Old 05-21-2013 , 04:34   Re: Find player using find_ent_in_sphere
Reply With Quote #9

@Connor
Isn't find_ent_by_class better than find_sphere_class?

Edit: Hehe, you missed get_players();

Last edited by didoWEE; 05-21-2013 at 04:36.
didoWEE is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-21-2013 , 09:53   Re: Find player using find_ent_in_sphere
Reply With Quote #10

Quote:
Originally Posted by didoWEE View Post
@Connor
Isn't find_ent_by_class better than find_sphere_class?

Edit: Hehe, you missed get_players();
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.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet 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 16:19.


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