Blood-game > Плагины > NPC


NPC Скачать sma amxx


(Non Player Character) Персонажи в игре, которые управляются компьютером, а не игроком. Их уровень реагирования зависит от искусственного интеллекта.

Инструкция по созданию

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:
public spawn_npc(id)

Then lets make the entity:

Code:
    new ent = create_entity("info_target")
Note: This creates the entity.

We also need to give the entity an origin, and also make the player *jump*, just for testing purposes.

Code:
    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)
Note: Sets the origin

2.
Ok the player is out of the way. Lets make it solid.

Code:
    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)
Note: Sets it BBOX solid, and gives it a bbox

3.
Its solid, but invinsible. Lets also make it take damage:

Code:
    entity_set_float(ent,EV_FL_takedamage,1.0)
    entity_set_float(ent,EV_FL_health,100.0)
Note: Changes the takedamage to 1, and gives it HP.

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:
    entity_set_string(ent,EV_SZ_classname,"npc_onna");
    entity_set_model(ent,"models/onna.mdl");
Note: Sets its model and classname

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:
    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);
Note: Sets the frameRate (framerate for ent), animation time (max time for an animation, and sequence (the actual animation). You do not really need animtime, but I think better safe then sorry.

6.
Making it think is SLIGHTLY harder.

First you have to register its think in plugin_init:

Code:
    register_think("npc_onna","npc_think");
Note: The first parameter must be the same as the classname you set.

Now then, we need to make the entity start thinking:
In the create NPC function:
Code:
    entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
Note: This makes the entity think REALLY soon. 1/100th of a second.

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:
public npc_think(id)
{
    // Put your think stuff here.
    entity_set_float(id,EV_FL_nextthink,halflife_time() + 0.01)
}

Everything else you do in here is your business. I'll put up some examples later of how to make it walk or shoot.

7. 
I'll show you how to add a weapon as well:

Code:

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") 
}
Make sure the model you set is precached, or it will fuck up.
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:
#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)
}

This is a working test function. You can easily take alter it to make an NPC of your choosing.

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

Скачать






© SAnTA 2017

Яндекс.Метрика

Меню:
Новости: