metastruct-experiments/heat_seeking_minori.g.lua

51 lines
1.4 KiB
Lua
Raw Permalink Normal View History

-- Code by Henke and Minori
-- to remove the hook please run
-- hook.Remove("StartCommand", "autopilot")
local target = matt
SHOULD_NOCLIP = false
say("[Luadev/follow] Now following", tostring(target))
hook.Add("StartCommand", "autopilot", function(ply, cmd)
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
-- 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
SHOULD_NOCLIP = true
2022-05-22 17:46:43 +00:00
RunConsoleCommand("noclip")
cmd:AddKey(IN_SPEED)
cmd:SetForwardMove(ply:GetRunSpeed())
end
2022-05-14 17:04:04 +00:00
local ang = cmd:GetViewAngles()
local targetAngle = (target:GetShootPos() - ply:GetShootPos()):GetNormalized():Angle()
targetAngle = LerpAngle(0.1, ang, targetAngle)
cmd:SetViewAngles(targetAngle)
end)
-- 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()
if SHOULD_NOCLIP and target:GetPos():Distance(LocalPlayer():GetPos()) < 512 then
SHOULD_NOCLIP = false
RunConsoleCommand("noclip")
end
end)