It'll be broken down into two sections:
1. Setting up an NPC
2. Setting up a bot.
Setting Up An NPC
Steps:
1. Making the ent
2. Making it solid
3. Making it take damage
4. Setting its model
5. Animating
6. Making NPC think correctly
7. Giving it a weapon
Ok, here we go.
1. First lets make a function:
Code: Select all
public spawn_npc(id)Code: Select all
new ent = create_entity("info_target")We also need to give the entity an origin, and also make the player *jump*, just for testing purposes.
Code: Select all
new Float:origin[3]
entity_get_vector(id,EV_VEC_origin,origin)
entity_set_origin(ent,origin);
origin[2] += 300.0
entity_set_origin(id,origin)2.
Ok the player is out of the way. Lets make it solid.
Code: Select all
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)
entity_set_int(ent,EV_INT_solid, 2)3.
Its solid, but invinsible. Lets also make it take damage:
Code: Select all
entity_set_float(ent,EV_FL_takedamage,1.0)
entity_set_float(ent,EV_FL_health,100.0)The health IS the health of the entity, but you should set it higher then normal. Ents seem to have less HP somehow.
4.
Setting the model is as easy as this:
Code: Select all
entity_set_string(ent,EV_SZ_classname,"npc_onna");
entity_set_model(ent,"models/onna.mdl");I know setting the classname is not setting the model, but you should set it with a similar classname.
5.
Ok, now lets give it a default animation.
Code: Select all
entity_set_float(ent,EV_FL_animtime,2.0)
entity_set_float(ent,EV_FL_framerate,1.0)
entity_set_int(ent,EV_INT_sequence,0);6.
Making it think is SLIGHTLY harder.
First you have to register its think in plugin_init:
Code: Select all
register_think("npc_onna","npc_think");Now then, we need to make the entity start thinking:
In the create NPC function:
Code: Select all
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)It needs to think VERY fast, in order to out run the server frames. This wont cause a whole lot of lag, since it is mostly handled in the engine.
Now then, the npc_think function will be called whenever it thinks. You can do all sorts of shit in here.
For instance, you can check if the HP has gone down, and make it bleed, play the right animation, etc.
Or, you could make it walk around by giving it velocity and changing the animation.
Above all, you must call the think function again:
Code: Select all
public npc_think(id)
{
// Put your think stuff here.
entity_set_float(id,EV_FL_nextthink,halflife_time() + 0.01)
}7.
I'll show you how to add a weapon as well:
Code: Select all
public give_weapon(ent)
{
new entWeapon = create_entity("info_target")
entity_set_string(entWeapon, EV_SZ_classname, "npc_weapon")
entity_set_int(entWeapon, EV_INT_movetype, MOVETYPE_FOLLOW)
entity_set_int(entWeapon, EV_INT_solid, SOLID_NOT)
entity_set_edict(entWeapon, EV_ENT_aiment, ent)
entity_set_model(entWeapon, "models/p_gauss.mdl")
}the P model is the PLAYER model, which will generally work. I used an HL default weapon because my model was HLDM.
Now then, lets put it all together:
Code: Select all
#include <amxmodx>
#include <engine>
public plugin_init()
{
register_clcmd("onna", "onna")
register_think("npc_onna","npc_think");
}
public plugin_precache()
{
precache_model("models/onna.mdl")
precache_model("models/p_gauss.mdl")
}
public onna(id)
{
new Float:origin[3]
entity_get_vector(id,EV_VEC_origin,origin)
new ent = create_entity("info_target")
give_weapon(ent)
entity_set_origin(ent,origin);
origin[2] += 300.0
entity_set_origin(id,origin)
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,"npc_onna");
entity_set_model(ent,"models/onna.mdl");
entity_set_int(ent,EV_INT_solid, 2)
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)
entity_set_float(ent,EV_FL_animtime,2.0)
entity_set_float(ent,EV_FL_framerate,1.0)
entity_set_int(ent,EV_INT_sequence,0);
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
drop_to_floor(ent)
return 1;
}
public give_weapon(ent)
{
new entWeapon = create_entity("info_target")
entity_set_string(entWeapon, EV_SZ_classname, "npc_weapon")
entity_set_int(entWeapon, EV_INT_movetype, MOVETYPE_FOLLOW)
entity_set_int(entWeapon, EV_INT_solid, SOLID_NOT)
entity_set_edict(entWeapon, EV_ENT_aiment, ent)
entity_set_model(entWeapon, "models/p_gauss.mdl")
}
public npc_think(id)
{
// Put your think stuff here.
entity_set_float(id,EV_FL_nextthink,halflife_time() + 0.01)
}
Have fun with it!
Making A Bot
Making a bot, or an NPC that can move easily and takes up a slot, is as simple as 1 2 3.
1. Follow the guide above
2. replace "create_entity("info_target"" with engfunc(EngFunc_CreateFakeClient,"Onna")
3. Set the model of the new bot using the mod specific functions.
You can now:
Use the FM engfunc command, EngFunc_RunPlayerMove to make them move
Act as if they are a normal player.
Very simple!
Have fun with it
