• TTT EndRound Hook thinks Spectators are innocents on timelimit win
    2 replies, posted
So in TTT there are 3 types of wins. When an inno wins, a traitor and when the time runs out. I coded a garbage looking addon that works that gives points based on who wins and if the ply is alive. Everything works for when innos/Traitors wins but when the timelimit win hits, spectators are considered to be innocent players. Here is the full code (Again I apologize it doesn't look neat at all. local function TTTWinRoundPoints(result) for _,ply in pairs(player.GetAll() ) do local innocent = ply:GetRole() == ROLE_INNOCENT local detective = ply:GetRole() == ROLE_DETECTIVE local traitor = ply:GetRole() == ROLE_TRAITOR local spectator = ply:GetRole() == TEAM_SPEC or ply:IsSpec() if result == WIN_INNOCENT then if innocent or detective then if ply:Alive() then ply:PS_GivePoints( 20 ) ply:ChatPrint("You've been given 20 points for winning and surviving the round as an Innocent!") elseif not ply:Alive() then  ply:PS_GivePoints( 5 ) ply:ChatPrint("Unfortunately, you're dead. You do however get 5 points since your Innocent team has won!") end elseif spectator then ply:ChatPrint("You're a Spectator, you get no points!") end elseif result == WIN_TRAITOR then if traitor then if ply:Alive() then ply:PS_GivePoints( 40 ) ply:ChatPrint("You've been given 40 points for winning and surviving the round as a Traitor!") elseif not ply:Alive() then  ply:PS_GivePoints( 10 ) ply:ChatPrint("Unfortunately, you're dead. You do however get 10 points since your Traitor team has won!") end elseif spectator then ply:ChatPrint("You're a Spectator, you get no points!") end elseif result == WIN_TIMELIMIT then  if innocent or detective then if ply:Alive() then ply:PS_GivePoints( 25 ) ply:ChatPrint("The time has run out! What are you doing Traitors?! You're awarded 25 points for the wait.") elseif not ply:Alive() and not traitor then ply:PS_GivePoints( 15 ) ply:ChatPrint("You're dead and you had to wait for the Traitors to do their jobs, here's 15 points for your troubles!") end elseif spectator then ply:ChatPrint("You're a Spectator, you get no points!") end end -- Result if/else statement end -- loop end -- Func hook.Add("TTTEndRound", "WinPoints", TTTWinRoundPoints) The code in question is the following: elseif result == WIN_TIMELIMIT then  if innocent or detective then if ply:Alive() then ply:PS_GivePoints( 25 ) ply:ChatPrint("The time has run out! What are you doing Traitors?! You're awarded 25 points for the wait.") elseif not ply:Alive() and not traitor then ply:PS_GivePoints( 15 ) ply:ChatPrint("You're dead and you had to wait for the Traitors to do their jobs, here's 15 points for your troubles!") end elseif spectator then ply:ChatPrint("You're a Spectator, you get no points!") end So when the timelimit hits, and a player is in spectator mode it is supposed to return "You're a Spectator, you get no points!" However they end up getting this: "The time has run out! What are you doing Traitors?! You're awarded 25 points for the wait." If you understand what I'm trying to say any help is appreciated!
To check if player is a forced spectator use local isForcedSpec = ply:IsSpec() and ply:GetForceSpec() Just check it once, on the top of your loop if isForcedSpec then ply:ChatPrint("You're a Spectator, you get no points!") continue end
Unfortunately, that did not work. However, I did find a fix! in every instances where it said: if ply:Alive() then I replaced it to: if ply:Alive() and not spectator then and it managed to work. However I removed the chatprint line and just put a return if the player was a spectator because it wouldn't print it.
Sorry, you need to Log In to post a reply to this thread.