How to make a basic aimbot.

From GMod Wiki

Revision as of 15:31, 10 February 2011 by garry :D (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
How to make a basic Aimbot.
Page white text.png Description:This tutorial will show you how to make a basic aimbot. For educational purposes only.
link=User:Shen Original Author:Shen
Calendar.png Created:September 26, 2010
Notepad-48.png I remind you this tutorial is only for educational purposes.


For this tutorial you need a brain, some lua knowledge and some maths.


Creating the .lua file

I'd recommend you to create the lua file in garrysmod/lua folder instead of garrysmod/lua/autorun/client because it is possible that you can type mistakes, and in that case you have to restart GMod. Name your script "aimbot.lua" Let's start coding, shall we?

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

Okay so we just created the function but it is not completed, we just added some basics needed for the aimbot to function correctly. "trace" basically gets where the player is aiming and "traceRes" uses "trace" to draw a line from the player to infinity or a wall.

	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() then -- But it must be a player.
			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
hook.Add("Think","aimbot",aimbot) -- The hook will spam "aimbot" until it finds a target..

If in any case the player aims at something at isn't the map, the script will save it as "target" and checks next is "target" is a player, if that is the case, the script gets the head of the player, its position and angle and sets the user's view at the head of the target. Finally, we add the hook which will spam the aimbot function until it finds something.

Testing

So now, you just created your first aimbot, but you need to run it. You may want to create a multiplayer game, open the console (~) and type "bot" to add a bot. Next, type in "lua_openscript_cl aimbot.lua". I precise you can also rename the script but you also have to change "aimbot" into the new name. And, finally, aim at the bot and you will automatically snap!

Other

You may also change the bone setting "ValveBiped.Bip01_Head1" to another bone like..

ValveBiped.Bip01_Head1
ValveBiped.Bip01_Neck1
ValveBiped.Bip01_Spine4
ValveBiped.Bip01_Spine2
ValveBiped.Bip01_Spine1
ValveBiped.Bip01_Spine
ValveBiped.Bip01_R_UpperArm
ValveBiped.Bip01_R_Forearm
ValveBiped.Bip01_R_Hand
ValveBiped.Bip01_L_UpperArm
ValveBiped.Bip01_L_Forearm
ValveBiped.Bip01_L_Hand
ValveBiped.Bip01_R_Thigh
ValveBiped.Bip01_R_Calf
ValveBiped.Bip01_R_Foot
ValveBiped.Bip01_R_Toe0
ValveBiped.Bip01_L_Thigh
ValveBiped.Bip01_L_Calf
ValveBiped.Bip01_L_Foot
ValveBiped.Bip01_L_Toe0

Also, make sure you write the bones correctly because Garry's Mod crashes when a bone doesn't exists when it's called.

Here is the whole script if you are the lazy kind.

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() then -- But it must be a player.
			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
hook.Add("Think","aimbot",aimbot) -- The hook will spam "aimbot" until it finds a target..

Enjoy!

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox