Raised This Month: $32 Target: $400
 8% 

find_ent_in_sphere , finding opposite team players index?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kotoamatsukami
Member
Join Date: Jan 2017
Location: Malaysia
Old 03-03-2017 , 13:00   find_ent_in_sphere , finding opposite team players index?
Reply With Quote #1

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...
Kotoamatsukami is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-03-2017 , 13:27   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #2

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

__________________

Last edited by OciXCrom; 03-03-2017 at 17:22.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 03-03-2017 , 15:43   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
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
jimaway is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-03-2017 , 15:59   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #4

Or y can get enemies players alive and check the distance for each player in a loop
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-03-2017 at 16:01.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-03-2017 , 17:23   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #5

@jimaway - or simply use is_user_connected(). Fixed.
@Natseh - it's the same I guess, but I prefer it this way.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
PartialCloning
Senior Member
Join Date: Dec 2015
Old 03-03-2017 , 17:29   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #6

Code:
new Players[32]; find_sphere_class(id, "player", 300.0, Players, 32);
PartialCloning is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-03-2017 , 17:38   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #7

Quote:
Originally Posted by OciXCrom View Post
@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
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-03-2017 at 17:39.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Kotoamatsukami
Member
Join Date: Jan 2017
Location: Malaysia
Old 03-04-2017 , 03:14   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #8

Quote:
Originally Posted by OciXCrom View Post
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 View Post
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?
Kotoamatsukami is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-04-2017 , 03:47   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #9

Quote:
Originally Posted by Kotoamatsukami View Post
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?
__________________

Last edited by edon1337; 03-04-2017 at 03:47.
edon1337 is offline
Kotoamatsukami
Member
Join Date: Jan 2017
Location: Malaysia
Old 03-04-2017 , 03:52   Re: find_ent_in_sphere , finding opposite team players index?
Reply With Quote #10

Quote:
Originally Posted by edon1337 View Post
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...
Kotoamatsukami 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 02:24.


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