~Lua~Aimbot Help

Ok I Have A Aimbot I’m Testing Out From Wiki…The Code Is:


function aimbot() -- Starting the function

local ply = LocalPlayer() -- Getting ourselves

local trace = util.GetPlayerTrace( ply ) -- Player Trace part. 1

local traceRes = util.TraceLine( trace ) -- Player Trace part. 2

if traceRes.HitNonWorld then -- If the aimbot aims at something that isn't the map..

	local target = traceRes.Entity -- It's obviously an entity.
	
	if target:IsPlayer() or target:IsNPC() then -- But it must be a player or NPC.
	
		local targethead = target:LookupBone("ValveBiped.Bip01_Head1") -- In this aimbot we only aim for the head.
		
		local targetheadpos,targetheadang = target:GetBonePosition(targethead) -- Get the position/angle of the head.
		
		ply:SetEyeAngles((targetheadpos - ply:GetShootPos()):Angle()) -- And finally, we snap our aim to the head of the target.
		
			end
	
		end
	
	end

function On()

hook.Add("Think","aimbot",aimbot)

end

function Off()

hook.Remove("Think","aimbot",aimbot)

end

concommand.Add("On", On)

concommand.Add("Off", Off)

The Problem Is,Is That It Only Snaps To The Target I’m Aiming At
I tried


for id,target in pairs(ents.FindByClass("Player")) do

but all that made it do is try to target me,is there anyways to use the FindByClass code
and exclude ply (LocalPlayer())?

You stole that LUA code right from the wiki, And its supposed to snap to a head when you aim at someone.

If you want to exclude yourself add a simple if statement:



for id, target in ipairs(player.GetAll()) do
     if target != ply then  -- Assuming you kept local ply = LocalPlayer()
          -- The found entity is not the player!
     end  
end 


This code’s by Trivkz, He posted in my thread.
http://www.facepunch.com/showthread.php?t=1010462

Also remember to change “v” to “target” :slight_smile:

Oops :stuck_out_tongue:

[editline]06:59PM[/editline]

I was just testing you guys ^^

It isn’t mandatory to go in order with that, so just use pairs instead of ipairs.

Hey, let’s use a slower method, just because we can!

(pairs is actually faster)

It is?


lua_run local tab = { { { { { { { { { { { { { { { { { { { { { { { { {   }}}}}}}}}}}}}}}}}}}}}}}}} local t1 = os.time() for i = 1 , 10000 do for k , v in ipairs(tab) do MsgN(type(v)) end end t2 = os.time() for i = 1 , 10000 do for k , v in pairs(tab) do MsgN(type(v)) end end t3 = os.time() print(t3 - t2 , t2 - t1)


3<TAB>2

Seems it is.

It is,ipairs orders the table for that scope,while pairs does not.

Go update flapfapflap hack?