Hello my Greek coder heroes,
I'm here today to ask for some of your help pertaining your very useful ulx spectate command.
As it stands, the command has a slight flaw that can be abused. If the player who wishes to use the spectate command is already dead, then when said person leaves spectate, it respawns them (or rather Ulib.spawn).
By taking a peak under the sheets, it's understandable because the solution to returning all the players' weapons/items before spectating is to Ulib.spawn the player upon pressing any WASD key.
However, I was wondering if it would be possible to add a few lines in the 'unspectate' function to check if the player is dead. If the player is found dead, then return Ulib.spawn( player,false ) perhaps?
I have given it a shot, but I'm missing knowledge on proper syntax and haven't figured out how to correctly create a call check for a dead player.
Here is the area of the util.lua code that directly affects the unspectate portion of the spectate command:
local function unspectate( player, key )
if calling_ply ~= player then return end -- Not the person we want
if key ~= IN_FORWARD and key ~= IN_BACK and key ~= IN_MOVELEFT and key ~= IN_MOVERIGHT then return end -- Not a key we're interested in
hook.Remove( "PlayerSpawn", "ulx_unspectatedspawn_" .. calling_ply:EntIndex() ) -- Otherwise spawn would cause infinite loop
ULib.spawn( player, true ) -- Get out of spectate.
stopSpectate( player )
player:SetPos( pos )
player:SetAngles( ang )
end
Thanks in advance for any help!