2022-04-18 16:10:01 +00:00
|
|
|
-- Code by Henke and Minori
|
|
|
|
-- to remove the hook please run
|
2022-05-14 17:04:04 +00:00
|
|
|
-- hook.Remove("StartCommand", "heatseekingminori")
|
2022-04-18 16:10:01 +00:00
|
|
|
|
2022-05-15 01:56:25 +00:00
|
|
|
local target = empy
|
|
|
|
local shouldNoClip = false
|
2022-04-18 16:10:01 +00:00
|
|
|
|
2022-05-14 17:04:04 +00:00
|
|
|
print("[luadev/Autopilot] Now following " .. tostring(target))
|
2022-04-18 16:10:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
hook.Add("StartCommand", "heatseekingminori", function(ply, cmd)
|
|
|
|
if ply ~= LocalPlayer() then return end
|
|
|
|
if not target:Alive() then return end
|
2022-05-15 01:56:25 +00:00
|
|
|
|
2022-04-18 16:10:01 +00:00
|
|
|
if target:GetPos():Distance(ply:GetPos()) < 128 then
|
2022-05-15 01:56:25 +00:00
|
|
|
shouldNoClip = false
|
2022-04-18 16:10:01 +00:00
|
|
|
return
|
|
|
|
end
|
2022-04-18 18:46:43 +00:00
|
|
|
|
2022-05-15 01:56:25 +00:00
|
|
|
if not shouldNoClip then
|
|
|
|
if not shouldNoClip then return else RunConsoleCommand("noclip") end
|
|
|
|
else
|
|
|
|
RunConsoleCommand("noclip")
|
|
|
|
end
|
|
|
|
|
2022-04-18 18:46:43 +00:00
|
|
|
|
2022-05-14 17:04:04 +00:00
|
|
|
-- we wanna run if our target is greater than 256 units
|
2022-04-18 16:10:01 +00:00
|
|
|
-- that way we can still catch up
|
2022-05-14 17:04:04 +00:00
|
|
|
if target:GetPos():Distance(ply:GetPos()) > 256 then
|
|
|
|
cmd:AddKey(IN_SPEED)
|
|
|
|
cmd:SetForwardMove(ply:GetRunSpeed())
|
|
|
|
else
|
|
|
|
cmd:SetForwardMove(ply:GetWalkSpeed())
|
|
|
|
end
|
|
|
|
|
2022-05-15 01:56:25 +00:00
|
|
|
-- if farther than 512 units away, noclip
|
2022-04-18 16:10:01 +00:00
|
|
|
if target:GetPos():Distance(ply:GetPos()) > 512 then
|
2022-05-15 01:56:25 +00:00
|
|
|
shouldNoClip = true
|
2022-04-18 16:10:01 +00:00
|
|
|
cmd:AddKey(IN_SPEED)
|
|
|
|
cmd:SetForwardMove(ply:GetRunSpeed())
|
2022-04-18 18:46:43 +00:00
|
|
|
end
|
2022-04-18 16:10:01 +00:00
|
|
|
|
2022-05-14 17:04:04 +00:00
|
|
|
-- This is too far now, we need to TP at this rate.
|
2022-05-15 01:56:25 +00:00
|
|
|
if target:GetPos():Distance(ply:GetPos()) > 4096 then
|
|
|
|
RunConsoleCommand("aowl", "tp", target:Name())
|
2022-05-14 17:04:04 +00:00
|
|
|
end
|
|
|
|
|
2022-04-18 16:10:01 +00:00
|
|
|
local ang = cmd:GetViewAngles()
|
|
|
|
local targetAngle = (target:GetShootPos() - ply:GetShootPos()):GetNormalized():Angle()
|
|
|
|
targetAngle = LerpAngle(0.1, ang, targetAngle)
|
|
|
|
|
|
|
|
cmd:SetViewAngles(targetAngle)
|
|
|
|
end)
|