Simple and clean round system with ( almost all ) the tools you need fore a DM gamemode.

Hi, i wanted to be useful so i made a round system for you guy’s!

Before we start off, my apologies for my bad English. i have dyslexia but i still try very hard to make it somewhat readable.

Why did i make this?
Well, i remembered back when i was bad at lua that i was looking for a round system. i found one but it wasn’t that good, so i made one for whoever might need it in the future!
instead of using silly timer ( for the exception of one, but that isn’t serverside :v: ) i made it with a think function. much nicer to use and if it fails, it won’t fail and tell you to wanted to make a joke but these failed me… go away.

Now let’s show some code shall we?
( i hope this scales automatically and doesn’t create a post the size of china… but if it does and i don’t get to it in time, sorry! )
[lua]
//Don’t touch these it will break everything.
GM.gameTime, GM.gameState = 0, 0;

//Small example of what you can do with this
//look at ‘GM:doStuffOnMap()’
GM.mapTable = {
[ “gm_construct” ] = { canScream = true },
[ “gm_flatgrass” ] = { canScream = false },
}

//network strings for playing music.
util.AddNetworkString( “randomMusic” );
util.AddNetworkString( “selectedMusic” );

//These are all the ‘Rounds’. add more if you wish to have more or remove if you wish to have less.
//WARNING if you do add/remove something from this table make sure that:
//‘GAMEMODE.gameState’ points to the next item in the table or that the last round loops it back, in other words ‘GAMEMODE.gameState = 0’
// How long the round lasts can be set with ‘GAMEMODE.gameTime’ and you use it like ‘GAMEMODE.gameTime = CurTime() + 400’
local roundTable = {
[ 0 ] = { func = function()// Round one.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 1;
GAMEMODE:playRandomMusic( true );//Set this to false if you don’t want it to stop all sound.
//GAMEMODE:playSelectedMusic( 1, true ) song 1 and we stop the sound. Commented this out because we already have random music.
/*
// Example on how to use the GAMEMODE:setGameTime()
GAMEMODE:setGameTime( 1, GAMEMODE.gameTime )
*/
GAMEMODE:alertPlayer( “hell yeah!” );
GAMEMODE:doStuffOnMap();

end },
[ 1 ] = { func = function()// Round two.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 2;
GAMEMODE:giveReward();
GAMEMODE:playRandomMusic( true );
GAMEMODE:alertPlayer( “Round two started!” );
GAMEMODE:doStuffOnMap();
end },
[ 2 ] = { func = function()// Round three.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 3;
GAMEMODE:giveReward();
GAMEMODE:playRandomMusic( true );
GAMEMODE:alertPlayer( “Round three started!” );
GAMEMODE:doStuffOnMap();
end },
[ 3 ] = { func = function()// Round four.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 4;
GAMEMODE:giveReward();
GAMEMODE:playRandomMusic( true );
GAMEMODE:alertPlayer( “Round four started!” );
GAMEMODE:doStuffOnMap();
end },
[ 4 ] = { func = function()// Round five.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 5;
GAMEMODE:giveReward();
GAMEMODE:playRandomMusic( true );
GAMEMODE:alertPlayer( “Round five started!” );
GAMEMODE:doStuffOnMap();
end },
[ 5 ] = { func = function()// Round six.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 6;
GAMEMODE:giveReward();
GAMEMODE:playRandomMusic( true );
GAMEMODE:alertPlayer( “Round six started!” );
GAMEMODE:doStuffOnMap();
end },
[ 6 ] = { func = function()// Round seven.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 7;
GAMEMODE:giveReward();
GAMEMODE:playRandomMusic( true );
GAMEMODE:alertPlayer( “Round seven started!” );
GAMEMODE:doStuffOnMap();
end },
[ 7 ] = { func = function()// Round eight.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 0;
GAMEMODE:giveReward();
GAMEMODE:alertPlayer( “Restarting the game in… “…( GAMEMODE.gameTime - CurTime() )…” Seconds!” );
GAMEMODE:slayAll()//KILL THEM ALL!
end },

}

// We handle this shit right here.
hook.Add( “Think”, “RoundHandeler”, function( pl )
if ( roundTable[ GAMEMODE.gameState ].func && GAMEMODE.gameTime < CurTime() ) then
roundTable[ GAMEMODE.gameState ].func();
end
end )

//this is just an example of what you can do with this.
// the music might stop you from hearing the scream, hence the print.
function GM:doStuffOnMap()
if !GAMEMODE.mapTable[ game.GetMap() ] then return; end

if ( GAMEMODE.mapTable[ game.GetMap() ].canScream ) then
	print( "yeah i can scream!" );
	for k, v in pairs( player.GetAll() ) do
		v:EmitSound( "npc/fast_zombie/fz_scream1.wav", 100, 100 );
	end
end

end

function GM:slayAll()
local canStart = true
for k, v in pairs( player.GetAll() ) do
v:SetVelocity( Vector( 0, 0, 50000 ) );
v:EmitSound(“npc/strider/fire.wav”);
timer.Simple( 0.5, function()
v:Kill();
end )
end
end

//Send some text to the player…
function GM:alertPlayer( Notification )
local pl = player.GetAll();
for k, v in pairs( pl ) do
if ( !IsValid( v ) ) then
continue;
end
v:ChatPrint( Notification );
end
end

// If you want to use the time variable for your HUD.
function GM:setGameTime( id , time )
local ent = game.GetWorld();
ent:SetDTFloat( id, time );
end
/*
//WARNING: This is CLIENT side.
//you can then use it with a function like this.
function GM:getGameTime()
local ent = game.GetWorld();
return ent:GetDTFloat( 1 );
end

function GM:HUDPaint()
draw.SimpleText( GAMEMODE:getGameTime(), “default”, 10, 10, Color( 255, 255, 255, 255 ) );
end
*/

//Add your great and awesome rewards right here.
local rewardTable = {
[ 1 ] = “weapon_crowbar”,
[ 2 ] = “weapon_smg1”,
[ 3 ] = “weapon_ar2”,
[ 4 ] = “weapon_rpg”,
}

function GM:giveReward()
local chance;
local pl = player.GetAll();

for k, v in pairs( pl ) do 
	if ( !IsValid( v ) ) then 
		continue; 
	end
	v:StripWeapons();
	chance = math.random( 1, #rewardTable );
	v:Give( rewardTable[ chance ] );
end

end

//Add/change what ever you like.
local songTable = {
[ 1 ] = “music/HL1_song14.mp3”,
[ 2 ] = “music/HL1_song15.mp3”,
[ 3 ] = “music/HL1_song17.mp3”,
[ 4 ] = “music/HL1_song19.mp3”,
[ 5 ] = “music/HL1_song20.mp3”,
[ 6 ] = “music/HL1_song21.mp3”,
[ 7 ] = “music/HL1_song3.mp3”,
[ 8 ] = “music/HL1_song5.mp3”,
[ 9 ] = “music/HL1_song6.mp3”,
[ 10 ] = “music/HL1_song9.mp3”,
[ 11 ] = “music/HL2_intro.mp3”,
[ 12 ] = “music/HL2_song0.mp3”,
[ 13 ] = “music/HL2_song1.mp3”,
[ 14 ] = “music/HL2_song10.mp3”,
[ 15 ] = “music/HL2_song11.mp3”,
[ 16 ] = “music/HL2_song32.mp3”,
[ 17 ] = “music/HL2_song30.mp3”,
[ 18 ] = “music/HL2_song29.mp3”,
[ 19 ] = “music/HL2_song26_trainstation1.mp3”,
[ 20 ] = “music/HL2_song26.mp3”,
[ 21 ] = “music/HL2_song23_suitsong3.mp3”,
[ 22 ] = “music/HL2_song20_submix0.mp3”,
[ 23 ] = “music/HL2_song12_long.mp3”,
[ 24 ] = “music/HL2_song2.mp3”,
}

// I added a boolean here incase you want to… RunConsoleCommand( ‘stopsound’ )?
function GM:playRandomMusic( bool )
local chance = math.random( 1, #songTable );

net.Start( "randomMusic" );  
	net.WriteBit( bool );
	net.WriteString( songTable[ chance ] );
net.Broadcast();

end

/*
//WARNING: This is CLIENT side
//You recieve it like this.
//without the timer it would stop the new sound you’re trying to play.
net.Receive( “randomMusic”, function()
local bool = net.ReadBit()
local music = net.ReadString()

if bool == 1 then 
	RunConsoleCommand( "stopsound" )
end

timer.Simple( 1, function()
	surface.PlaySound( music )   
end ) 

end )
*/

//Add/change what ever you like.
local selectedMusic = {
[ 1 ] = “music/HL1_song14.mp3”,
[ 2 ] = “music/HL1_song15.mp3”,
[ 3 ] = “music/HL1_song17.mp3”,
[ 4 ] = “music/HL1_song19.mp3”,
}

// I added a boolean here incase you want to… RunConsoleCommand( ‘stopsound’ )?
function GM:playSelectedMusic( song, bool )
local chance = math.random( 1, #songTable );

net.Start( "selectedMusic" );  
	net.WriteBit( bool );
	net.WriteString( selectedMusic[ song ] );
net.Broadcast();

end

/*
//WARNING: This is CLIENT side
//You recieve it like this.
//without the timer it would stop the new sound you’re trying to play.
net.Receive( “selectedMusic”, function()
local bool = net.ReadBit()
local music = net.ReadString()

if bool == 1 then 
	RunConsoleCommand( "stopsound" )
end

timer.Simple( 1, function()
	surface.PlaySound( music )   
end ) 

end )
*/
[/lua]

The code speaks for it self, it’s all serverside side unless i tell you otherwise.
I’d recommend that you make a new lua file ‘round_system’ or what ever, and add/include it serverside.

How do i add/remove rounds!?!?!
I explained it above but if you somehow blinded yourself while reading this post or lead from severe memory loss… i’ll explain it again.
what you would do to remove a round is simple, here is an example:

[lua]
local roundTable = {
[ 0 ] = { func = function()// Round one.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 1; //We set this to the next item in the table.

end },
[ 1 ] = { func = function()// Round two.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 0; //We start from 0 again…

end },
}
[/lua]

What you would do to add a round:
[lua]
local roundTable = {
[ 0 ] = { func = function()// Round one.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 1; //We set this to the next item in the table.

end },
[ 1 ] = { func = function()// Round two.
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 2; //We set this to the next item in the table.

end },
[ 2 ] = { func = function()// The new round
GAMEMODE.gameTime = CurTime() + 10;
GAMEMODE.gameState = 0; //We start from 0 again…

end },
}
[/lua]
just make sure that ‘GAMEMODE.gameState’ points to the next item in the table.

So i see this round system… but what are those other functions?
Those are helper function i made for you in case you would ever need them, blast your fantastic dubstep through those headsets or make them listen to your favorite quote from the bible… it’s up to you!

That’s cool, but i would like… [ blank ] to be added!
No problem! if you want something to be added here let me know in the comments below.

Now that that is all done you can start making what ever you want! make a gamemode that’s about raping people in the shortest amount of time or how much potato’s you can collect in 10000 rounds!

**Edit: ** i would like to add that i made this in two hours or so… it’s still better then anything else i could find when i started. that’s my opinion atleast.

-snip-

It’s only useful once you realize darkrp isn’t a deathmatch gamemode.

So i made a dumb mistake… forgot that if you run a function in a k,v loop it will repeat itself * Amount of players :v:

fixed it, cleaned up some stuff and added a couple of things!

New stuff.
[lua]
GM:doStuffOnMap()// you need to include the map name to the table and tell it what todo. table name is ‘GM.mapTable’ NOTE: this is just an example.
GM:slayAll()// SLAY THEM ALL
GM:alertPlayer( Notification )// We had print, but because we only want the round stuff to call once… i made this.
GM:giveReward()//slight changes. remove ‘v:StripWeapons();’ if you want them to keep there weapons
[/lua]

If you want something, i’m still willing to add things!

Maybe just a small hint:
Usually all functions begin with a capital letter, it’s the common syntax used in GMod. Maybe you want to do that in future aswell.

i used to code like that but i started learning java and soon c# in college so i’m forcing myself to code like this. i’ll adapt back if it bothers you guy’s to much. :v:

As long as you are not obsessed with underscores in front of variables, everythings’s fine.
Just wanted to tell you that it’s widely used.

the title ‘Master Of underscores;’ is already taken :v:

but thanks for the tip, i used to prefer it a while ago but i just have to force myself to unlearn my old nasty code habits. since… well, they din’t like it at my college.