Deathrun Code

Recently i have begun setting up a deathrun server, and as a result have noticed how there is a lack of code for deathrun on both facepunch and coderhire. So i decided that it might be a good idea to, post some code i have created here. This list will be updated with code as i create it, and if any of you wish to add code put it in the comments and i will add it to the op.

Please note:
You are free to use this code in any projects that you wish, so long as you credit the original developer and do not sell it.

ALL CODE MUST BE COPYED TO A LUA FILE AND PLACED IN:

garrysmod/lua/autorun/server

Script to give pointshop points to winning team. Easily customizable.



--[[--------Created by prop11 http://steamcommunity.com/id/prop11----------]]

--[[--------POINT CONFIGURATION----------]]

local DEATH_WIN = 60 -- How many points should the Deaths get?
local RUNNER_WIN = 120  -- How many points should the Runners get?

--[[---------DO NOT EDIT BELOW THIS LINE-----]]--
hook.Add( "OnRoundSet", "DeathrunGivePoints", function( round, winner )
	if round != ROUND_ENDING or winner == 123 then return end

	local winp = winner == TEAM_DEATH && DEATH_WIN or RUNNER_WIN
	PrintMessage( 3, "The "..team.GetName(winner).." team has prevailed, and has received ".. tostring(winp) .." points for winning the round." )

	for k,v in pairs( player.GetAll() ) do
		if v:Team() != winner then continue end
		v:PS_GivePoints( winp )
		v:PS_Notify( "You were given "..tostring(winp).." points for winning the round!" )
	end
end)
 

Simple code to add color to players names on the default scoreboard.




--[[--------Created by prop11 http://steamcommunity.com/id/prop11----------]]


if SERVER then
	AddCSLuaFile()

hook.Add( "GetScoreboardNameColor", "Name Color", function( ply )

	if ply:IsUserGroup( "VIP" ) then -- If the player is in the "vip" group
		return Color( 255, 0, 0, 255 ) -- give the player a red name.
	end

end ) 

Simple code to change ulx goup icon on default scoreboard



--[[--------Created by prop11 http://steamcommunity.com/id/prop11----------]]

if SERVER then
	AddCSLuaFile()


hook.Add( "GetScoreboardIcon", "Icon", function( ply )

	if ply:IsUserGroup( "vip" ) then -- If the player is in the "vip" group
		return "icon16/heart.png" -- give the player a heart icon! You can find 16x16 silkicons inside garrysmod/materials/icon16/
	end

end )

**Jackpost system for Deathrun, by SaintSin6 **


--[[ 	Jackpot System for Deathrun

		Install - Place in lua/autorun/
		Steam: http://steamcommunity.com/profiles/76561198009157874
		Message me for tips, suggestions, or help.
	]]
if not SERVER then return end

local playerMin = 5 -- Minimum # of players required
local base = 25 -- Base points
local chance = 2.5 -- Chance of a Jackpot(Percentage)

local function doJackpot( round, winner )
	if round == 4 and winner != ( 2 or 3 or 123 ) then return end -- 2=Deaths, 3=Runners, 123=TimesUp
	if ( #player.GetAll() < playerMin ) then Notify( "Round Points Disabled - Need additional players (" .. playerMin - #player.GetAll() .. " more)" ) return end
	
	if not ( math.random( 100 / chance ) == 1 ) then -- Not a jackpot
		for k, v in pairs( team.GetPlayers( winner ) ) do
			if IsValid( v ) and v:Alive() then
				v:PS_GivePoints( base )
				v:Notify( "You received " .. base .. " points for winning!" )
			end
		end
		return
	end
	
	local increment = ( winner == 3 ) and 6 or 3
	local multi, prizepot, winners = math.random( 2, 5 ), #player.GetAll() * increment + base, {}
	
	for k, v in pairs( team.GetPlayers( winner ) ) do
		if IsValid( v ) and v:Alive() then
			table.insert( winners, v )
		end
	end
	
	if #winners < 1 then return end
	
	Notify(  "* * * * x" .. multi .. " JACKPOT x" .. multi .. " * * * *" )
	Notfiy( "The " .. team.GetName( winner ) .. "s split a " .. prizepot * multi .. " point jackpot between " .. #winners .. " player(s)!" )
	
	for k, v in pairs( winners ) do
		v:PS_GivePoints( prizepot * multi / #winners )
		v:Notify( "You received " .. prizepot * multi / #winners .. " points for winning!" )
	end
end

hook.Add( "OnRoundSet", "EndingJackpot", doJackpot )

-SNIP- I am so tried lol

Probably because there aren’t a lot of “advanced” features that people want to add to a gamemode as simple as Deathrun, so most of the things made for it aren’t worth posting - and anything that is is usually just a fancy HUD or etc that they want to keep to themselves because it makes them feel ~unique~.

Also, cleaned up your code a bit.

[lua]–[[--------Created by prop11 http://steamcommunity.com/id/prop11----------]]

–[[--------POINT CONFIGURATION----------]]

local DEATH_WIN = 60 – How many points should the Deaths get?
local RUNNER_WIN = 120 – How many points should the Runners get?

–[[---------DO NOT EDIT BELOW THIS LINE-----]]–
hook.Add( “OnRoundSet”, “DeathrunGivePoints”, function( round, winner )
if round != ROUND_ENDING or winner == 123 then return end

local winp = winner == TEAM_DEATH && DEATH_WIN or RUNNER_WIN
PrintMessage( 3, "The "..team.GetName(winner).." team has prevailed, and has received ".. tostring(winp) .." points for winning the round." )

for k,v in pairs( player.GetAll() ) do
	if v:Team() != winner then continue end
	v:PS_GivePoints( winp )
	v:PS_Notify( "You were given "..tostring(winp).." points for winning the round!" )
end

end)[/lua]

Thanks shadow, updated OP with new cleaned code.

The main reason for this thread was to help people new, or unable to code to add some extra useful features to deathrun. I thought some may find it useful.

winner == 123?

Yea, 123 represent the 3 deathrun teams 1 = Spectator 2 = Runner 3= Death

When no one wins and the time is up, it returns 123. Never bothered to give a fancy enum, but it does state what it means in the hook examples file when you download the gamemode.

[editline]ayylmao[/editline]
Haha, I never thought of it that way (post above). Only made it that because it was simple and easy to remember

Thats the way i always define my variables and hooks when im calling teams in a gamemode.

Updated with new code :wink:

Where do I paste this code? Or put the file

lua/autorun/server

Ill add it to the OP

More code added :wink:

I don’t think you know how to close an if then statement…? Both of the bottom two examples aren’t going to work.

I had posted this a few months back. Probably could be cleaned up a bit

http://forum.facepunch.com/showthread.php?t=1387309

You should try searching the forums and grabbing some of the stuff that has already been posted. It may require some digging around though.

Its not the complete code, the bottom two i litteraly ripped from a project im working on. Ill post the complete version when its done.

Thanks, ill start that now.