AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   find_ent_in_sphere , finding opposite team players index? (https://forums.alliedmods.net/showthread.php?t=294620)

Kotoamatsukami 03-03-2017 13:00

find_ent_in_sphere , finding opposite team players index?
 
Hello... I am sorry for making thread, again.

As the title stated, by the way, I know how the native works. My main problem emerges when finding the entities( specifically players ) index. So, I tried.
PHP Code:

public Randomid )
{
    new 
Float:CurOrigin], EnemyEnt = -1
    
    pev
idpev_originCurOrigin )
    
    
EnemyEnt find_ent_in_sphereEnemyEntCurOrigin300.0 )
    
    while( 
EnemyEnt != )
    {
        
// do stuff...
    
}


AFAIK, this will only retrieve a single entity( player ) index, right? Do I need to use 'for' loop instead of 'while' to catch the indexes using get_maxplayers( )? If so, then how?
My main goal is to retrieve all entities( players ) index inside the radius...

Thank you for your time...

OciXCrom 03-03-2017 13:27

Re: find_ent_in_sphere , finding opposite team players index?
 
PHP Code:

new Float:fOrigin[3], iTeam get_user_team(id), iEnt
entity_get_vector
(idEV_VEC_originfOrigin)

while((
iEnt find_ent_in_sphere(iEntfOrigin300.0)) != 0)
{
    if(
id == iEnt)
        continue
    
    if(
is_user_connected(iEnt))
    {
        if(
iTeam != get_user_team(iEnt))
        {
            
// iEnt is an enemy...
        
}
    }



jimaway 03-03-2017 15:43

Re: find_ent_in_sphere , finding opposite team players index?
 
Quote:

Originally Posted by OciXCrom (Post 2500469)
PHP Code:

new Float:fOrigin[3], szClassname[32], iTeam get_user_team(id), iEnt
entity_get_vector
(idEV_VEC_originfOrigin)

while((
iEnt find_ent_in_sphere(iEntfOrigin300.0)) != 0)
{
    if(
id == iEnt)
        continue
        
    
entity_get_string(iEntEV_SZ_classnameszClassnamecharsmax(szClassname))
    
    if(
equal(szClassname"player"))
    {
        if(
iTeam != get_user_team(iEnt))
        {
            
// iEnt is an enemy...
        
}
    }



i guess a small optimization could be done by removing the classname check and use 1<=iEnt<=maxplayers instead

Natsheh 03-03-2017 15:59

Re: find_ent_in_sphere , finding opposite team players index?
 
Or y can get enemies players alive and check the distance for each player in a loop

OciXCrom 03-03-2017 17:23

Re: find_ent_in_sphere , finding opposite team players index?
 
@jimaway - or simply use is_user_connected(). Fixed.
@Natseh - it's the same I guess, but I prefer it this way.

PartialCloning 03-03-2017 17:29

Re: find_ent_in_sphere , finding opposite team players index?
 
Code:
new Players[32]; find_sphere_class(id, "player", 300.0, Players, 32);

Natsheh 03-03-2017 17:38

Re: find_ent_in_sphere , finding opposite team players index?
 
Quote:

Originally Posted by OciXCrom (Post 2500526)
@jimaway - or simply use is_user_connected(). Fixed.
@Natseh - it's the same I guess, but I prefer it this way.

Check if user is alive instead of connected, probably it might found an player ent which is not alive

Kotoamatsukami 03-04-2017 03:14

Re: find_ent_in_sphere , finding opposite team players index?
 
Quote:

Originally Posted by OciXCrom (Post 2500469)
PHP Code:

new Float:fOrigin[3], iTeam get_user_team(id), iEnt
entity_get_vector
(idEV_VEC_originfOrigin)

while((
iEnt find_ent_in_sphere(iEntfOrigin300.0)) != 0)
{
    if(
id == iEnt)
        continue
    
    if(
is_user_connected(iEnt))
    {
        if(
iTeam != get_user_team(iEnt))
        {
            
// iEnt is an enemy...
        
}
    }



Pardon me, may I ask?
I actually have a question upon your codes.
Firstly, isn't the 'iEnt' should be valued to '-1- ? I remembered on the Docs there was stated it should start by '-1' in order to prevent it from missing the first entity that the native should catch.

Secondly, I am sorry again, maybe I misunderstood your codes but nevermind, isn't your codes will only retrieve a single player's index? In the 'while' loop, shouldn't the value of 'iEnt' increase ascending for each loop because '!=0' means that when the value of 'iEnt' reached '0' then it will stop the loop and the aftermath will only catch a single player index?

Anyone may enlighten the case.....

Quote:

Originally Posted by PartialCloning (Post 2500527)
Code:
new Players[32]; find_sphere_class(id, "player", 300.0, Players, 32);

I haven't seen that native for quite a time. Is there any difference between this native and the current native that I am using?

edon1337 03-04-2017 03:47

Re: find_ent_in_sphere , finding opposite team players index?
 
Quote:

Originally Posted by Kotoamatsukami (Post 2500582)
Firstly, isn't the 'iEnt' should be valued to '-1- ? I remembered on the Docs there was stated it should start by '-1' in order to prevent it from missing the first entity that the native should catch.

Don't you notice the != 0 in the loop or it's necessary for us to remind you?

Kotoamatsukami 03-04-2017 03:52

Re: find_ent_in_sphere , finding opposite team players index?
 
Quote:

Originally Posted by edon1337 (Post 2500590)
Don't you notice the != 0 in the loop or it's necessary for us to remind you?

My apology, but I did wrote about that on my second question...


All times are GMT -4. The time now is 20:59.

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