Raised This Month: $ Target: $400
 0% 

help! how to make npc walk,and attack player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
1023168216
Member
Join Date: Jun 2013
Location: Tokyo
Old 07-20-2013 , 23:11   help! how to make npc walk,and attack player
Reply With Quote #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
}
1023168216 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-21-2013 , 04:43   Re: help! how to make npc walk,and attack player
Reply With Quote #2

You miss a lot of code. You should check some NPC tutorial and some related plugins. You have just done the easy part, spawning an entity.

You can't expect to handle walking/firing just with few lines of code.

You should play instead with MonsterMod if you don't have much knowledege (which seems to be the case otherwise you won't ask here what to do).
__________________

Last edited by Arkshine; 07-21-2013 at 04:44.
Arkshine is offline
1023168216
Member
Join Date: Jun 2013
Location: Tokyo
Old 07-21-2013 , 09:32   Re: help! how to make npc walk,and attack player
Reply With Quote #3

what you said is correct.but i google NPC code,i only can found some simple code,no much help,if you have some better code,can you give me some pls?
Quote:
Originally Posted by Arkshine View Post
You miss a lot of code. You should check some NPC tutorial and some related plugins. You have just done the easy part, spawning an entity.

You can't expect to handle walking/firing just with few lines of code.

You should play instead with MonsterMod if you don't have much knowledege (which seems to be the case otherwise you won't ask here what to do).
1023168216 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-21-2013 , 10:33   Re: help! how to make npc walk,and attack player
Reply With Quote #4

Again, if you have no idea on what you're doing, just use something already done, like MonsterMod module. Also, doing in Pawn is really not recommended as it would very very inefficient.
__________________
Arkshine is offline
Reply



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 06:21.


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