Run Code Faster Than Think?

I’m trying to run a section of code over and over again as fast as possible. The think hook isn’t meeting my needs so I was wondering if anyone knows an efficient way of doing what I need done. I was thinking about creating a timer that runs every 0.000001 seconds but I’m sure there’s a better way.

Why do you want to do this??

The tick hook maybe?

I was afraid someone would ask this… I hope this doesn’t discourage people to help but I’m trying to improve my aimbot. It works pretty well but rarely a shot will miss even with a swep that has no cone or recoil. I’m trying to make it as best as possible. Here’s my code.


local function FindNearestPlayer()
	local target
	local distsqr = math.huge
	local position = LocalPlayer():GetPos()
	for k, v in pairs(player.GetAll()) do
		if LocalPlayer() != v and IsValid(v) and v:Alive() and !table.HasValue(FRIENDS, v) then
			local position2 = v:GetPos()
			if LocalPlayer():IsLineOfSightClear(v) and distsqr > (position.x - position2.x)^2 + (position.y - position2.y)^2 + (position.z - position2.z)^2 then
				target = v
			end
		end
	end
	return target
end

local function Aimbot()
	if AIMBOT_ENABLED and input.IsKeyDown(AIMBOT_KEY) or AIMBOT_RAGE_ENABLED then	
		local target = FindNearestPlayer()
		if IsValid(target) and IsValid(LocalPlayer():GetActiveWeapon()) and target:Alive() and target:IsPlayer() then
			local targethead = target:LookupBone("ValveBiped.Bip01_Head1")
			local targetheadpos, targetheadang = target:GetBonePosition(targethead) + Vector(-2.5, 0, 2.5)
			LocalPlayer():SetEyeAngles((targetheadpos - LocalPlayer():GetShootPos()):Angle())
        end
    end
end
hook.Add("Think", "Aimbot", Aimbot)

Thats called lag

Are you sure? I’m testing on a listen server so my ping should be pretty low, and I’m getting 100-300fps at all times.

Tick is the fastest you’re going to find. If you want your code to execute faster overall, make it more efficient and cache things.

Pretty sure you can’t run code any faster than the frametime

I don’t see why you guys are dumbing him, writing a cheat is one of the best ways to learn lua.

[editline]11th February 2016[/editline]

Also think is called every frame and I don’t think you can run faster than once every frame, creating a timer with a value close to 0 is essentially the same effect as think as well.



while true do
...
end


Your aimbot will never miss again :slight_smile:

Thanks for the advice. Things seems to be slightly faster now however the Think hook seems to be significantly faster than Tick, so I’m going to stick to that.

Run your aiming code in CreateMove / SetupMove instead of Think.

[editline]11th February 2016[/editline]

SetupMove and CreateMove are both ran at exactly the moment the client is about to send data to the server. Running your aiming code here will ensure that you’re always aiming at where your target is when the client is preparing to send data.

Thanks for the tips everyone! I’m going to mark this solved now, everything seems to working fantastic.