• SNPC Won't Attack
    5 replies, posted
I'm having a small problem with a simple SNPC I have made. The problem being that it runs to you alright but just stop right close to you and doesn't attack like i wanted it to. Any help would be appreciated! [lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') ENT.SpawnRagdollOnDeath = true ENT.BloodType = "red" ENT.AnimScale = 3 ENT.Damage = 40 ENT.Death = {"runner/death1.wav", "runner/death2.wav"} ENT.Taunt = {"runner/alert1.wav","runner/alert2.wav"} ENT.Attack = {"runner/attack.wav","npc/attack2.wav"} ENT.MeleeAnims = {"swing"} function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 20 local ent = ents.Create( "npc_zombie2" ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end function ENT:Initialize() self:SetModel( "models/Zed/malezed_0"..ChooseRandom({4,6,8})..".mdl" ) util.PrecacheSound("runner/stalk2.wav") util.PrecacheSound("runner/stalk.wav") self:SetHullType( HULL_HUMAN ); self:SetHullSizeNormal(); self:SetSolid( SOLID_BBOX ) self:SetMoveType( MOVETYPE_STEP ) self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_AIM_GUN | CAP_OPEN_DOORS ) self:SetMaxYawSpeed( 5000 ) self:SetHealth ( 500 ) end function ENT:SelectSchedule() local schdChase = ai_schedule.New( "AIFighter Chase" ) //creates the schedule used for this npc schdChase:AddTask( "FindEnemy", { Class = "player", Radius = 10000000 } ) schdChase:EngTask( "TASK_GET_PATH_TO_ENEMY", 0 ) schdChase:EngTask( "TASK_RUN_PATH_TIMED", 0.1 ) schdChase:EngTask( "TASK_WAIT", 0.1 ) local close = false local tbl = player.GetAll() for k,v in pairs(tbl) do if v:GetPos():Distance(self:GetPos()) < 75 then close = true end end if close then schdChase:EngTask( "TASK_STOP_MOVING", 0 ) schdChase:EngTask( "TASK_FACE_ENEMY", 0 ) schdChase:AddTask( "PlaySequence", { Name = "swing", Speed = 3 } ) end self:StartSchedule( schdChase ) end[/lua] It doesn't even swing!
any code?
Yes he posted code but its in lua tags so you probably can't see it. You can't just name your animation swing you have to make sure that the model's animation to attack is called swing with the source sdk model viewer.
Okay I've edited it but now it does the attack animation but i don't get damaged at all Also it appears to be invincible most of the time [editline]12:23PM[/editline] Any Help?
You're only telling it to play the swing animation when close to a player, not to cause any damage. And you're not telling it to make a ragdoll when killed, or even take damage for that matter.
Yeah, how do i fix it? It adds to my knowledge!
Sorry, you need to Log In to post a reply to this thread.