| Apokalipsisa |
07-28-2013 17:28 |
[HELP] Switch to closest enemy
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(ent, pev_origin, Origin) pev(victim, pev_origin, VicOrigin) distance = get_distance_f(Origin, VicOrigin) 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(ent, pev_origin, Ent_Origin) pev(victim, pev_origin, Vic_Origin) npc_turntotarget(ent, Ent_Origin, victim, Vic_Origin) zombie_attack(ent, victim) entity_set_float(ent, EV_FL_nextthink, get_gametime() + 2.5) } else { if(get_anim(ent) != ANIM_WALK) play_anim(ent, ANIM_WALK, 1.0) new Float:Ent_Origin[3], Float:Vic_Origin[3] pev(ent, pev_origin, Ent_Origin) pev(victim, pev_origin, Vic_Origin) npc_turntotarget(ent, Ent_Origin, victim, Vic_Origin) hook_ent(ent, victim) entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.5) } current_target[ent] = victim } else { //hook_ent(ent, ent) if(get_anim(ent) != ANIM_IDLE) play_anim(ent, ANIM_IDLE, 1.0) entity_set_float(ent, EV_FL_nextthink, get_gametime() + 1.0) } } else { if(get_anim(ent) != ANIM_IDLE) play_anim(ent, ANIM_IDLE, 1.0) entity_set_float(ent, EV_FL_nextthink, get_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(entid, i)) { Dist = entity_range(entid, i) 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?
|