Something pretty easy I assume

This is my first time lua coding, and ive brushed up on it but I cant seem to solve this problem.
Im trying to code an antlion npc which is a remake of the glowing antlions from early Hl2 ep2 trailers. Its skin is a reskin of the normal antlion skin (I know this isent the issue). So im using an antlion worker as a base npc, and It wont follow me to attack me (It will fly at me and npcs when I first spawn it, and a while after but not often) and it just sits there moving its head the exact same way (Im assuming this is the base npc, antlion worker, trying to use its spit attack) but when I go near it will melee attack me like a normal antlion would, but move back after 3-4 hits. So basicly im asking can someone fix this, Im not an experienced coder, so if you decide to edit this, I need it to stop trying to spit and follow and attack me and npc’s

AddCSLuaFile( “cl_init.lua” ) // Make sure clientside
AddCSLuaFile( “shared.lua” ) // and shared scripts are sent.


local schdChase = ai_schedule.New( “AIFighter Chase” ) //creates the schedule used for this npc

// Run away randomly (first objective in task)
schdChase:EngTask( “TASK_GET_PATH_TO_RANDOM_NODE”, 128 )
schdChase:EngTask( “TASK_RUN_PATH”, 0 )
schdChase:EngTask( “TASK_WAIT_FOR_MOVEMENT”, 0 )
schdChase:AddTask( “PlaySequence”, { Name = “rumble1”, Speed = 1 } )

// Find an enemy and run to it (second objectives in task)
schdChase:AddTask( “FindEnemy”, { Class = “player”, Radius = 2000 } )
schdChase:EngTask( “TASK_RUN_PATH”, 0 )
schdChase:EngTask( “TASK_SCRIPT_RUN_TO_TARGET”, 0 )
schdChase:EngTask( “TASK_WAIT_FOR_MOVEMENT”, 0 )

// Attack it (third objective in task)
schdChase:EngTask( “TASK_STOP_MOVING”, 0 )
schdChase:EngTask( “TASK_FACE_ENEMY”, 0 )
schdChase:EngTask( “TASK_ANNOUNCE_ATTACK”, 0 )
schdChase:EngTask( “TASK_MELEE_ATTACK1”, 0 )

//schedule is looped till you give it a different schedule

function ENT:SpawnFunction( ply, tr )

if ( !tr.Hit ) then return end

local SpawnPos = tr.HitPos + tr.HitNormal * 30
local ent = ents.Create( “npc_antlion_cave” ) – name of the folder
ent:SetPos( SpawnPos )
return ent

function ENT:Initialize()
self.ent = ents.Create( “npc_antlion_worker” ) – this a npc which use a antlion_worker npc as a base
self.ent:SetPos( self:GetPos() )
self.ent:SetAngles( self:GetAngles() )
self.ent:SetModel(“models/antlio3.mdl”) – the is the model of the npc ragdoll


function ENT:OnRemove()

I’m not going to fix it for you, but I hope this post will give you a bit of intuition as to how AI work.

In an ai derived SENT, the hook **[ENT.SelectSchedule](** is called whenever the AI is doing nothing, for example, if it just finished walking somewhere or if nothing has happened yet. In this hook, you make the SNPC select a task or schedule or whatever and it will do so. Once again, it’s only called when the SNPC has no schedule.

Inside SelectSchedule, you can use self:StartSchedule( customSched ) or self:SetSchedule( ENGINE_SCHED ). In your case, it looks like you want to use a custom schedule, so you’d do something like

[lua]function ENT:SelectSchedule()

 if( iShouldDoSomething ) then
      self:StartSchedule( customSchedHere );
 self:StartSchedule( ifImNotDoingAnything );


That’s basically how SNPCs work.