I've been learning how to make SNPC's and I was trying to create a zombie. I have it so the zombie will attack the player, but I also want the SNPC to attack props or entites.
I tried changing ( and adding ) to the
[lua]
schdChase:AddTask( "FindEnemy", { Class = "player", Radius = 10000000 } )
[/lua]
code, adding "wood_crate", as another entity, or just replacing the player part with it. But that doesn't appear to be working.
SNPC init.lua code:
[lua]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
ENT.SpawnRagdollOnDeath = true
ENT.AnimScale = 3
ENT.Damage = 40
ENT.MeleeAnims = {"swing"}
function ENT:Initialize()
self:SetModel( "models/z0mbeh.mdl" )
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:OnTakeDamage(dmg)
self:SetHealth(self:Health() - dmg:GetDamage())
if self:Health() <= 0 then
self:SetSchedule( SCHED_FALL_TO_GROUND )
end
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]
If anyone could help, that'd be really appreciated.
I'm very new to scripting, and lua but there are different wood crates.
models/props_junk/wood_crate001a.mdl
models/props_junk/wood_crate001a_damaged.mdl
models/props_junk/wood_crate002a.mdl
Maybe you need to distinguish between them.
Nah, 'wood_crate' is an entity.
Did you try NPC.SetEnemy
Sorry, you need to Log In to post a reply to this thread.