2021-12-16 02:08:16 -05:00
|
|
|
--@name
|
|
|
|
--@author
|
|
|
|
--@server
|
|
|
|
|
|
|
|
--[[
|
|
|
|
TODO: Custom HUD (health, armor, etc)
|
2021-12-22 19:18:07 -05:00
|
|
|
TODO: Grab binds from game instead of settings
|
2022-03-26 01:47:39 -04:00
|
|
|
TODO: Send viewmodel to client and create hologram of viewmodel
|
2021-12-22 19:18:07 -05:00
|
|
|
TODO: Let user open chatbox
|
2021-12-16 02:08:16 -05:00
|
|
|
--]]
|
|
|
|
|
|
|
|
do
|
2021-12-22 19:18:07 -05:00
|
|
|
local function spectate(args)
|
|
|
|
local function stopSpectate()
|
2021-12-16 02:08:16 -05:00
|
|
|
core:log(log.INFO, "Stopped spectating.")
|
|
|
|
owner():setViewEntity()
|
|
|
|
if loadHolo ~= nil then
|
|
|
|
loadHolo:remove()
|
|
|
|
end
|
2021-12-22 19:18:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local loadHolo = nil
|
|
|
|
|
|
|
|
net.receive("LSFT-Stop-Spectate", function()
|
|
|
|
stopSpectate()
|
2021-12-16 02:08:16 -05:00
|
|
|
end)
|
|
|
|
|
2021-12-22 19:18:07 -05:00
|
|
|
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")
|
|
|
|
|
2021-12-16 02:08:16 -05:00
|
|
|
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")
|
2022-03-26 01:47:39 -04:00
|
|
|
loadHolo:setColor(Color(0,0,0,0))
|
2021-12-16 02:08:16 -05:00
|
|
|
owner():setViewEntity(loadHolo)
|
|
|
|
|
|
|
|
net.receive("LSFT-LoadHolo-Update", function()
|
|
|
|
loadHolo:setPos(net.readVector())
|
|
|
|
end)
|
|
|
|
|
|
|
|
core:log(log.INFO, "Started spectating.")
|
|
|
|
|
|
|
|
net.send()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-03-26 01:47:39 -04:00
|
|
|
local target = core:get_entity(args[1])
|
|
|
|
if target == nil then
|
2021-12-16 02:08:16 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-03-26 01:47:39 -04:00
|
|
|
if target:isPlayer() then
|
|
|
|
core:log(log.INFO, "Started spectating \""..target:getName().."\".")
|
|
|
|
net.writeEntity(target)
|
2021-12-16 02:08:16 -05:00
|
|
|
net.send()
|
2022-03-26 01:47:39 -04:00
|
|
|
owner():setViewEntity(target)
|
2021-12-16 02:08:16 -05:00
|
|
|
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
|