Nextbots Script — Nico-s

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

-- Play the scream (both server & client) self:EmitSound(CONFIG.ScreamSound, 85, 100, 1, CHAN_AUTO)

-- Pre‑cache the scream sound to avoid hitches util.PrecacheSound(CONFIG.ScreamSound) util.PrecacheSound(CONFIG.FootstepSound) end

-- ----------------------------------------------------------------- -- 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 Nico-s Nextbots Script

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

-- Internal state self.NextAttack = 0 self.CurrentTarget = nil end

-- ----------------------------------------------------------------- -- Called once when the entity is spawned (server side) -- ----------------------------------------------------------------- function ENT:Initialize() -- Model & physics self:SetModel(CONFIG.Model) self:SetHealth(100) self:SetCollisionGroup(COLLISION_GROUP_NPC) tolerance = 40

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

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

ENT.Base = "base_nextbot" ENT.Type = "nextbot" timeout = 5

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())

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

-- 4️⃣ Attack if close enough and cooldown elapsed if distToTarget <= CONFIG.AttackDistance ^ 2 and CurTime() > self.NextAttack then self:AttackTarget() self.NextAttack = CurTime() + CONFIG.AttackCooldown end end end

-- Simple damage packet (feel free to replace with a more complex system) local dmg = DamageInfo() dmg:SetAttacker(self) dmg:SetInflictor(self) dmg:SetDamage(30) -- damage per hit dmg:SetDamageType(DMG_SLASH) -- any type you like self.CurrentTarget:TakeDamageInfo(dmg)

if distToTarget > CONFIG.LoseRadius ^ 2 then -- Too far – give up and look for another player self.CurrentTarget = nil coroutine.yield() else -- 3️⃣ Move toward the player self:MoveToPos(self.CurrentTarget:GetPos(), tolerance = CONFIG.AttackDistance, timeout = 10, repath = 1, maxage = 2, goalpos = self.CurrentTarget:GetPos() )