|
Member
Join Date: Jun 2013
Location: Tokyo
|

07-20-2013
, 23:11
help! how to make npc walk,and attack player
|
#1
|
i created npc by the code successfully,but i cant walk and cant attack player. how to do it?anyone knows it? pls help me~
Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
enum {
Anim_NONE = 0,
Anim_IDLE,
Anim_WALK,
Anim_RUN,
Anim_ATTACK,
Anim_DIE1,
Anim_DIE2,
Anim_DIE3,
Anim_DIE4
}
public plugin_init()
{
register_plugin("Zombie Attack!", "1.0", "Alexander Mathiasen")
register_think("npc_zombie", "zombie_think")
register_clcmd("create_zombie", "zombie_spawn")
}
public plugin_precache() {
precache_model("models/NPC/ZOMBIE.mdl")
}
public zombie_spawn(id) {
new Float: origin[3]
entity_get_vector(id, EV_VEC_origin, origin)
new eZombie = create_entity("info_target")
origin[1] += 50.0
entity_set_origin(eZombie, origin)
entity_set_float(eZombie, EV_FL_takedamage, 1.0)
entity_set_float(eZombie, EV_FL_health, 100.0)
entity_set_string(eZombie, EV_SZ_classname, "npc_zombie")
entity_set_model(eZombie, "models/NPC/ZOMBIE.mdl")
entity_set_int(eZombie, EV_INT_solid, 2)
entity_set_byte(eZombie,EV_BYTE_controller1, 125)
entity_set_byte(eZombie,EV_BYTE_controller2, 125)
entity_set_byte(eZombie,EV_BYTE_controller3, 125)
entity_set_byte(eZombie,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(eZombie, mins, maxs)
play_animation(eZombie, Anim_IDLE)
entity_set_float(eZombie, EV_FL_nextthink, halflife_time() + 0.01)
engfunc(EngFunc_WalkMove, id, 0.5, 50.0, WALKMOVE_NORMAL)
drop_to_floor(eZombie)
return 1
}
stock play_animation(id, sequence)
{
entity_set_float(id, EV_FL_animtime, get_gametime())
entity_set_float(id, EV_FL_framerate, 1.0)
entity_set_int(id, EV_INT_sequence, sequence)
}
public zombie_think(ent) {
return HAM_IGNORED
}
stock NPC_FindNearestPlayer(npc_ent,Float:ShortestDistance = 800.0) {
new Float:PlayerOrigin[3],Float:Distance,NearestPlayer=0
new players[32],playerCount,Float:fOrigin[3]
pev(npc_ent,pev_origin,fOrigin)
get_players(players,playerCount,"ah")
for(new i=0;i<playerCount;i++) {
pev(players[i],pev_origin,PlayerOrigin)
Distance = vector_distance(PlayerOrigin,fOrigin)
if(Distance <= ShortestDistance) {
ShortestDistance = Distance
NearestPlayer = players[i]
break
}
}
return NearestPlayer
}
|
|