End of Round Deathrun Points

[lua]if SERVER then
AddCSLuaFile() – Send the file to the client.

hook.Add( "OnRoundSet", "Round Set Example", function( round, winner )

	if round == ROUND_WAITING then
		print( "We're waiting for the game to start!" )
	elseif round == ROUND_PREPARING then
		print( "The round is preparing!" )
	elseif round == ROUND_ACTIVE then
		print( "Let's play!" )
	elseif round == ROUND_ENDING then
		print( "The winner is "..winner.."!" ) -- If the winner is the timelimit, it will be the number 123.
		if winner != 123 then
			print( team.GetName(winner).." is awesome!" )
		end
	end
end )
return

end[/lua]
This is example code in the deathrun readme.txt.

[lua]if SERVER then
AddCSLuaFile() – Send the file to the client.

hook.Add( "OnRoundSet", "Round Winner Points", function( round, winner )
	if round == 3 then 
		if winner == (2 or 3) then
			if IsValid(ply) and ply:Alive() then
				ply:PS_GivePoints(25)
				ply:PS_GivePoints("You won 25 points for winning the round!")
			end
		end
	end
end )

return

end[/lua]

I have this in my garrysmod/lua/autorun directory. I am not sure what the issue with this it. Can someone help me with my code my steam name is jjt8521.
I am trying to give the winning team players points at the end of round, but I can’t seem to get it working. Also how would I make it so there is a set jackpot (100) points or so, then split it between the winning players?

I assume winner is the team number that won the round, so you need to get all the players on that team. You can’t just index ply randomly if it is never defined in that scope, so what you would do is

[lua]
if winner == (2 or 3) then
for k, ply in pairs(player.GetAll()) do
if ply:Team() == winner then
if IsValid(ply) and ply:Alive() then
ply:PS_GivePoints(25)
ply:ChatPrint(“You won 25 points for winning the round!”)
end
end
end
end
[/lua]

Ok that is what I was trying to figure out. Also to my other questions, how would I count the players alive on the winning team and then split the prize money between them?

Trying that code now. ( worked like a beauty, thank you! )

EDIT: Can the colour of ChatPrint() be changed? I don’t see anything for it on the wiki.

You would use chat.AddText, but that is on clienside; so you would have to send a umsg with the string and then set the colors when you receive it. (You could also use the net library)

This is what I mean if you never sent data from server to client before

[lua]
if IsValid(ply) and ply:Alive() then
ply:PS_GivePoints(25)

umsg.Start("Receive Points Message", ply) --ply is the client who gets the message
	umsg.String("You won 25 points for winning the round!") --message sent to client
umsg.End()



--Now this is in a clientside file

usermessage.Hook("Receive Points Message", function(um) --The first argument is the same name of the message that we sent
	local message = um:ReadString()
	local white = Color(255, 255, 255, 255)
	
	chat.AddText(white, message) --will add the message in a white color to the client
end)

end
[/lua]

Also you really wouldn’t have to even send the string through the usermessage since it will always be the same message, which would also allow you to color the message with several colors easier like so
[lua]
local white = Color(255, 255, 255, 255)
local red = Color(255, 0, 0, 255)

chat.AddText(white, “You won " red, “25”, white, " points for winning the round”) --All the text is in white except the number is in red
[/lua]

[editline]25th August 2013[/editline]

Forget what I just said about not sending the message, I just remembered you want a jackpot thing aswell. This would be the simplest way to do it I think,

[lua]
local jackpot = 100
if winner == (2 or 3) then
local winners = {}

	for k, ply in pairs(team.GetPlayers(winner)) do
		if IsValid(ply) and ply:Alive() then
			table.insert(winners, ply) --So jackpot is only divided among ALIVE players in team
		end
	end
	
	if #winners > 0 then

	        local amount = (jackpot / #winners)

		for k, champ in pairs(winners) do
			champ:PS_GivePoints(amount)
			umsg.Start("Receive Points Message", champ) --ply is the client who gets the message
				umsg.String("You won " ..amount .. " points for winning the round!") --message sent to client
			umsg.End()
		end
	end

end

--Now this is in a clientside file

usermessage.Hook("Receive Points Message", function(um) --The first argument is the same name of the message that we sent
	local message = um:ReadString()
	local white = Color(255, 255, 255, 255)
	
	chat.AddText(white, message) --will add the message in a white color to the client
end)

[/lua]

Were would you put all of that? do you just create a lua file inside autorun and just put all of that?

You can put it in addons with the right file pathing it will load properly.

addons/“folder name”/lua/autorun/“file.lua”

Now when you say --clientside file. Is it fine if I have it set up using

[lua]
if SERVER then
AddCSLuaFile()

my hook("event", "hookname", funtion(round, winner)
end)

return

end

usermessage.Hook(“name”, funtion()
hook stuff
end)
[/lua]

SaintSin6 too great example for this dude)



local amount = 10
  
if round == 3 then
 for k, ply in pairs(team.GetPlayers(winner)) do
 if IsValid(ply) and ply:Alive() then

    ply:PS_GivePoints(amount)

	ply:SendLua("chat.AddText(Color(255,255,255,255),'You won " ..tostring(amount) .. " points for winning the round!')")
 
  end
end
end


ok so using

[lua]ply:SendLua(“chat.AddText(255,255,255,255),‘You won " …tostring(amount) … " points for winning the round!’)”)[/lua]

will send the text to the client and allow the colouring?

Yeah)

Got it all working and commented. Here it is if anyone wants to use it. I dropped the colour all together. I was having to many issues with it. If there is any way I could improve this code please tell me how :slight_smile:

If anyone wants to use this to add end of round points with a jackpot based on the number of players and the winning team feel free to take this and put it in a file inside either of these directories.
garrysmod/lua/autorun/ or garrysmod/addons/folder name/lua/autorun/
[lua]if SERVER then
AddCSLuaFile() – Send the file to the client.

hook.Add("OnRoundSet", "Bonus Round Points", function( round, winner)
	if winner == 2 or winner == 3 or winner == 123 then -- Checks for a winning team
		local players = {}
		for k, ply in pairs(player.GetAll()) do	-- Creates a player tables
			table.insert(players, ply)
		end
		
		if #players >= 5 then -- Checks for 5 players online
			local prizepot = 0 -- Define prize pot
			local increment = 3 -- Death increment points
			if winner == 3 then increment = 6 end -- Runner increment points
			
			for i = 1, #players do -- Creates prize pot based off of the winning team and the number of players online
				prizepot = prizepot + increment
			end
		
			local jackpot = false	
			if math.random(20) == 6 then jackpot = true end -- Attempts for a lucky jackpot (5% chance)
			
			local winners = {}
			for k, ply in pairs(team.GetPlayers(winner)) do -- Finds all players on the winning team
				if IsValid(ply) and ply:Alive() then -- Checks if players are valid and alive
					table.insert(winners, ply)
				end
			end			
		
			local multiplier = 1
			if jackpot then -- Creates jackpot reward and prints jackpot message
				multiplier = math.random(2, 5)
				for k, ply in pairs(player.GetAll()) do
					ply:ChatPrint("* * * * JACKPOT * * * *")
					ply:ChatPrint("The " .. team.GetName(winner) .. "s split a " .. prizepot * multiplier .. " point jackpot between " .. #winners .. " players!")
				end
			end

			if #winners > 0 then -- Checks if there was atleast 1 winner
				local prize = math.Round((prizepot * multiplier) / #winners) -- Divides the points as an integer instead of the chance of a float
				for k, champ in pairs(winners) do -- Gives out the points to the winners and prints messages
					champ:PS_GivePoints(prize)
					champ:PS_Notify("You were awarded " .. prize .. " points for winning!")
					champ:ChatPrint("You were awarded " .. prize .. " points for winning!")
				end
			end
		
		else -- If there are not 5 players online print these messages.
			for k, ply in pairs(player.GetAll()) do 
				ply:ChatPrint( winner == 123 and "Time is up!" or team.GetName(winner).."s have won!" )
				local moreplayers = 5 - #players
				ply:ChatPrint("Round Points Disabled - Need " .. moreplayers .. " more player(s)")
				ply:PS_Notify("Round Points Disabled - Need " .. moreplayers .. " more player(s)")
			end
		end
	end
end)

return

end[/lua]

Just though I’d point out one thing.

[lua]
for k, ply in pairs(players) do – Creates prize pot based off of the winning team and the number of players online
prizepot = prizepot + increment
end
[/lua]

With what you were doing here you could just use a simple for loop since all you doing is increasing something based on the number of items in the table.

[lua]
for i = 1, #players do
prizepot = prizepot + increment
end
[/lua]

Alright thanks added that.

How do you change the amount of points awarded to the player and how do you make the dead team members receive points if their team wins but not as much as the alive players?