Nico-s Nextbots Script -

-- Optional: push the player a little local push = (self.CurrentTarget:GetPos() - self:GetPos()):GetNormalized() * 200 self.CurrentTarget:SetVelocity(push) end

if not IsValid(self.CurrentTarget) then -- No players in range – wander randomly self:MoveToPos(self:GetPos() + VectorRand() * 200, tolerance = 40, timeout = 5, repath = 1, maxage = 2 ) else -- 2️⃣ Target is within chase radius? local distToTarget = self:GetPos():DistToSqr(self.CurrentTarget:GetPos())

-- ========================================================= -- BASIC NEXTBOT SETUP -- ========================================================= AddCSLuaFile() -- make the file sent to clients (for the model & sounds)

-- Internal state self.NextAttack = 0 self.CurrentTarget = nil end Nico-s Nextbots Script

for _, ply in ipairs(player.GetAll()) do if not IsValid(ply) or not ply:Alive() then continue end

local dist = self:GetPos():DistToSqr(ply:GetPos()) if dist < nearestDist ^ 2 then nearest = ply nearestDist = math.sqrt(dist) end end

-- ----------------------------------------------------------------- -- Helper: Find the nearest viable player -- ----------------------------------------------------------------- function ENT:FindClosestPlayer() local nearest = nil local nearestDist = CONFIG.ChaseRadius -- Optional: push the player a little local push = (self

-- Make sure the physics hull is appropriate for the model self:SetHullSizeNormal() self:SetCollisionBounds(Vector(-16, -16, 0), Vector(16, 16, 72))

if SERVER then self:SetMoveType(MOVETYPE_STEP) self:SetSolid(SOLID_BBOX) self:SetHealth(100)

-- ----------------------------------------------------------------- -- Optional: footstep sounds – makes the bot feel more alive -- ----------------------------------------------------------------- function ENT:FootStepSound() self:EmitSound(CONFIG.FootstepSound, 70, 100, 0.5, CHAN_AUTO) end tolerance = 40

-- ----------------------------------------------------------------- -- Core AI loop – runs every tick on the server -- ----------------------------------------------------------------- function ENT:RunBehaviour() while true do -- 1️⃣ Acquire / validate target if not IsValid(self.CurrentTarget) or not self.CurrentTarget:Alive() then self.CurrentTarget = self:FindClosestPlayer() end

return nearest end

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.