ULX

Author Topic: Ulx Spectate  (Read 3813 times)

0 Members and 1 Guest are viewing this topic.

Offline Goku

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Carpe Diem.
    • Fight Club
Ulx Spectate
« on: April 01, 2018, 09:06:01 AM »
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:

     
Code: [Select]
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!  :D
Destruction is a form of creation.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Ulx Spectate
« Reply #1 on: April 01, 2018, 11:43:47 AM »
http://wiki.garrysmod.com/page/Player/Alive

in the unspectate command, 'player' is the Player Object being passed, so you could do this:

player:Alive() to check if they are alive or not.

it will return a boolean. True if they are, false if they are not.

So, if you wanted to wrap the ULib.spawn inside of that, you could do something like this:

Code: [Select]
if player:Alive() then
   ULib.spawn( player, true )
end

I'm not 100% sure if this will work or not for what you are experiencing as it might break unspectating. Give it a try though.

Offline Goku

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Carpe Diem.
    • Fight Club
Re: Ulx Spectate
« Reply #2 on: April 01, 2018, 03:04:04 PM »
Hey MrPresident,

Thanks for the quick reply and help!
I saw that alive command and didn't know if I could reverse it so it checks death. Thanks for the explanation.

So I input what you said, and it semi-worked. A previously dead player using the command would no longer respawn after hitting WASD to leave the ulx spectate. However, said person would be stuck spectating their own dead body and incapable of returning to the natural "spectate members of your team mode" (this is specific to team based gamemodes of course).
I ended up adding "else Ulib.spawn( player, false )" to see if that helped fix the team loop issue. What happens with that is that when you hit WASD to leave ulx spectate, you don't actually leave it (it doesn't show the "You stopped spectating [name]" in chat) but you are returned to the normal team spectating mode.

Code: [Select]
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
if player:Alive() then ULib.spawn( player, true ) else Ulib.spawn( player, false ) end -- Get out of spectate.
stopSpectate( player )
player:SetPos( pos )
player:SetAngles( ang )
end

So I think the two routes to go for fixing this is:
  • Use your more concise version, and tell the script to forcibly rejoin the team spectate mode (I can't begin testing this because I feel like it might be too complex)
  • Otherwise, use my current version, and somehow simply remind the script to leave the ulx spectate mode when pressing WASD if player:Alive() == false for example
Does that sound correct? :)
Destruction is a form of creation.

Offline Goku

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Carpe Diem.
    • Fight Club
Re: Ulx Spectate
« Reply #3 on: April 15, 2018, 08:13:19 AM »
I'm sorry to have to bump this, but having played around with the script some more hasn't led me anywhere new.
If I use MrPresident's small code which works well other than forcing the dead spectator to only look at his/her dead body after using the command.

I believe that to be the cleanest method so far, but I would sill like to find a way that sends a dead spectator back to their team spectating mode, rather than being stuck.

Any new commands I could try?

Thanks!
Destruction is a form of creation.