Please tell me how to make the entity follow the closest player to him?Now the entity follow only the first player catched in that radius and i want to make it follow every player in it (change to closest target).
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(entid, i))
{
Dist = entity_range(entid, i)
if(Dist <= maxdistance)
{
maxdistance=Dist
indexid=i
return indexid
}
}
}
return 0
}