Raised This Month: $ Target: $400
 0% 

Get player by distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Killer zm
Senior Member
Join Date: Jun 2011
Old 04-22-2013 , 13:13   Get player by distance
Reply With Quote #1

My code

PHP Code:
public FindClosesEnemy(entid)
{
    new 
Float:Dist
    
new Float:maxdistance=4000.0
    
new indexid=0
    
    
    
for(new i=1;i<=g_iMaxPlayers;i++)
    {
        
        
        if(
is_user_alive(i) || is_user_bot(i) && is_valid_ent(i) && can_see_fm(entidi))
        {
            
Dist entity_range(entidi)
            
            
            if(
Dist <= maxdistance)
            {
                
maxdistance=Dist
                indexid
=i
                
                
return indexid
            
}
        }    
    }    
    return 
0

Why is always return indexid = 1
and i saw that when i change new i=1 with another number new i=5 indexid will be returned like 5

Please help me .Thank You
Killer zm is offline
didoWEE
Senior Member
Join Date: Oct 2012
Location: Bulgaria
Old 04-22-2013 , 14:12   Re: Get player by distance
Reply With Quote #2

because when you return sth, your function stops, the whole function
you can store the indexes in array

Last edited by didoWEE; 04-22-2013 at 14:12.
didoWEE is offline
Killer zm
Senior Member
Join Date: Jun 2011
Old 04-22-2013 , 14:36   Re: Get player by distance
Reply With Quote #3

how ??
Killer zm is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 04-22-2013 , 17:02   Re: Get player by distance
Reply With Quote #4

you exit the function after first iteration of the for loop

Code:
public FindClosesEnemy(entid) {     new Float:Dist     new Float:maxdistance=4000.0     new indexid=0             for(new i=1;i<=g_iMaxPlayers;i++)     {                         if(is_user_alive(i) || is_user_bot(i) && is_valid_ent(i) && can_see_fm(entid, i))         {             Dist = entity_range(entid, i)                                     if(Dist <= maxdistance)             {                 maxdistance=Dist                 indexid=i             }         }         }         return (indexid) ? indexid : 0 }

Last edited by jimaway; 04-22-2013 at 17:03.
jimaway is offline
Killer zm
Senior Member
Join Date: Jun 2011
Old 04-23-2013 , 12:54   Re: Get player by distance
Reply With Quote #5

is working thank you . TC
Killer zm 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 00:18.


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