Aim at NPCs for Aimbot

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)

Can anybody help?

player.GetAll() doesn’t include npcs
v:IsNPC() == v:IsNPC() will always be true
did you make aimNpc?

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)

[editline]18th August 2014[/editline]

How would I make it include NPCs?

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

I dont know how to do that

I knew you were making an aimbot you little rascal.

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

So if I did that I just needed to do


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

?

I tried doing it like this


	if (!aimNpc:GetBool()) and npcs() then
		continue
	end

and like this


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

and still it didn’t work

bump

try adding npcs name to the end of the aimbot

That’s not lua…

Where are you placing the aforementioned code?

“npcs” is now a table of all entities started with npc_

Loop through the table.

for k, v in pairs( ents.GetAll() ) do loop through all entities, npc’s are stored in there (players too)

Fix your check

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

You will no longer target players, just npcs

Thanks so much! I did it and I made it aim at players too. How can I make it not target dead npcs? the v:Alive thing is only for players


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

Entity:Health() > 0? Not sure of too many other ways to check if dead.

I tried this

but for the npc one, it says Entity is a nil value

Entity was just a placeholder for whatever variable you were using,


if ( aimNpc:GetBool() ) and !( v:IsNPC() and ( v:Health() > 0 ) ) then 

Not sure what you are doing with your code but the ! in front of the conditions seems out of place to me.

i doubt you made this aimbot, you have no idea what you’re doing