lsft/modules/server/sv_spectate.txt

83 lines
No EOL
2.4 KiB
Text

--@name
--@author
--@server
--[[
TODO: Custom HUD (health, armor, etc)
TODO: Grab binds from game instead of settings
TODO: Send viewmodel to client and create hologram of viewmodel
TODO: Let user open chatbox
--]]
do
local function spectate(args)
local function stopSpectate(reason)
core:log(log.INFO, "Stopped spectating."..(#reason > 0 and "Reason: "..reason or ""))
owner():setViewEntity()
if loadHolo ~= nil then
loadHolo:remove()
end
end
local loadHolo = nil
net.receive("LSFT-Stop-Spectate", function()
stopSpectate(net.readString())
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!")
end
loadHolo = holograms.create(chip():getPos(), Angle(0,0,0), "models/hunter/blocks/cube025x025x025.mdl")
loadHolo:setColor(Color(0,0,0,0))
owner():setViewEntity(loadHolo)
net.receive("LSFT-LoadHolo-Update", function()
loadHolo:setPos(net.readVector())
end)
core:log(log.INFO, "Started spectating.")
net.send()
return
end
local target = core:get_entity(args[1])
if target == nil then
return
end
if target:isPlayer() then
core:log(log.INFO, "Started spectating \""..target:getName().."\".")
net.writeEntity(target)
net.send()
owner():setViewEntity(target)
end
end
core.modules.spectate = {
version = 1,
desc = "Spectate players or freecam.",
commands = {
spectate = {
func = spectate,
usage = "spectate [ply]",
desc = "Spectate a player in first person by specifying a player, or leave arguments empty for freecam.",
},
},
}
core.defaultconfig.spectate = {
speed = 8,
multiplier = 4
}
end