Raised This Month: $ Target: $400
 0% 

[HELP] Switch to closest enemy


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Apokalipsisa
Member
Join Date: May 2012
Old 07-28-2013 , 17:28   [HELP] Switch to closest enemy
Reply With Quote #1

How to make the etnity switch to closest player and not following the one who catched first?Here is the code in the entity think:

PHP Code:
public fw_zb_think(ent)
{
    if(!
is_valid_ent(ent))
        return 
FMRES_IGNORED
    
    
if(g_think[ent])
    {
        static 
victim
        
static Float:Origin[3], Float:VicOrigin[3], Float:distance

        victim 
FindClosesEnemy(ent)
        
        
pev(entpev_originOrigin)
        
pev(victimpev_originVicOrigin)
        
        
distance get_distance_f(OriginVicOrigin)
        
        if(
is_user_alive(victim))
        {
            if(
distance <= 60.0)
            {
                if(!
is_valid_ent(ent))
                    return 
FMRES_IGNORED    
            
                
new Float:Ent_Origin[3], Float:Vic_Origin[3]
                
                
pev(entpev_originEnt_Origin)
                
pev(victimpev_originVic_Origin)            
            
                
npc_turntotarget(entEnt_OriginvictimVic_Origin)
                
                
zombie_attack(entvictim)
                
entity_set_float(entEV_FL_nextthinkget_gametime() + 2.5)
            } else {
                
                if(
get_anim(ent) != ANIM_WALK)
                    
play_anim(entANIM_WALK1.0)
                    
                new 
Float:Ent_Origin[3], Float:Vic_Origin[3]
                
                
pev(entpev_originEnt_Origin)
                
pev(victimpev_originVic_Origin)
                
                
npc_turntotarget(entEnt_OriginvictimVic_Origin)
                
hook_ent(entvictim)
                
                
entity_set_float(entEV_FL_nextthinkget_gametime() + 0.5)
            }
            
            
current_target[ent] = victim
        
} else {
            
//hook_ent(ent, ent)
            
            
if(get_anim(ent) != ANIM_IDLE)
                
play_anim(entANIM_IDLE1.0)
            
            
entity_set_float(entEV_FL_nextthinkget_gametime() + 1.0)
        }
    } else {
        if(
get_anim(ent) != ANIM_IDLE)
            
play_anim(entANIM_IDLE1.0)
            
        
entity_set_float(entEV_FL_nextthinkget_gametime() + 1.0)        
    }
    
    return 
FMRES_HANDLED


Now the FindClosesEnemy function is set to public:

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


How to make it switch targets and not store the ID to only first one who catch?If i connect first in the server the entity will follow only me even if there is close targets around him.How to make it switch targets?
Apokalipsisa is offline
 



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 15:56.


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