Spectate can now teleport to current position by hitting R

This commit is contained in:
Logan G 2021-12-22 17:18:07 -07:00
parent e3aad2621a
commit c0a09101ab
Signed by: logan
GPG key ID: E328528C921E7A7A
2 changed files with 45 additions and 7 deletions

View file

@ -2,6 +2,11 @@
--@author
--@client
--[[
TODO: Clean this up
TODO: Add keybind for teleport
--]]
if player() == owner() then do
net.start("LSFT-Get-Config")
net.writeString("LSFT-Get-Freecam-Binds")
@ -65,6 +70,16 @@ if player() == owner() then do
return
end
if input.isKeyDown(KEY.R) then
input.lockControls(false)
net.start("LSFT-Teleport-Spectate")
net.writeVector(target:getEyePos())
net.send()
hook.remove("calcview", "freecam")
return
end
return {
origin = target:getEyePos(),
angles = target:getEyeAngles(),
@ -95,6 +110,18 @@ if player() == owner() then do
return
end
if input.isKeyDown(KEY.R) then
input.lockControls(false)
net.start("LSFT-Teleport-Spectate")
net.writeVector(position)
net.send()
hook.remove("calcview", "freecam")
hook.remove("think", "updatepos")
timer.remove("updateholo")
return
end
return {
origin = position,
angles = eyeAngles(),

View file

@ -3,24 +3,35 @@
--@server
--[[
TODO: Draw viewmodel (not possible :c)
TODO: Custom HUD (health, armor, etc)
TODO: Grab binds from game instead of settings
TODO: Let user open chatbox
--]]
do
function spectate(args)
local loadHolo = nil
net.start("LSFT-Start-Spectate")
net.receive("LSFT-Stop-Spectate", function()
local function spectate(args)
local function stopSpectate()
core:log(log.INFO, "Stopped spectating.")
owner():setViewEntity()
if loadHolo ~= nil then
loadHolo:remove()
end
end
local loadHolo = nil
net.receive("LSFT-Stop-Spectate", function()
stopSpectate()
end)
net.receive("LSFT-Teleport-Spectate", function()
local coords = net.readVector()
teleport:tpteleport({coords.x, coords.y, coords.z})
stopSpectate()
end)
net.start("LSFT-Start-Spectate")
if args[1] == nil then
if not holograms.canSpawn() then
core:log(log.ERROR, "Cannot spawn hologram for freecam!")