Advertisement
Guest User

gearbot

a guest
Apr 1st, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.01 KB | None | 0 0
  1. --[[
  2.  
  3. GEARBOT
  4.  
  5. CREDITS TO STEVEN cORTEZ FOR FINDING IT ON THE INTERNET CONGRATS UR GAY
  6.  
  7. notes:
  8. i haven't hooked it up to gear menu, but it will have its own tab when i decide to stop being a laz-e nigger
  9.  
  10.  
  11. --]]
  12.  
  13.  
  14. if SERVER then return end
  15.  
  16. local GB = {}
  17.  
  18. local concommand = concommand
  19. local cvars = cvars
  20. local debug = debug
  21. local ents = ents
  22. local file = file
  23. local hook = hook
  24. local math = math
  25. local spawnmenu = spawnmenu
  26. local string = string
  27. local surface = surface
  28. local table = table
  29. local timer = timer
  30. local util = util
  31. local vgui = vgui
  32.  
  33. local Angle = Angle
  34. local CreateClientConVar = CreateClientConVar
  35. local CurTime = CurTime
  36. local ErrorNoHalt = ErrorNoHalt
  37. local FrameTime = FrameTime
  38. local GetConVarString = GetConVarString
  39. local GetViewEntity = GetViewEntity
  40. local include = include
  41. local ipairs = ipairs
  42. local pairs = pairs
  43. local pcall = pcall
  44. local print = print
  45. local RunConsoleCommand = RunConsoleCommand
  46. local ScrH = ScrH
  47. local ScrW = ScrW
  48. local tonumber = tonumber
  49. local type = type
  50. local unpack = unpack
  51. local ValidEntity = IsValid
  52. local Vector = Vector
  53.  
  54.  
  55.  
  56.  
  57. local LocalPlayer = LocalPlayer
  58.  
  59. do
  60. local hooks = {}
  61. local created = {}
  62. local function CallHook(self, name, args)
  63. if !hooks[name] then return end
  64. for funcName, _ in pairs(hooks[name]) do
  65. local func = self[funcName]
  66. if func then
  67. local ok, err = pcall(func, self, unpack(args or {}))
  68. if !ok then
  69. ErrorNoHalt(err .. "\n")
  70. elseif err then
  71. return err
  72. end
  73. end
  74. end
  75. end
  76. local function RandomName()
  77. local random = ""
  78. for i = 1, math.random(4, 10) do
  79. local c = math.random(65, 116)
  80. if c >= 91 && c <= 96 then c = c + 6 end
  81. random = random .. string.char(c)
  82. end
  83. return random
  84. end
  85. local function AddHook(self, name, funcName)
  86. // If we haven't got a hook for this yet, make one with a random name and store it.
  87. // This is so anti-cheats can't detect by hook name, and so we can remove them later.
  88. if !created[name] then
  89. local random = RandomName()
  90. hook.Add(name, random, function(...) return CallHook(self, name, {...}) end)
  91. created[name] = random
  92. end
  93.  
  94. hooks[name] = hooks[name] or {}
  95. hooks[name][funcName] = true
  96. end
  97.  
  98. local cvarhooks = {}
  99. local function GetCallbackTable(convar)
  100. local callbacks = cvars.GetConVarCallbacks(convar)
  101. if !callbacks then
  102. cvars.AddChangeCallback(convar, function() end)
  103. callbacks = cvars.GetConVarCallbacks(convar)
  104. end
  105. return callbacks
  106. end
  107.  
  108. local function AddCVarHook(self, convar, funcName, ...)
  109. local hookName = "CVar_" .. convar
  110. if !cvarhooks[convar] then
  111. local random = RandomName()
  112.  
  113. local callbacks = GetCallbackTable(convar)
  114. callbacks[random] = function(...)
  115. CallHook(self, hookName, {...})
  116. end
  117.  
  118. cvarhooks[convar] = random
  119. end
  120. AddHook(self, hookName, funcName)
  121. end
  122.  
  123. // Don't let other scripts remove our hooks.
  124. local oldRemove = hook.Remove
  125. function hook.Remove(name, unique)
  126. if created[name] == unique then return end
  127. oldRemove(name, unique)
  128. end
  129.  
  130. // Removes all hooks, useful if reloading the script.
  131. local function RemoveHooks()
  132. for hookName, unique in pairs(created) do
  133. oldRemove(hookName, unique)
  134. end
  135. for convar, unique in pairs(cvarhooks) do
  136. local callbacks = GetCallbackTable(convar)
  137. callbacks[unique] = nil
  138. end
  139. end
  140.  
  141. // Add copies the script can access.
  142. GB.AddHook = AddHook
  143. GB.AddCVarHook = AddCVarHook
  144. GB.CallHook = CallHook
  145. GB.RemoveHooks = RemoveHooks
  146. end
  147.  
  148. concommand.Add("gb_reload", function()
  149. GB:CallHook("Shutdown")
  150. print("Removing hooks...")
  151. GB:RemoveHooks()
  152.  
  153. GB = nil
  154. local info = debug.getinfo(1, "S")
  155. if info && info.short_src then
  156. if string.Left(info.short_src, 3) == "lua" then
  157. info.short_src = string.sub(info.short_src, 5)
  158. end
  159. print("Reloading (" .. info.short_src .. ")...")
  160. include(info.short_src)
  161. else
  162. print("Cannot find AutoAim file, reload manually.")
  163. end
  164. end)
  165. print("AutoAim loaded.")
  166.  
  167. // ##################################################
  168. // MetaTables
  169. // ##################################################
  170.  
  171. local function GetMeta(name)
  172. return table.Copy(FindMetaTable(name) or {})
  173. end
  174.  
  175. local AngM = GetMeta("Angle")
  176. local CmdM = GetMeta("CUserCmd")
  177. local EntM = GetMeta("Entity")
  178. local PlyM = GetMeta("Player")
  179. local VecM = GetMeta("Vector")
  180.  
  181. // ##################################################
  182. // Settings
  183. // ##################################################
  184.  
  185. do
  186. local settings = {}
  187. local function SettingVar(self, name)
  188. return (self.SettingPrefix or "") .. string.lower(name)
  189. end
  190.  
  191. local function RandomName()
  192. local random = ""
  193. for i = 1, math.random(4, 10) do
  194. local c = math.random(65, 116)
  195. if c >= 91 && c <= 96 then c = c + 6 end
  196. random = random .. string.char(c)
  197. end
  198. return random
  199. end
  200.  
  201. local function SetSetting(name, _, new)
  202. if !settings[name] then return end
  203. local info = settings[name]
  204.  
  205. if info.Type == "number" then
  206. new = tonumber(new)
  207. elseif info.Type == "boolean" then
  208. new = (tonumber(new) or 0) > 0
  209. end
  210.  
  211. info.Value = new
  212. end
  213.  
  214. local function CreateSetting(self, name, desc, default, misc)
  215. local cvar = SettingVar(self, name)
  216. local info = {Name = name, Desc = desc, CVar = cvar, Type = type(default), Value = default}
  217.  
  218. for k, v in pairs(misc or {}) do
  219. if !info[k] then info[k] = v end
  220. end
  221.  
  222. // Convert default from boolean to number.
  223. if type(default) == "boolean" then
  224. default = default and 1 or 0
  225. end
  226.  
  227. if !settings[cvar] then
  228. local tab = cvars.GetConVarCallbacks(cvar)
  229. if !tab then
  230. cvars.AddChangeCallback(cvar, function() end)
  231. tab = cvars.GetConVarCallbacks(cvar)
  232. end
  233.  
  234. while true do
  235. local name = RandomName()
  236. if !tab[name] then
  237. tab[name] = SetSetting
  238. info.Callback = name
  239. break
  240. end
  241. end
  242. end
  243.  
  244. settings[cvar] = info
  245. settings[#settings + 1] = info
  246.  
  247. // Create the convar.
  248. CreateClientConVar(cvar, default, (info.Save != false), false)
  249. SetSetting(cvar, _, GetConVarString(cvar))
  250. end
  251. local function GetSetting(self, name)
  252. local cvar = SettingVar(self, name)
  253. if !settings[cvar] then return end
  254. return settings[cvar].Value
  255. end
  256. local function Shutdown()
  257. print("Removing settings callbacks...")
  258. for _, info in ipairs(settings) do
  259. if info.CVar && info.Callback then
  260. local tab = cvars.GetConVarCallbacks(info.CVar)
  261. if tab then
  262. tab[info.Callback] = nil
  263. end
  264. end
  265. end
  266. end
  267. local function SettingsList()
  268. return table.Copy(settings)
  269. end
  270. local function BuildMenu(self, panel)
  271. for _, info in ipairs(settings) do
  272. if info.Show != false then
  273. if info.MultiChoice then
  274. local m = panel:MultiChoice(info.Desc or info.CVar, info.CVar)
  275. for k, v in pairs(info.MultiChoice) do
  276. m:AddChoice(k, v)
  277. end
  278. elseif info.Type == "number" then
  279. panel:NumSlider(info.Desc or info.CVar, info.CVar, info.Min or -1, info.Max or -1, info.Places or 0)
  280. elseif info.Type == "boolean" then
  281. panel:CheckBox(info.Desc or info.CVar, info.CVar)
  282. elseif info.Type == "string" then
  283. panel:TextEntry(info.Desc or info.CVar, info.CVar)
  284. end
  285. end
  286. end
  287. end
  288.  
  289. GB.SettingPrefix = "gb_"
  290. GB.CreateSetting = CreateSetting
  291. GB.Setting = GetSetting
  292. GB.SettingsList = SettingsList
  293. GB.BuildMenu = BuildMenu
  294.  
  295. GB.SettingsShutdown = Shutdown
  296. GB:AddHook("Shutdown", "SettingsShutdown")
  297. end
  298.  
  299.  
  300. // ##################################################
  301. // Targetting - Positions
  302. // ##################################################
  303.  
  304. GB.ModelTarget = {}
  305. function GB:SetModelTarget(model, targ)
  306. self.ModelTarget[model] = targ
  307. end
  308. function GB:BaseTargetPosition(ent)
  309. // The eye attachment is a lot more stable than bones for players.
  310. if type(ent) == "Player" then
  311. local head = EntM["LookupAttachment"](ent, "eyes")
  312. if head then
  313. local pos = EntM["GetAttachment"](ent, head)
  314. if pos then
  315. return pos.Pos - (AngM["Forward"](pos.Ang) * 2)
  316. end
  317. end
  318. end
  319.  
  320. // Check if the model has a special target assigned to it.
  321. local special = self.ModelTarget[string.lower(EntM["GetModel"](ent) or "")]
  322. if special then
  323. // It's a string - look for a bone.
  324. if type(special) == "string" then
  325. local bone = EntM["LookupBone"](ent, special)
  326. if bone then
  327. local pos = EntM["GetBonePosition"](ent, bone)
  328. if pos then
  329. return pos
  330. end
  331. end
  332. // It's a Vector - return a relative position.
  333. elseif type(special) == "Vector" then
  334. return EntM["LocalToWorld"](ent, special)
  335. // It's a function - do something fancy!
  336. elseif type(special) == "function" then
  337. local pos = pcall(special, ent)
  338. if pos then return pos end
  339. end
  340. end
  341.  
  342. // Try and use the head bone, found on all of the player + human models.
  343. local bone = "ValveBiped.Bip01_Head1"
  344. local head = EntM["LookupBone"](ent, bone)
  345. if head then
  346. local pos = EntM["GetBonePosition"](ent, head)
  347. if pos then
  348. return pos
  349. end
  350. end
  351.  
  352. // Give up and return the center of the entity.
  353. return EntM["LocalToWorld"](ent, EntM["OBBCenter"](ent))
  354. end
  355. function GB:TargetPosition(ent)
  356. local targetPos = self:BaseTargetPosition(ent)
  357.  
  358. local ply = LocalPlayer()
  359. if ValidEntity(ply) then
  360. targetPos = self:CallHook("TargetPrediction", {ply, ent, targetPos}) or targetPos
  361. end
  362.  
  363. return targetPos
  364. end
  365.  
  366. GB:SetModelTarget("models/crow.mdl", Vector(0, 0, 5)) // Crow.
  367. GB:SetModelTarget("models/pigeon.mdl", Vector(0, 0, 5)) // Pigeon.
  368. GB:SetModelTarget("models/seagull.mdl", Vector(0, 0, 6)) // Seagull.
  369. GB:SetModelTarget("models/combine_scanner.mdl", "Scanner.Body") // Scanner.
  370. GB:SetModelTarget("models/hunter.mdl", "MiniStrider.body_joint") // Hunter.
  371. GB:SetModelTarget("models/combine_turrets/floor_turret.mdl", "Barrel") // Turret.
  372. GB:SetModelTarget("models/dog.mdl", "Dog_Model.Eye") // Dog.
  373. GB:SetModelTarget("models/vortigaunt.mdl", "ValveBiped.Head") // Vortigaunt.
  374. GB:SetModelTarget("models/antlion.mdl", "Antlion.Body_Bone") // Antlion.
  375. GB:SetModelTarget("models/antlion_guard.mdl", "Antlion_Guard.Body") // Antlion guard.
  376. GB:SetModelTarget("models/antlion_worker.mdl", "Antlion.Head_Bone") // Antlion worker.
  377. GB:SetModelTarget("models/zombie/fast_torso.mdl", "ValveBiped.HC_BodyCube") // Fast zombie torso.
  378. GB:SetModelTarget("models/zombie/fast.mdl", "ValveBiped.HC_BodyCube") // Fast zombie.
  379. GB:SetModelTarget("models/headcrabclassic.mdl", "HeadcrabClassic.SpineControl") // Normal headcrab.
  380. GB:SetModelTarget("models/headcrabblack.mdl", "HCBlack.body") // Poison headcrab.
  381. GB:SetModelTarget("models/headcrab.mdl", "HCFast.body") // Fast headcrab.
  382. GB:SetModelTarget("models/zombie/poison.mdl", "ValveBiped.Headcrab_Cube1") // Poison zombie.
  383. GB:SetModelTarget("models/zombie/classic.mdl", "ValveBiped.HC_Body_Bone") // Zombie.
  384. GB:SetModelTarget("models/zombie/classic_torso.mdl", "ValveBiped.HC_Body_Bone") // Zombie torso.
  385. GB:SetModelTarget("models/zombie/zombie_soldier.mdl", "ValveBiped.HC_Body_Bone") // Zombine.
  386. GB:SetModelTarget("models/combine_strider.mdl", "Combine_Strider.Body_Bone") // Strider.
  387. GB:SetModelTarget("models/combine_dropship.mdl", "D_ship.Spine1") // Combine dropship.
  388. GB:SetModelTarget("models/combine_helicopter.mdl", "Chopper.Body") // Combine helicopter.
  389. GB:SetModelTarget("models/gunship.mdl", "Gunship.Body") // Combine gunship.
  390. GB:SetModelTarget("models/lamarr.mdl", "HeadcrabClassic.SpineControl") // Lamarr!
  391. GB:SetModelTarget("models/mortarsynth.mdl", "Root Bone") // Mortar synth.
  392. GB:SetModelTarget("models/synth.mdl", "Bip02 Spine1") // Synth.
  393. GB:SetModelTarget("models/vortigaunt_slave.mdl", "ValveBiped.Head") // Vortigaunt slave.
  394.  
  395.  
  396. // ##################################################
  397. // Targetting - General
  398. // ##################################################
  399.  
  400. GB.NPCDeathSequences = {}
  401. function GB:AddNPCDeathSequence(model, sequence)
  402. self.NPCDeathSequences = self.NPCDeathSequences or {}
  403. self.NPCDeathSequences[model] = self.NPCDeathSequences[model] or {}
  404. if !table.HasValue(self.NPCDeathSequences[model]) then
  405. table.insert(self.NPCDeathSequences[model], sequence)
  406. end
  407. end
  408.  
  409. GB:AddNPCDeathSequence("models/barnacle.mdl", 4)
  410. GB:AddNPCDeathSequence("models/barnacle.mdl", 15)
  411. GB:AddNPCDeathSequence("models/antlion_guard.mdl", 44)
  412. GB:AddNPCDeathSequence("models/hunter.mdl", 124)
  413. GB:AddNPCDeathSequence("models/hunter.mdl", 125)
  414. GB:AddNPCDeathSequence("models/hunter.mdl", 126)
  415. GB:AddNPCDeathSequence("models/hunter.mdl", 127)
  416. GB:AddNPCDeathSequence("models/hunter.mdl", 128)
  417.  
  418. GB:CreateSetting("friendlyfire", "Target teammates", false)
  419. function GB:IsValidTarget(ent)
  420. // We only want players/NPCs.
  421. local typename = type(ent)
  422. if typename != "NPC" && typename != "Player" then return false end
  423.  
  424. // No invalid entities.
  425. if !ValidEntity(ent) then return false end
  426.  
  427. // Go shoot yourself, emo kid.
  428. local ply = LocalPlayer()
  429. if ent == ply then return false end
  430.  
  431. if typename == "Player" then
  432. if !PlyM["Alive"](ent) then return false end // Dead players FTL.
  433. if !self:Setting("friendlyfire") && PlyM["Team"](ent) == PlyM["Team"](ply) then return false end
  434. if EntM["GetMoveType"](ent) == MOVETYPE_OBSERVER then return false end // No spectators.
  435. if EntM["GetMoveType"](ent) == MOVETYPE_NONE then return false end
  436. //if pl["Team"](ent) == 1001 then return false end
  437. end
  438.  
  439. if typename == "NPC" then
  440. if EntM["GetMoveType"](ent) == MOVETYPE_NONE then return false end // No dead NPCs.
  441.  
  442. // No dying NPCs.
  443. local model = string.lower(EntM["GetModel"](ent) or "")
  444. if table.HasValue(self.NPCDeathSequences[model] or {}, EntM["GetSequence"](ent)) then return false end
  445. end
  446. end
  447.  
  448. GB:CreateSetting("predictblocked", "Predict blocked (time)", 0.4, {Min = 0, Max = 1})
  449. function GB:BaseBlocked(target, offset)
  450. local ply = LocalPlayer()
  451. if !ValidEntity(ply) then return end
  452.  
  453. // Trace from the players shootpos to the position.
  454. local shootPos = PlyM["GetShootPos"](ply)
  455. local targetPos = self:TargetPosition(target)
  456.  
  457. if offset then targetPos = targetPos + offset end
  458.  
  459. local trace = util.TraceLine({start = shootPos, endpos = targetPos, filter = {ply, target}, mask = MASK_SHOT})
  460. local wrongAim = self:AngleBetween(PlyM["GetAimVector"](ply), VecM["GetNormal"](targetPos - shootPos)) > 2
  461.  
  462. // If we hit something, we're "blocked".
  463. if trace.Hit && trace.Entity != target then
  464. return true, wrongAim
  465. end
  466.  
  467. // It is not blocked.
  468. return false, wrongAim
  469. end
  470. function GB:TargetBlocked(target)
  471. if !target then target = self:GetTarget() end
  472. if !target then return end
  473.  
  474. local blocked, wrongAim = self:BaseBlocked(target)
  475. if self:Setting("predictblocked") > 0 && blocked then
  476. blocked = self:BaseBlocked(target, EntM["GetVelocity"](target) * self:Setting("predictblocked"))
  477. end
  478. return blocked, wrongAim
  479. end
  480.  
  481.  
  482. function GB:SetTarget(ent)
  483. if self.Target && !ent then
  484. self:CallHook("TargetLost")
  485. elseif !self.Target && ent then
  486. self:CallHook("TargetGained")
  487. elseif self.Target && ent && self.Target != ent then
  488. self:CallHook("TargetChanged")
  489. end
  490.  
  491. self.Target = ent
  492. end
  493. function GB:GetTarget()
  494. if ValidEntity(self.Target) != false then
  495. return self.Target
  496. else
  497. return false
  498. end
  499. end
  500.  
  501. GB:CreateSetting("maxangle", "Max angle", 30, {Min = 5, Max = 90})
  502. GB:CreateSetting("targetblocked", "Don't check LOS", false)
  503. GB:CreateSetting("holdtarget", "Hold targets", false)
  504. function GB:FindTarget()
  505. if !self:Enabled() then return end
  506.  
  507. local ply = LocalPlayer()
  508. if !ValidEntity(ply) then return end
  509.  
  510. local maxAng = self:Setting("maxangle")
  511. local aimVec, shootPos = PlyM["GetAimVector"](ply), PlyM["GetShootPos"](ply)
  512. local targetBlocked = self:Setting("targetblocked")
  513.  
  514. if self:Setting("holdtarget") then
  515. local target = self:GetTarget()
  516. if target then
  517. local targetPos = self:TargetPosition(target)
  518. local angle = self:AngleBetween(AngM["Forward"](self:GetView()), VecM["GetNormal"](targetPos - shootPos))
  519. local blocked = self:TargetBlocked(target)
  520. if angle <= maxAng && (!blocked || targetBlocked) then return end
  521. end
  522. end
  523.  
  524. // Filter out targets.
  525. local targets = ents.GetAll()
  526. for i, ent in pairs(targets) do
  527. if self:IsValidTarget(ent) == false then
  528. targets[i] = nil
  529. end
  530. end
  531.  
  532. local closestTarget, lowestAngle = _, maxAng
  533. for _, target in pairs(targets) do
  534. if targetBlocked || !self:TargetBlocked(target) then
  535. local targetPos = self:TargetPosition(target)
  536. local angle = self:AngleBetween(AngM["Forward"](self:GetView()), VecM["GetNormal"](targetPos - shootPos))
  537.  
  538. if angle < lowestAngle then
  539. lowestAngle = angle
  540. closestTarget = target
  541. end
  542. end
  543. end
  544.  
  545. self:SetTarget(closestTarget)
  546. end
  547. GB:AddHook("Think", "FindTarget")
  548.  
  549.  
  550. // ##################################################
  551. // Fake view
  552. // ##################################################
  553.  
  554. GB.View = Angle(0, 0, 0)
  555. function GB:GetView()
  556. return self.View * 1
  557. end
  558. function GB:KeepView()
  559. if !self:Enabled() then return end
  560.  
  561. local ply = LocalPlayer()
  562. if !ValidEntity(ply) then return end
  563.  
  564. self.View = EntM["EyeAngles"](ply)
  565. end
  566. GB:AddHook("OnToggled", "KeepView")
  567.  
  568. local sensitivity = 0.022
  569. function GB:RotateView(cmd)
  570. self.View.p = math.Clamp(self.View.p + (CmdM["GetMouseY"](cmd) * sensitivity), -89, 89)
  571. self.View.y = math.NormalizeAngle(self.View.y + (CmdM["GetMouseX"](cmd) * sensitivity * -1))
  572. end
  573.  
  574. GB:CreateSetting("debug", "Debug", false, {Show = false})
  575. function GB:FakeView(ply, origin, angles, FOV)
  576. if !self:Enabled() && !self.SetAngleTo then return end
  577. if GetViewEntity() != LocalPlayer() then return end
  578. if self:Setting("debug") then return end
  579.  
  580. local base = GAMEMODE:CalcView(ply, origin, self.SetAngleTo or self.View, FOV) or {}
  581. base.angles = base.angles or (self.AngleTo or self.View)
  582. base.angles.r = 0 // No crappy screen tilting in ZS.
  583. return base
  584. end
  585. GB:AddHook("CalcView", "FakeView")
  586.  
  587.  
  588. function GB:TargetPrediction(ply, target, targetPos)
  589. local weap = PlyM["GetActiveWeapon"](ply)
  590. if ValidEntity(weap) then
  591. local class = EntM["GetClass"](weap)
  592. if class == "weapon_crossbow" then
  593. local dist = VecM["Length"](targetPos - PlyM["GetShootPos"](ply))
  594. local time = (dist / 3500) + 0.05 // About crossbow bolt speed.
  595. targetPos = targetPos + (EntM["GetVelocity"](target) * time)
  596. end
  597.  
  598. local mul = 0.0075
  599. //targetPos = targetPos - (e["GetVelocity"](ply) * mul)
  600. end
  601.  
  602. return targetPos
  603. end
  604. GB:AddHook("TargetPrediction", "TargetPrediction")
  605.  
  606. // ##################################################
  607. // Aim
  608. // ##################################################
  609.  
  610. function GB:SetAngle(ang)
  611. self.SetAngleTo = ang
  612. end
  613.  
  614. GB:CreateSetting("smoothspeed", "Smooth aim speed (0 to disable)", 120, {Min = 0, Max = 360})
  615. GB:CreateSetting("snaponfire", "Snap on fire", true)
  616. GB:CreateSetting("snapgrace", "Snap on fire grace", 0.5, {Min = 0, Max = 3, Places = 1})
  617. GB.LastAttack = 0
  618. function GB:SetAimAngles(cmd)
  619. self:RotateView(cmd)
  620.  
  621. if !self:Enabled() && !self.SetAngleTo then return end
  622.  
  623. local ply = LocalPlayer()
  624. if !ValidEntity(ply) then return end
  625.  
  626. // We're aiming with the view, normally.
  627. local targetAim = self:GetView()
  628.  
  629. // If we have a target, aim at them!
  630. local target = self:GetTarget()
  631. if target then
  632. local targetPos = self:TargetPosition(target)
  633. targetAim = VecM["Angle"](targetPos - ply:GetShootPos())
  634. end
  635.  
  636. // We're following the view, until we fire.
  637. if self:Setting("snaponfire") then
  638. local time = CurTime()
  639. if PlyM["KeyDown"](ply, IN_ATTACK) || PlyM["KeyDown"](ply, IN_ATTACK2) || self:Setting("autoshoot") != 0 then
  640. self.LastAttack = time
  641. end
  642. if CurTime() - self.LastAttack > self:Setting("snapgrace") then
  643. targetAim = self:GetView()
  644. end
  645. end
  646.  
  647. // We want to change to whatever was SetAngle'd.
  648. if self.SetAngleTo then
  649. targetAim = self.SetAngleTo
  650. end
  651.  
  652. // Smooth aiming.
  653. local smooth = self:Setting("smoothspeed")
  654. if smooth > 0 then
  655. local current = CmdM["GetViewAngles"](cmd)
  656.  
  657. // Approach the target angle.
  658. current = self:ApproachAngle(current, targetAim, smooth * FrameTime())
  659. current.r = 0
  660.  
  661. // If we're just following the view, we don't need to smooth it.
  662. if self.RevertingAim then
  663. local diff = self:NormalizeAngle(current - self:GetView())
  664. if math.abs(diff.p) < 1 && math.abs(diff.y) < 1 then self.RevertingAim = false end
  665. elseif targetAim == self:GetView() then
  666. current = targetAim
  667. end
  668.  
  669. // Check if the angles are the same...
  670. if self.SetAngleTo then
  671. local diff = self:NormalizeAngle(current - self.SetAngleTo)
  672. if math.abs(diff.p) < 1 && math.abs(diff.y) < 1 then self.SetAngleTo = nil end
  673. end
  674.  
  675. aim = current
  676. else
  677. aim = targetAim
  678. self.SetAngleTo = nil
  679. end
  680.  
  681. // Set the angles.
  682. CmdM["SetViewAngles"](cmd, aim)
  683. local sensitivity = 0.22
  684. local diff = aim - CmdM["GetViewAngles"](cmd)
  685. CmdM["SetMouseX"](cmd, diff.y / sensitivity)
  686. CmdM["SetMouseY"](cmd, diff.p / sensitivity)
  687.  
  688.  
  689. // Change the players movement to be relative to their view instead of their aim.
  690. local move = Vector(CmdM["GetForwardMove"](cmd), CmdM["GetSideMove"](cmd), 0)
  691. local norm = VecM["GetNormal"](move)
  692. local set = AngM["Forward"](VecM["Angle"](norm) + (aim - self:GetView())) * VecM["Length"](move)
  693. CmdM["SetForwardMove"](cmd, set.x)
  694. CmdM["SetSideMove"](cmd, set.y)
  695. end
  696. GB:AddHook("CreateMove", "SetAimAngles")
  697.  
  698. function GB:RevertAim()
  699. self.RevertingAim = true
  700. end
  701. GB:AddHook("TargetLost", "RevertAim")
  702. function GB:StopRevertAim()
  703. self.RevertingAim = false
  704. end
  705. GB:AddHook("TargetGained", "RevertAim")
  706.  
  707. // When we turn off the bot, we want our aim to go back to our view.
  708. function GB:ViewToAim()
  709. if self:Enabled() then return end
  710. self:SetAngle(self:GetView())
  711. end
  712. GB:AddHook("OnToggled", "ViewToAim")
  713.  
  714.  
  715. // ##################################################
  716. // HUD
  717. // ##################################################
  718.  
  719. GB:CreateSetting("crosshair", "Crosshair size (0 to disable)", 18, {Min = 0, Max = 20})
  720. function GB:DrawTarget()
  721. if !self:Enabled() then return end
  722.  
  723. local target = self:GetTarget()
  724. if !target then return end
  725.  
  726. local size = self:Setting("crosshair")
  727. if size <= 0 then return end
  728.  
  729. // Change colour on the block status.
  730. local blocked, aimOff = self:TargetBlocked()
  731. if blocked then
  732.  
  733. if GetConVar("gear_screenshot"):GetInt() == 0 then
  734.  
  735. surface.SetDrawColor(255, 0, 0, 255) // Red.
  736.  
  737. end
  738.  
  739. elseif aimOff then
  740.  
  741. if GetConVar("gear_screenshot"):GetInt() == 0 then
  742.  
  743. surface.SetDrawColor(255, 255, 0, 255) // Yellow.
  744. else
  745. surface.SetDrawColor(0, 255, 0, 255) // Green.
  746. end
  747. end
  748.  
  749. // Get the onscreen coordinates for the target.
  750. local pos = self:TargetPosition(target)
  751.  
  752. local screen = VecM["ToScreen"](pos)
  753. local x, y = screen.x, screen.y
  754.  
  755. // Work out sizes.
  756. local a, b = size / 2, size / 6
  757.  
  758. if GetConVar("gear_screenshot"):GetInt() == 0 then
  759.  
  760. // Top left.
  761. surface.DrawLine(x - a, y - a, x - b, y - a)
  762. surface.DrawLine(x - a, y - a, x - a, y - b)
  763.  
  764. // Bottom right.
  765. surface.DrawLine(x + a, y + a, x + b, y + a)
  766. surface.DrawLine(x + a, y + a, x + a, y + b)
  767.  
  768. // Top right.
  769. surface.DrawLine(x + a, y - a, x + b, y - a)
  770. surface.DrawLine(x + a, y - a, x + a, y - b)
  771.  
  772. // Bottom left.
  773. surface.DrawLine(x - a, y + a, x - b, y + a)
  774. surface.DrawLine(x - a, y + a, x - a, y + b)
  775.  
  776. end
  777.  
  778. end
  779. GB:AddHook("HUDPaint", "DrawTarget")
  780.  
  781.  
  782. GB.ScreenMaxAngle = {
  783. Length = 0,
  784. FOV = 0,
  785. MaxAngle = 0
  786. }
  787. GB:CreateSetting("draw_maxangle", "Draw Max Angle", true)
  788. function GB:DrawMaxAngle()
  789. if !self:Enabled() then return end
  790.  
  791. // Check that we want to be drawing this...
  792. local show = GB:Setting("draw_maxangle")
  793. if !show then return end
  794.  
  795. // We need a player for this to work...
  796. local ply = LocalPlayer()
  797. if !ValidEntity(ply) then return end
  798.  
  799. local info = self.ScreenMaxAngle
  800. local maxang = GB:Setting("maxangle")
  801.  
  802. local fov = PlyM["GetFOV"](ply)
  803. if GetViewEntity() == ply && (maxang != info.MaxAngle || fov != info.FOV) then
  804. local view = self:GetView()
  805. view.p = view.p + maxang
  806.  
  807. local screen = (PlyM["GetShootPos"](ply) + (AngM["Forward"](view) * 100))
  808. screen = VecM["ToScreen"](screen)
  809.  
  810. info.Length = math.abs((ScrH() / 2) - screen.y)
  811.  
  812. info.MaxAngle = maxang
  813. info.FOV = fov
  814. end
  815.  
  816. local length = info.Length
  817.  
  818. local cx, cy = ScrW() / 2, ScrH() / 2
  819. for x = -1, 1 do
  820. for y = -1, 1 do
  821. if x != 0 || y != 0 then
  822.  
  823. if GetConVar("gear_screenshot"):GetInt() == 0 then
  824.  
  825. local add = VecM["GetNormal"](Vector(x, y, 0)) * length
  826. surface.SetDrawColor(0, 0, 0, 255)
  827. surface.DrawRect((cx + add.x) - 2, (cy + add.y) - 2, 5, 5)
  828. surface.SetDrawColor(255, 255, 255, 255)
  829. surface.DrawRect((cx + add.x) - 1, (cy + add.y) - 1, 3, 3)
  830.  
  831. end
  832. end
  833. end
  834. end
  835.  
  836. end
  837. GB:AddHook("HUDPaint", "DrawMaxAngle")
  838.  
  839. // ##################################################
  840. // Auto-shoot
  841. // ##################################################
  842.  
  843. GB.AttackDown = false
  844. function GB:SetShooting(bool)
  845. if self.AttackDown == bool then return end
  846. self.AttackDown = bool
  847.  
  848. local pre = {[true] = "+", [false] = "-"}
  849. RunConsoleCommand(pre[bool] .. "attack")
  850. end
  851.  
  852. GB.NextShot = 0
  853. GB:CreateSetting("autoshoot", "Max auto-shoot distance (0 to disable)", 0, {Min = 0, Max = 16384})
  854. function GB:Shoot()
  855. if !self:Enabled() then
  856. self:SetShooting(false)
  857. return
  858. end
  859.  
  860. // Get the maximum distance.
  861. local maxDist = self:Setting("autoshoot")
  862. if maxDist == 0 then return end
  863.  
  864. // Check we've got something to shoot at...
  865. local target = self:GetTarget()
  866. if !target then return end
  867.  
  868. // Don't shoot until we can hit, you idiot!
  869. local blocked, wrongAim = self:TargetBlocked(target)
  870. if blocked || wrongAim then return end
  871.  
  872. // We're gonna need the player object in a second.
  873. local ply = LocalPlayer()
  874. if !ValidEntity(ply) then return end
  875.  
  876. // Check we're within our maximum distance.
  877. local targetPos = self:TargetPosition(target)
  878. local distance = VecM["Length"](targetPos - ply:GetShootPos())
  879. if distance > maxDist && maxDist != -1 then return end
  880.  
  881. // Check if it's time to shoot yet.
  882. if CurTime() < self.NextShot then return end
  883.  
  884. // Check we got our weapon.
  885. local weap = PlyM["GetActiveWeapon"](ply)
  886. if !ValidEntity(weap) then return end
  887.  
  888. // Shoot!
  889. self:SetShooting(true)
  890. // If we're semi-auto, we want to stop holding down fire.
  891. if self:IsSemiAuto(weap) then
  892. timer.Simple(0.05, function() self:SetShooting(false) end)
  893. end
  894.  
  895. // Set the next time to shoot.
  896. self.NextShot = CurTime() + 0.1
  897. end
  898. GB:AddHook("Think", "Shoot")
  899.  
  900. // When we lose our target we stop shooting.
  901. function GB:StopShooting()
  902. self:SetShooting(false)
  903. end
  904. GB:AddHook("TargetLost", "StopShooting")
  905.  
  906. // ##################################################
  907. // Toggle
  908. // ##################################################
  909.  
  910. GB.IsEnabled = false
  911. function GB:Enabled() return self.IsEnabled end
  912.  
  913. function GB:SetEnabled(bool)
  914. if self.IsEnabled == bool then return end
  915. self.IsEnabled = bool
  916.  
  917. local message = {[true] = "ON", [false] = "OFF"}
  918. print("AutoAim " .. message[self.IsEnabled])
  919.  
  920. local e = {[true] = "1", [false] = "0"}
  921. RunConsoleCommand("gb_enabled", e[self.IsEnabled])
  922.  
  923. self:CallHook("OnToggled")
  924. end
  925.  
  926. function GB:Toggle()
  927. self:SetEnabled(!self:Enabled())
  928. end
  929. concommand.Add("gb_toggle", function() GB:Toggle() end)
  930.  
  931. GB:CreateSetting("enabled", "Enabled", false, {Save = false})
  932. function GB:ConVarEnabled(_, old, val)
  933. if old == val then return end
  934. val = tonumber(val) or 0
  935. self:SetEnabled(val > 0)
  936. end
  937. GB:AddCVarHook("gb_enabled", "ConVarEnabled")
  938.  
  939. concommand.Add("+GB", function() GB:SetEnabled(true) end)
  940. concommand.Add("-GB", function() GB:SetEnabled(false) end)
  941.  
  942. // ##################################################
  943. // Menu
  944. // ##################################################
  945.  
  946. function GB:OpenMenu()
  947. local w, h = ScrW() / 3, ScrH() / 2
  948.  
  949. local menu = vgui.Create("DFrame")
  950. menu:SetTitle("AutoAim")
  951. menu:SetSize(w, h)
  952. menu:Center()
  953. menu:MakePopup()
  954.  
  955. local scroll = vgui.Create("DPanelList", menu)
  956. scroll:SetPos(5, 25)
  957. scroll:SetSize(w - 10, h - 30)
  958. scroll:EnableVerticalScrollbar()
  959.  
  960. local form = vgui.Create("DForm", menu)
  961. form:SetName("")
  962. form.Paint = function() end
  963. scroll:AddItem(form)
  964.  
  965. self:BuildMenu(form)
  966.  
  967. if GB.Menu then GB.Menu:Remove() end
  968. GB.Menu = menu
  969. end
  970. concommand.Add("gb_menu", function() GB:OpenMenu() end)
  971.  
  972. function GB:RegisterMenu()
  973. spawnmenu.AddToolMenuOption("Options", "Hacks", "AutoAim", "AutoAim", "", "", function(p) self:BuildMenu(p) end)
  974. end
  975. GB:AddHook("PopulateToolMenu", "RegisterMenu")
  976.  
  977. // ##################################################
  978. // Useful functions
  979. // ##################################################
  980.  
  981. function GB:AngleBetween(a, b)
  982. return math.deg(math.acos(VecM["Dot"](a, b)))
  983. end
  984.  
  985. function GB:NormalizeAngle(ang)
  986. return Angle(math.NormalizeAngle(ang.p), math.NormalizeAngle(ang.y), math.NormalizeAngle(ang.r))
  987. end
  988.  
  989. function GB:ApproachAngle(start, target, add)
  990. local diff = self:NormalizeAngle(target - start)
  991.  
  992. local vec = Vector(diff.p, diff.y, diff.r)
  993. local len = VecM["Length"](vec)
  994. vec = VecM["GetNormal"](vec) * math.min(add, len)
  995.  
  996. return start + Angle(vec.x, vec.y, vec.z)
  997. end
  998.  
  999. local notAuto = {"weapon_pistol", "weapon_rpg", "weapon_357", "weapon_crossbow"}
  1000. function GB:IsSemiAuto(weap)
  1001. if !ValidEntity(weap) then return end
  1002. return (weap.Primary && !weap.Primary.Automatic) || table.HasValue(notAuto, EntM["GetClass"](weap))
  1003. end
  1004.  
  1005. --lol kuro ur a fucking retard
  1006.  
  1007. -- A function to get whether a player is Combine.
  1008. function Schema:PlayerIsCombine(player, bHuman)
  1009.  
  1010. return true;
  1011.  
  1012. end;
  1013.  
  1014. function Schema:GetCinematicIntroInfo()
  1015. return {
  1016. credits = "lmafo I can override this shit, gearvision by johnny.",
  1017. title = "Gearvision, by yours truly <3",
  1018. text = Clockwork.config:Get("intro_text_small"):Get()
  1019. };
  1020. end;
  1021.  
  1022. --nulify flash bangs
  1023.  
  1024. function Schema:AddFlashEffect()
  1025.  
  1026. return false
  1027.  
  1028. end;
  1029.  
  1030. function Schema:AddStunEffect(duration)
  1031.  
  1032. return false
  1033.  
  1034. end;
  1035.  
  1036. --Working on duping items, will complete soon
  1037. --[[
  1038. function ItemDuplicator()
  1039.  
  1040. RunConsoleCommand( "say", "/dropcash 2" )
  1041.  
  1042. end
  1043. hook.Add("Tick", "ItemDuplicator", ItemDuplicator)
  1044. --]]
  1045. --possible way to snag stuff from any container (untested)
  1046. -- A function to get whether the local player can take from storage.
  1047. function Clockwork.storage:CanTakeFrom(itemTable)
  1048.  
  1049. return true
  1050.  
  1051. end;
  1052.  
  1053. -- A function to get whether the local player can give to storage.
  1054. function Clockwork.storage:CanGiveTo(itemTable)
  1055.  
  1056. return true
  1057.  
  1058. end;
  1059.  
  1060. --[[
  1061. -- yep :)
  1062. function ViewCharData(player, arguments)
  1063. local target = Clockwork.player:FindByID( arguments[1] );
  1064.  
  1065. if (target) then
  1066. if (player != target) then
  1067. Clockwork.datastream:Start( player, "EditData", { target, target:GetCharacterData("combinedata") } );
  1068.  
  1069. player.editDataAuthorised = target;
  1070. else
  1071. GearPrintMessage("You cannot view or edit your own data!")
  1072. end;
  1073. else
  1074. GearPrintMessage("Error")
  1075. end;
  1076. end;
  1077. concommand.Add("gear_viewdata",ViewCharData)
  1078. --]]
  1079.  
  1080. -- Called when screen space effects should be rendered.
  1081. function Schema:RenderScreenspaceEffects()
  1082. if (!Clockwork.kernel:IsScreenFadedBlack()) then
  1083. local curTime = CurTime();
  1084.  
  1085. if (self.flashEffect) then
  1086. local timeLeft = math.Clamp( self.flashEffect[1] - curTime, 0, self.flashEffect[2] );
  1087. local incrementer = 1 / self.flashEffect[2];
  1088.  
  1089. if (timeLeft > 0) then
  1090. modify = {};
  1091.  
  1092. modify["$pp_colour_brightness"] = 0;
  1093. modify["$pp_colour_contrast"] = 0;
  1094. modify["$pp_colour_colour"] = 0;
  1095. modify["$pp_colour_addr"] = 0;
  1096. modify["$pp_colour_addg"] = 0;
  1097. modify["$pp_colour_addb"] = 0;
  1098. modify["$pp_colour_mulr"] = 0;
  1099. modify["$pp_colour_mulg"] = 0;
  1100. modify["$pp_colour_mulb"] = 0;
  1101.  
  1102. DrawColorModify(modify);
  1103. end;
  1104. end;
  1105.  
  1106. if (self:PlayerIsCombine(Clockwork.Client)) then
  1107. render.UpdateScreenEffectTexture();
  1108.  
  1109. self.combineOverlay:SetFloat("$refractamount", 0.3);
  1110. self.combineOverlay:SetFloat("$envmaptint", 0);
  1111. self.combineOverlay:SetFloat("$envmap", 0);
  1112. self.combineOverlay:SetFloat("$alpha", 0.5);
  1113. self.combineOverlay:SetInt("$ignorez", 1);
  1114.  
  1115. render.SetMaterial(self.combineOverlay);
  1116. render.DrawScreenQuad();
  1117. end;
  1118. end;
  1119. end;
  1120.  
  1121. --[[
  1122. -- yep :)
  1123. function DupeInv(player, arguments)
  1124.  
  1125. local inventory = player:GetInventory();
  1126.  
  1127. Clockwork.inventory:CreateDuplicate(inventory)
  1128.  
  1129. end;
  1130. concommand.Add("gear_givegear",DupeInv)
  1131. --]]
  1132.  
  1133. --[[
  1134. function Clockwork.salesmenu:GetPriceScale()
  1135. return 0;
  1136. end;
  1137.  
  1138. function Clockwork.salesmenu:BuyInShipments()
  1139. return false;
  1140. end;
  1141.  
  1142. function Clockwork.salesmenu:GetCash()
  1143. return 10000000;
  1144. end;
  1145.  
  1146. -- A function to get the salesman price scale.
  1147. function Clockwork.salesman:GetPriceScale()
  1148. return 0;
  1149. end;
  1150.  
  1151. function Clockwork.salesman:GetCash()
  1152. return 100000;
  1153. end;
  1154.  
  1155. --]]
  1156.  
  1157. --untested
  1158.  
  1159. function Schema:IsCombineFaction(faction)
  1160. return (faction == FACTION_CITIZEN or faction == FACTION_OTA);
  1161. end;
  1162.  
  1163. function Schema:PlayerSetDefaultColorModify(colorModify)
  1164. colorModify["$pp_colour_brightness"] = 0;
  1165. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement