Spectator now uses new helper functions

This commit is contained in:
Logan G 2022-03-25 23:47:39 -06:00
parent 8b6ecac597
commit 4ca3dac3df
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -5,6 +5,7 @@
--[[ --[[
TODO: Custom HUD (health, armor, etc) TODO: Custom HUD (health, armor, etc)
TODO: Grab binds from game instead of settings TODO: Grab binds from game instead of settings
TODO: Send viewmodel to client and create hologram of viewmodel
TODO: Let user open chatbox TODO: Let user open chatbox
--]] --]]
@ -37,7 +38,7 @@ do
core:log(log.ERROR, "Cannot spawn hologram for freecam!") core:log(log.ERROR, "Cannot spawn hologram for freecam!")
end end
loadHolo = holograms.create(chip():getPos(), Angle(0,0,0), "models/hunter/blocks/cube025x025x025.mdl") loadHolo = holograms.create(chip():getPos(), Angle(0,0,0), "models/hunter/blocks/cube025x025x025.mdl")
loadHolo:setColor(Color(255,255,255,0)) loadHolo:setColor(Color(0,0,0,0))
owner():setViewEntity(loadHolo) owner():setViewEntity(loadHolo)
net.receive("LSFT-LoadHolo-Update", function() net.receive("LSFT-LoadHolo-Update", function()
@ -50,27 +51,16 @@ do
return return
end end
local targets = find.playersByName(args[1]) local target = core:get_entity(args[1])
if target == nil then
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 return
end end
if targets[1]:isPlayer() then if target:isPlayer() then
core:log(log.INFO, "Started spectating \""..targets[1]:getName().."\".") core:log(log.INFO, "Started spectating \""..target:getName().."\".")
net.writeEntity(targets[1]) net.writeEntity(target)
net.send() net.send()
owner():setViewEntity(targets[1]) owner():setViewEntity(target)
end end
end end