2022-04-18 16:10:01 +00:00
|
|
|
-- Code by Henke and Minori
|
|
|
|
-- to remove the hook please run
|
2022-06-09 15:56:07 +00:00
|
|
|
-- hook.Remove("StartCommand", "autopilot")
|
2022-04-18 16:10:01 +00:00
|
|
|
|
2022-06-22 00:56:01 +00:00
|
|
|
local target = phyta
|
2022-06-09 15:56:07 +00:00
|
|
|
SHOULD_NOCLIP = false
|
2022-04-18 16:10:01 +00:00
|
|
|
|
2022-06-09 15:56:07 +00:00
|
|
|
say("[Luadev/follow] Now following", tostring(target))
|
2022-04-18 16:10:01 +00:00
|
|
|
|
2022-06-09 15:56:07 +00:00
|
|
|
hook.Add("StartCommand", "autopilot", function(ply, cmd)
|
2022-04-18 16:10:01 +00:00
|
|
|
if ply ~= LocalPlayer() then return end
|
|
|
|
if not target:Alive() then return end
|
|
|
|
if target:GetPos():Distance(ply:GetPos()) < 128 then
|
2022-05-22 17:46:43 +00:00
|
|
|
return
|
2022-05-15 01:56:25 +00:00
|
|
|
end
|
|
|
|
|
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-06-09 15:56:07 +00:00
|
|
|
SHOULD_NOCLIP = true
|
2022-05-22 17:46:43 +00:00
|
|
|
RunConsoleCommand("noclip")
|
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
|
|
|
|
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)
|
2022-06-09 15:56:07 +00:00
|
|
|
end)
|
|
|
|
|
2022-06-10 03:05:04 +00:00
|
|
|
-- This hook makes sure our noclip disengages
|
|
|
|
-- Because there's no pretty way than to run this every tick
|
|
|
|
-- which is very fucking computationally expensive
|
|
|
|
-- But gmod lua is weirdge
|
|
|
|
hook.Add("Think", "noclip_think", function()
|
2022-06-09 15:56:07 +00:00
|
|
|
if SHOULD_NOCLIP and target:GetPos():Distance(LocalPlayer():GetPos()) < 512 then
|
|
|
|
SHOULD_NOCLIP = false
|
|
|
|
RunConsoleCommand("noclip")
|
|
|
|
end
|
2022-04-18 16:10:01 +00:00
|
|
|
end)
|