xuqiang52133
|
分享:
▼
x0
|
[插件] (带源码)NPC走道的速度太慢了,帮改一下,出生位置不能自己设定
((带源码)NPC走道的速度太慢了,帮改一下,出生位置不能自己设定)
#include <amxmodx> #include <engine> #include <fakemeta> #include <hamsandwich>
#define ZB_CLASSNAME "npc_zombie" #define TASK_ATTACK 323423
new const zombie_model[] = "models/player/tank_zombi_host/tank_zombi_host.mdl" new const zombie_hurt_sound[] = "biohazard/zombie_hurt_01.wav" new const zombie_attack_sound[] = "biohazard/zombi_attack_1.wav" new const zombie_die_sound[] = "biohazard/zombie_death_1.wav"
enum { ANIM_IDLE = 1, ANIM_WALK = 3, ANIM_ATTACK = 76, ANIM_DIE = 104 }
new Float:g_spawn_point[3], Float:g_angles[3] new pev_victim = pev_enemy
new ent2
public plugin_init() { register_plugin("NPC Zombie", "1.0", "Dias") register_think(ZB_CLASSNAME, "fw_zb_think") register_clcmd("say /set_spawn_point", "get_spawn_point") register_clcmd("say /create_zombie", "create_zombie") }
public client_PostThink(id) { //new Float:distance = entity_range(id, ent2) //client_print(id, print_chat, "%f", distance) }
public plugin_precache() { engfunc(EngFunc_PrecacheModel, zombie_model) precache_sound(zombie_hurt_sound) precache_sound(zombie_attack_sound) precache_sound(zombie_die_sound) }
public get_spawn_point(id) { entity_get_vector(id, EV_VEC_origin, g_spawn_point) entity_get_vector(id, EV_VEC_angles, g_angles) }
public create_zombie(id) { new ent = create_entity("info_target") ent2 = ent entity_set_origin(ent, g_spawn_point) entity_set_float(ent, EV_FL_takedamage,1.0) entity_set_float(ent, EV_FL_health, 100.0) entity_set_string(ent, EV_SZ_classname, ZB_CLASSNAME) entity_set_model(ent, zombie_model) entity_set_int(ent, EV_INT_solid, 2) entity_set_int(ent, EV_INT_movetype, MOVETYPE_STEP) set_pev(ent, pev_victim, 0) entity_set_byte(ent, EV_BYTE_controller1, 125) entity_set_byte(ent, EV_BYTE_controller2, 125) entity_set_byte(ent, EV_BYTE_controller3, 125) entity_set_byte(ent, EV_BYTE_controller4, 125) new Float:maxs[3] = {16.0, 16.0, 36.0} new Float:mins[3] = {-16.0, -16.0, -36.0} entity_set_size(ent, mins, maxs) play_anim(ent, ANIM_IDLE, 1.0) entity_set_float(ent,EV_FL_nextthink, halflife_time() + 0.01) drop_to_floor(ent) RegisterHamFromEntity(Ham_TakeDamage, ent, "fw_zb_takedmg") RegisterHamFromEntity(Ham_Killed, ent, "fw_zb_killed") return 1 }
public fw_zb_takedmg(victim, inflictor, attacker, Float:damage, damagebits) { emit_sound(victim, CHAN_BODY, zombie_hurt_sound, 1.0, ATTN_NORM, 0, PITCH_NORM) }
public fw_zb_killed(ent2) { new ent = create_entity("info_target") new Float:Origin[3], Float:Angles[3] pev(ent2, pev_origin, Origin) pev(ent2, pev_angles, Angles) entity_set_origin(ent, Origin) entity_set_vector(ent, EV_VEC_angles, Angles) entity_set_string(ent, EV_SZ_classname, "temp_zb") entity_set_model(ent, zombie_model) new Float:maxs[3] = {16.0, 16.0, 36.0} new Float:mins[3] = {-16.0, -16.0, -36.0} entity_set_size(ent, mins, maxs) drop_to_floor(ent) play_anim(ent, ANIM_IDLE, 1.0) play_anim(ent, ANIM_DIE, 1.0) emit_sound(ent, CHAN_BODY, zombie_die_sound, 1.0, ATTN_NORM, 0, PITCH_NORM) set_task(5.0, "remove_temp_zb", ent) }
public remove_temp_zb(ent) { remove_entity(ent) }
public fw_zb_think(ent) { if(!is_valid_ent(ent)) return FMRES_IGNORED new victim = FindClosesEnemy(ent) new Float:Origin[3], Float:VicOrigin[3], Float:distance pev(ent, pev_origin, Origin) pev(victim, pev_origin, VicOrigin) distance = get_distance_f(Origin, VicOrigin) if(distance <= 60.0) { 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.1) } return FMRES_HANDLED }
public zombie_attack(ent, victim) { 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) play_anim(ent, ANIM_ATTACK, 1.0) ExecuteHam(Ham_TakeDamage, victim, 0, victim, random_float(5.0, 10.0), DMG_BULLET) emit_sound(victim, CHAN_BODY, zombie_attack_sound, 1.0, ATTN_NORM, 0, PITCH_NORM) remove_task(ent+TASK_ATTACK) set_task(1.5, "stop_attack", ent+TASK_ATTACK) }
public stop_attack(ent) { ent -= TASK_ATTACK play_anim(ent, ANIM_IDLE, 1.0) remove_task(ent+TASK_ATTACK) }
public npc_turntotarget(ent, Float:Ent_Origin[3], target, Float:Vic_Origin[3]) { if(target) { new Float:newAngle[3] entity_get_vector(ent, EV_VEC_angles, newAngle) new Float:x = Vic_Origin[0] - Ent_Origin[0] new Float:z = Vic_Origin[1] - Ent_Origin[1]
new Float:radians = floatatan(z/x, radian) newAngle[1] = radians * (180 / 3.14) if (Vic_Origin[0] < Ent_Origin[0]) newAngle[1] -= 180.0 entity_set_vector(ent, EV_VEC_angles, newAngle) } }
public hook_ent(ent, victim) { new Float:fl_Velocity[3] new Float:VicOrigin[3], Float:EntOrigin[3]
pev(ent, pev_origin, EntOrigin) pev(victim, pev_origin, VicOrigin) new Float:distance_f = get_distance_f(EntOrigin, VicOrigin)
if (distance_f > 60.0) { new Float:fl_Time = distance_f / 100.0
fl_Velocity[0] = (VicOrigin[0] - EntOrigin[0]) / fl_Time fl_Velocity[1] = (VicOrigin[1] - EntOrigin[1]) / fl_Time fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time } else { fl_Velocity[0] = 0.0 fl_Velocity[1] = 0.0 fl_Velocity[2] = 0.0 }
entity_set_vector(ent, EV_VEC_velocity, fl_Velocity) }
stock bool:IsValidTarget(iTarget) { if (!iTarget || !(1<= iTarget <= get_maxplayers()) || !is_user_connected(iTarget) || !is_user_alive(iTarget)) return false return true }
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 }
public bool:can_see_fm(entindex1, entindex2) { if (!entindex1 || !entindex2) return false
if (pev_valid(entindex1) && pev_valid(entindex1)) { new flags = pev(entindex1, pev_flags) if (flags & EF_NODRAW || flags & FL_NOTARGET) { return false }
new Float:lookerOrig[3] new Float:targetBaseOrig[3] new Float:targetOrig[3] new Float:temp[3]
pev(entindex1, pev_origin, lookerOrig) pev(entindex1, pev_view_ofs, temp) lookerOrig[0] += temp[0] lookerOrig[1] += temp[1] lookerOrig[2] += temp[2]
pev(entindex2, pev_origin, targetBaseOrig) pev(entindex2, pev_view_ofs, temp) targetOrig[0] = targetBaseOrig [0] + temp[0] targetOrig[1] = targetBaseOrig [1] + temp[1] targetOrig[2] = targetBaseOrig [2] + temp[2]
engfunc(EngFunc_TraceLine, lookerOrig, targetOrig, 0, entindex1, 0) // checks the had of seen player if (get_tr2(0, TraceResult:TR_InOpen) && get_tr2(0, TraceResult:TR_InWater)) { return false } else { new Float:flFraction get_tr2(0, TraceResult:TR_flFraction, flFraction) if (flFraction == 1.0 || (get_tr2(0, TraceResult:TR_pHit) == entindex2)) { return true } else { targetOrig[0] = targetBaseOrig [0] targetOrig[1] = targetBaseOrig [1] targetOrig[2] = targetBaseOrig [2] engfunc(EngFunc_TraceLine, lookerOrig, targetOrig, 0, entindex1, 0) // checks the body of seen player get_tr2(0, TraceResult:TR_flFraction, flFraction) if (flFraction == 1.0 || (get_tr2(0, TraceResult:TR_pHit) == entindex2)) { return true } else { targetOrig[0] = targetBaseOrig [0] targetOrig[1] = targetBaseOrig [1] targetOrig[2] = targetBaseOrig [2] - 17.0 engfunc(EngFunc_TraceLine, lookerOrig, targetOrig, 0, entindex1, 0) // checks the legs of seen player get_tr2(0, TraceResult:TR_flFraction, flFraction) if (flFraction == 1.0 || (get_tr2(0, TraceResult:TR_pHit) == entindex2)) { return true } } } } } return false }
stock get_anim(id) { return pev(id, pev_sequence) }
stock play_anim(index, sequence, Float:framerate = 1.0) { entity_set_float(index, EV_FL_animtime, get_gametime()) entity_set_float(index, EV_FL_framerate, framerate) entity_set_float(index, EV_FL_frame, 0.0) entity_set_int(index, EV_INT_sequence, sequence) }
stock DirectedVec(Float:start[3],Float:end[3],Float:reOri[3]) { new Float:v3[3] v3[0]=start[0]-end[0] v3[1]=start[1]-end[1] v3[2]=start[2]-end[2] new Float:vl = vector_length(v3) reOri[0] = v3[0] / vl reOri[1] = v3[1] / vl reOri[2] = v3[2] / vl
谁帮我弄一下可以吗,NPC走道的速度慢死了,比乌龟还慢。NPC出生的位置怎么自己设定??还有NPC多了就会卡在一个地方不动了,求高手帮我一下??
|