Round based gamemode

I plan to make a gamemode with a round based mechanic, similar to the stalker gamemode.

Is there any base gamemode for this type of thing or is it something you must do from scratch. If it is a “from scratch” thing could somebody briefly give me an outline of how to do this kind of thing?

You could either just take a gamemode, for example stalker, and use it as a format.

or

you can make a gamemode from scratch. Theres a link below to about the best gamemode scripting tutorial out there.

Click Me!

Building from base gamemmode. The following doesn’t seem to work. I have put print to console debug messages on the round end, round start and player death events but I can’t read them.

When I put a sound on these events it didn’t work also.

No errors in console.
My shared file fixes the error this code will throw by assigning the teams an integer value.

Can anybody help me here?

cl_init.lua only includes shared and nothing else

init.lua


 
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
 
include( "shared.lua" ) 

GM.plyWinner

/*
--------------HOOKS
*/

function GM:PlayerInitialSpawn( ply ) 
/* First time player is on server. Set them to spectate. */
-- count number of players. IF 1 then set this new guy to  stalker and start the round
	ply:SetTeam( TEAM_OW ) 
	ply:Spawn()

end

function GM:PlayerSpawn( ply )
/* Set players gear, spawn, hp etc here. Also reset materials n stuff */
end

function GM:PlayerDisconnected( ply )
	GAMEMODE:CheckEnd()
end

function GM:DoPlayerDeath( ply, attacker, dmginfo )
	print("check end")
	GAMEMODE:CheckEnd()
end

function GM:PlayerDeathSound( ply )
	return true 
	
end

function GM:CheckEnd() 
	print("check end")
	local bTS = false
	local bOW = false
	
	-- count overwatch
	for k,v in pairs( team.GetPlayers( TEAM_OW ) ) do 
		if v:Alive() then 
			bOW = true
			break
		end
	end
	
	-- count stalker
	for k,v in pairs( team.GetPlayers( TEAM_TS ) ) do 
		if v:Alive() then
			bTS = true
			break
		end
	end
	
	if not bOW then
		-- stalker wins
		GAMEMODE:EndRound( TEAM_TS )
	end
	if not bTS then
		-- overwatch win
		GAMEMODE:EndRound( TEAM_OW )
	end
	
end

function GM:EndRound( t )
	print("end of round")
	
	GAMEMODE:StartRound()
	
	
end

function GM:StartRound() 
	print("start of round")
	local bNoWinner = false
	for k,v in pairs( player.GetAll() ) do
		v:SetTeam( TEAM_OW )
		if GAMEMODE.plyWinner then
			if v == GAMEMODE.plyWinner then
				v:SetTeam( TEAM_TS )
			end
		else
			bNoWinner = true
		end
		
		if bNoWinner then
			table.Random( player.GetAll() ):SetTeam( TEAM_TS )
		end
		
		v:Spawn()
		
	end
	
end

shared.lua


GM.Name = "test"
GM.Author = "icle"
GM.Email = "N/A"
GM.Website = "N/A"

TEAM_OW = 1
TEAM_TS = 2

function GM:Initialize()

end 

function GM:CreateTeams()

	team.SetUp( TEAM_OW, "Combine", Color( 70, 230, 230 ), true )
	team.SetSpawnPoint( TEAM_OW, { "info_player_human", "info_player_counterterrorist", "info_player_combine", "info_player_deathmatch" } )
	
	team.SetUp( TEAM_TS, "Stalker", Color( 70, 230, 230 ), true )
	team.SetSpawnPoint( TEAM_TS, { "info_player_stalker", "info_player_terrorist", "info_player_rebel", "info_player_start" } )
	
	team.SetUp( TEAM_SPECTATOR, "Spectators", Color( 80, 255, 150 ), true )
	team.SetSpawnPoint( TEAM_SPECTATOR, { "info_player_counterterrorist", "info_player_combine", "info_player_human", "info_player_deathmatch" } ) 
	team.SetSpawnPoint( TEAM_UNASSIGNED, { "info_player_counterterrorist", "info_player_combine", "info_player_human", "info_player_deathmatch" } ) 


end

Getting one error infact. It is clientside:
Couldn’t include file ‘shared.lua’ (File not found) (@gamemodes/stalker/gamemode/cl_init.lua (line 1))

The shared.lua is definately there, not sure if this is actually causing an issue. The serverside is finding shared just fine.

Its been a really long time since I have actually scripted a gamemode… I wouldnt know what to tell you :suicide:

I’m dum, the global plyWinner needed to be evaluated. Problem solved

Mark the thread as solved if you’re done here. Cleans the place up :slight_smile: