Help with pointshop points on round win

I tried to make a script to give points to the winning team if they were alive or dead and give a set amount of points.
I’m fairly new to lua and came up with this. I don’t get any errors in console when trying to use it so i’m kind of stuck. (I apologize for how crappy it looks)


local function TTTWinRoundPoints(result)
if result == WIN_INNOCENT then 
	for _,ply in pairs(player.GetAll() ) do
		if ply:GetRole() == ROLE_INNOCENT or ply:GetRole() == ROLE_DETECTIVE and ply:Alive() then
			ply:PS_GivePoints( 35 )
			ply:PS_Notify("You've been given 35 points for winning and surviving the round as an Innocent!")

		elseif not ply:Alive() and ply:GetRole() == ROLE_INNOCENT or ROLE_DETECTIVE then 
			ply:PS_GivePoints( 15 )
			ply:PS_Notify("Unfortunately, you're dead. You do however get 15 points since your Innocent team has won!")
		end
	end
end

if result == WIN_TRAITOR then
	for _,ply in pairs(player.GetAll() ) do
		if ply:GetRole() == ROLE_TRAITOR and ply:Alive() then
			ply:PS_GivePoints( 70 )
			ply:PS_Notify("You've been given 70 points for winning and surviving the round a Traitor!")

		elseif not ply:Alive() and ply:GetRole() == ROLE_TRAITOR then
			ply:PS_GivePoints( 20 ) 	
			ply:PS_Notify("Unfortunately, you're dead. You do however get 20 points since your Traitor team has won!")
		end
	end
end
end -- end func
hook.Add("TTTEndRound", "WinPoints", TTTWinRoundPoints)

I got it to work, ish. As seen above. The only problem now is, when a traitor is dead and the round as ended where t’s win it says you’ve been given 15 points and the inno’s have won.

Try this. You had a error on the line where you were checking to see what Team they were on and if they were alive or not. You had the checking to see if they were not alive and they were on the Innocent team or if the Detective existed and the Detective team will exist on the TTT gamemode. I fixed this by Checking the Team Once and corrected the syntax then also doing the rest of the checks inside of that if statement. I have not tested it so it may not work.


local function TTTWinRoundPoints(result)
	if result == WIN_INNOCENT then 
		for _,ply in pairs(player.GetAll() ) do
			if (ply:GetRole() == ROLE_INNOCENT or ply:GetRole()== ROLE_DETECTIVE) then
				if ply:Alive() then
					ply:PS_GivePoints( 35 )
					ply:PS_Notify("You've been given 35 points for winning and surviving the round as an Innocent!")
				elseif not ply:Alive() then 
					ply:PS_GivePoints( 15 )
					ply:PS_Notify("Unfortunately, you're dead. You do however get 15 points since your Innocent team has won!")
				end
			end
		end
	elseif result == WIN_TRAITOR then
		for _,ply in pairs(player.GetAll() ) do
			if ply:GetRole() == ROLE_TRAITOR then
				if ply:Alive() then
					ply:PS_GivePoints( 70 )
					ply:PS_Notify("You've been given 70 points for winning and surviving the round a Traitor!")
				elseif not ply:Alive() then
					ply:PS_GivePoints( 20 ) 	
					ply:PS_Notify("Unfortunately, you're dead. You do however get 20 points since your Traitor team has won!")
				end
			end
		end
	end
end -- end func
hook.Add("TTTEndRound", "WinPoints", TTTWinRoundPoints)

[quote=“Jimbo_, post:3, topic:231959”]

Try this. You had a error on the line where you were checking to see what Team they were on and if they were alive or not. You had the checking to see if they were not alive and they were on the Innocent team or if the Detective existed and the Detective team will exist on the TTT gamemode. I fixed this by Checking the Team Once and corrected the syntax then also doing the rest of the checks inside of that if statement. I have not tested it so it may not work.


local function TTTWinRoundPoints(result)
--	if result == WIN_TIMELIMIT then return end 
	if result == WIN_INNOCENT then 
		for _,ply in pairs(player.GetAll() ) do
			if (ply:GetRole() == ROLE_INNOCENT or ply:GetRole()== ROLE_DETECTIVE) then
				if ply:Alive() then
					ply:PS_GivePoints( 35 )
					ply:ChatPrint("You've been given 35 points for winning and surviving the round as an Innocent!")
				elseif not ply:Alive() then 
					ply:PS_GivePoints( 15 )
					ply:ChatPrint("Unfortunately, you're dead. You do however get 15 points since your Innocent team has won!")
				end
			elseif ply:GetRole() == TEAM_SPEC then return
			end
		end
	elseif result == WIN_TRAITOR then
		for _,ply in pairs(player.GetAll() ) do
			if ply:GetRole() == ROLE_TRAITOR then
				if ply:Alive() then
					ply:PS_GivePoints( 70 )
					ply:ChatPrint("You've been given 70 points for winning and surviving the round as a Traitor!")
				elseif not ply:Alive() then
					ply:PS_GivePoints( 20 ) 	
					ply:ChatPrint("Unfortunately, you're dead. You do however get 20 points since your Traitor team has won!")
				end
			elseif ply:GetRole() == TEAM_SPEC then return
			end
		end
	elseif result == WIN_TIMELIMIT then 
		for _,ply in pairs(player.GetAll() ) do
			if (ply:GetRole() == ROLE_INNOCENT or ply:GetRole()== ROLE_DETECTIVE) then
				if ply:Alive() then
					ply:PS_GivePoints( 50 )
					ply:ChatPrint("The time has run out! What are you doing Traitors?! You're awarded 50 points for the wait.")
				elseif not ply:Alive() then 
					ply:PS_GivePoints( 25 )
					ply:ChatPrint("You're dead and you had to wait for the Traitors to do their jobs, here's 25 points for your troubles!")
				end
			end
		end
	end
end -- end func
hook.Add("TTTEndRound", "WinPoints", TTTWinRoundPoints)

-snip- It works great, thank you for the fix! :slight_smile:

Edit: I forgot the posibility of spectators. How would I go about not giving points to them? If a team wins they get points. I tried something with it but I don’t really know how to do it for specs.

Edit 2: I fixed it sorry for the unnecessary comment

Sorry for the bump. A new issue has arised and I have no idea how to fix it. Whenever someone joins the server for the first time and they’re in spectator they get points at the end of the round regardless of the outcome.

What would be name of whoever is placed there? It’s not TEAM_SPEC because that doesn’t seem to be fixing the issue.

If someone is in spectator mode (from being afk) they don’t get points at all which is what I want. It’s confusing.

TEAM_SPEC should work. You can try ply:IsSpec() and see if that works. Also trying to do a print message in the if statement for the spectator:



if ply:IsSpec() then
    ply:PrintMessage(HUD_PRINTTALK, "You're a spectator which means you do not get any points!")
end


Spectators only get points if inno’s win.
I’m confused again.

Well I kept playing around with it, it doesn’t really know when someone is a spectator. I tried to make it print something in the chat box along the lines of “You don’t get points since you’re a spectator” but even that text doesn’t show up. Specs don’t get the points though (which is good) How would I go about making the game print that? I’m fairly sure I just put


elseif ply:GetRole() == TEAM_SPEC then return

in the wrong spot in the code.


elseif ply:IsSpec() and ply:Alive()

Did the same thing as the above code