I’m trying to make a aimbot and I can’t get it to aim at NPC’s.

I tried adding

if (!aimNpc:GetBool()) and v:IsNPC() == v:IsNPC() then
continue
end

to the aimbot but it still wont work.

This is the code for the function aimbot

local function Aimbot(ucmd)
local ply = LocalPlayer()
if (!aiming) then return end
local closest, dist = nil, 0
for k, v in next, player.GetAll() do
if (!IsValid(v)) then continue end
if v == ply then continue end
if (!v:Alive()) then continue end
if (!aimFriends:GetBool()) and v:GetFriendStatus() == "friend" then
continue
end
if (!aimTeam:GetBool()) and v:Team() == ply:Team() then
continue
end
if (!aimNpc:GetBool()) and v:IsNPC() == v:IsNPC() then
continue
end
if (!InFov(ply:GetAngles(),(v:GetPos() - ply:GetShootPos()):Angle())) then
continue
end
if (!IsVisible(v,GetHead(v))) then continue end
local _dist = math_dist(GetHead(v):ToScreen().x, GetHead(v):ToScreen().y, ScrW() * 0.50, ScrH() * 0.50)
if (!closest or _dist < dist) then
dist = _dist
closest = v
targ = v
local angle = (GetHead(v) - ply:GetShootPos()):Angle()
if aimNospread:GetBool() then
angle = PredictSpread(ucmd, angle)
end
angle.y = math.NormalizeAngle(angle.y)
angle.p = math.NormalizeAngle(angle.p)
ucmd:SetViewAngles(angle)
if aimShoot:GetBool() then
ucmd:SetButtons(bit.bor(ucmd:GetButtons(), IN_ATTACK))
end
end
end
end
concommand.Add("+crouch", function() aiming = true end)
concommand.Add("-crouch", function() aiming = false end)
hook.Add("CreateMove","Aimbot", Aimbot)

Yes I did make aimNpc, This is the whole code for the aimbot

local function Aimbot(ucmd)
local ply = LocalPlayer()
if (!aiming) then return end
local closest, dist = nil, 0
for k, v in next, player.GetAll() do
if (!IsValid(v)) then continue end
if v == ply then continue end
if (!v:Alive()) then continue end
if (!aimFriends:GetBool()) and v:GetFriendStatus() == "friend" then
continue
end
if (!aimTeam:GetBool()) and v:Team() == ply:Team() then
continue
end
if (!aimNpc:GetBool()) and v:IsNPC() == v:IsNPC() then
continue
end
if (!InFov(ply:GetAngles(),(v:GetPos() - ply:GetShootPos()):Angle())) then
continue
end
if (!IsVisible(v,GetHead(v))) then continue end
local _dist = math_dist(GetHead(v):ToScreen().x, GetHead(v):ToScreen().y, ScrW() * 0.50, ScrH() * 0.50)
if (!closest or _dist < dist) then
dist = _dist
closest = v
targ = v
local angle = (GetHead(v) - ply:GetShootPos()):Angle()
if aimNospread:GetBool() then
angle = PredictSpread(ucmd, angle)
end
angle.y = math.NormalizeAngle(angle.y)
angle.p = math.NormalizeAngle(angle.p)
ucmd:SetViewAngles(angle)
if aimShoot:GetBool() then
ucmd:SetButtons(bit.bor(ucmd:GetButtons(), IN_ATTACK))
end
end
end
end
end
concommand.Add("+crouch", function() aiming = true end)
concommand.Add("-crouch", function() aiming = false end)
hook.Add("CreateMove","Aimbot", Aimbot)

I don’t really mess with anything related to NPCs, but I’m assuming you could run a search to get all of the entities, and then out of that search search for all the NPCs in those entities. So something to run ents.GetAll() or whatever, and then if ents is NPC or something along those lines

Thinking back on it now, an easier way would be ents.FindByClass, so you would do something like
[lua]
local npcs = ents.FindByClass(“npc_*”)
[/lua]
and npcs would be the variable that stores all of the npc’s