93 lines
No EOL
2.6 KiB
Text
93 lines
No EOL
2.6 KiB
Text
--@name
|
|
--@author
|
|
--@server
|
|
|
|
--[[
|
|
TODO: Custom HUD (health, armor, etc)
|
|
TODO: Grab binds from game instead of settings
|
|
TODO: Let user open chatbox
|
|
--]]
|
|
|
|
do
|
|
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!")
|
|
end
|
|
loadHolo = holograms.create(chip():getPos(), Angle(0,0,0), "models/hunter/blocks/cube025x025x025.mdl")
|
|
loadHolo:setColor(Color(255,255,255,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 targets = find.playersByName(args[1])
|
|
|
|
if #targets == 0 or targets == nil then
|
|
core:log(log.ERROR, "No targets found!")
|
|
return
|
|
elseif #targets > 1 then
|
|
local list = ""
|
|
for i, v in pairs(target) do
|
|
list = list..v..", "
|
|
end
|
|
|
|
list:sub(1, -2)
|
|
core:log(log.ERROR, "Muliple targets found! ("..list..")")
|
|
return
|
|
end
|
|
|
|
if targets[1]:isPlayer() then
|
|
core:log(log.INFO, "Started spectating \""..targets[1]:getName().."\".")
|
|
net.writeEntity(targets[1])
|
|
net.send()
|
|
owner():setViewEntity(targets[1])
|
|
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 |