metastruct-experiments/heat_seeking_minori.lua

53 lines
1.4 KiB
Lua
Raw Normal View History

-- Code by Henke and Minori
-- to remove the hook please run
2022-05-14 17:04:04 +00:00
-- hook.Remove("StartCommand", "heatseekingminori")
2022-05-15 01:56:25 +00:00
local target = empy
local shouldNoClip = false
2022-05-14 17:04:04 +00:00
print("[luadev/Autopilot] Now following " .. tostring(target))
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
if target:GetPos():Distance(ply:GetPos()) < 128 then
2022-05-15 01:56:25 +00:00
shouldNoClip = false
return
end
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-05-14 17:04:04 +00:00
-- we wanna run if our target is greater than 256 units
-- 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
if target:GetPos():Distance(ply:GetPos()) > 512 then
2022-05-15 01:56:25 +00:00
shouldNoClip = true
cmd:AddKey(IN_SPEED)
cmd:SetForwardMove(ply:GetRunSpeed())
end
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
local ang = cmd:GetViewAngles()
local targetAngle = (target:GetShootPos() - ply:GetShootPos()):GetNormalized():Angle()
targetAngle = LerpAngle(0.1, ang, targetAngle)
cmd:SetViewAngles(targetAngle)
end)