AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   help! how to make npc walk,and attack player (https://forums.alliedmods.net/showthread.php?t=221351)

1023168216 07-20-2013 23:11

help! how to make npc walk,and attack player
 
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
}


Arkshine 07-21-2013 04:43

Re: help! how to make npc walk,and attack player
 
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 07-21-2013 09:32

Re: help! how to make npc walk,and attack player
 
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 (Post 1995520)
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).


Arkshine 07-21-2013 10:33

Re: help! how to make npc walk,and attack player
 
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.


All times are GMT -4. The time now is 06:21.

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