Map Vote Fix

I recently found http://forum.facepunch.com/showthread.php?t=1279250, it seems like a good enough map vote apart from the fact that after it counts down it just continues to add an extra 30 seconds to the round, the map therefore never changes. Would someone be kind enough to edit the code so that it changes the map after the countdown is completed?

Thanks.



if SERVER and GetConVarString("gamemode") == "terrortown" then
	function SQLCheckLast3Maps()
		if sql.TableExists("tttmapvote") then
			local map1 = sql.QueryValue("SELECT map1 FROM tttmapvote WHERE prevmaps = 'prevmaps'")
			local map2 = sql.QueryValue("SELECT map2 FROM tttmapvote WHERE prevmaps = 'prevmaps'")
			local map3 = sql.QueryValue("SELECT map3 FROM tttmapvote WHERE prevmaps = 'prevmaps'")
			return map1,map2,map3
		else
			sql.Query("CREATE TABLE tttmapvote ( prevmaps varchar(255), map1 varchar(255), map2 varchar(255), map3 varchar(255) )")
			sql.Query("INSERT INTO tttmapvote (`prevmaps`, `map1`, `map2`, `map3`) VALUES ('prevmaps', 'nomap', 'nomap', 'nomap')")
		end
	end
	
	function SQLUpdateLast3Maps(map1,map2,map3)
		if sql.TableExists("tttmapvote") then
			sql.QueryValue("UPDATE tttmapvote SET map1 = '"..map1.."' WHERE prevmaps = 'prevmaps'")
			sql.QueryValue("UPDATE tttmapvote SET map2 = '"..map2.."' WHERE prevmaps = 'prevmaps'")
			sql.QueryValue("UPDATE tttmapvote SET map3 = '"..map3.."' WHERE prevmaps = 'prevmaps'")
		else
			SQLCheckLast3Maps()
		end
	end
	
	SQLCheckLast3Maps()
	
	local maps = string.Explode("
",file.Read("ttt_mapcycle.txt", "DATA"))
	local isvoteing = false
	local MapVotes = {}
	local VoteMaps = {}
	local votetimeleft = 0
	local files = file.Find("maps/*", "GAME") 
	
	for k,v in pairs(maps) do
		if file.Exists( "materials/tttvotemap/" ..v.. ".jpg", "GAME" ) then 
			resource.AddFile( "materials/tttvotemap/" ..v..".jpg" )
		end
	end
	
	util.AddNetworkString( "GetVoteMapTable" ) 
	util.AddNetworkString( "GetMapVotesTable" ) 
	util.AddNetworkString( "SendMyVote" ) 
	util.AddNetworkString( "WinVote" ) 
	
	function StartVoteMap()
		votetimeleft = 30
		function UpdateSeconds()
			if votetimeleft > 0 then 
				votetimeleft = votetimeleft - 1 
				timer.Simple(1, UpdateSeconds)
			else
				FindWinningMap()
			end	
		end
		timer.Simple(1, UpdateSeconds)
		local newmaps = {}
		
		local map1,map2,map3 = SQLCheckLast3Maps()
		
		for k,v in pairs(maps) do
			if string.len(v) > 1 and v != game.GetMap() and v != map1 and v != map2 and v != map3 then
				table.insert(newmaps,v)
			end
		end	
		
		local sendingmaps = {} 
		for i = 1, 12 do
			local num = math.random(#newmaps)
			table.insert(sendingmaps,newmaps[num])
			table.remove(newmaps,num)
			MapVotes* = {}
		end
		VoteMaps = sendingmaps
		net.Start( "GetVoteMapTable" )
			net.WriteTable( VoteMaps )
		net.Broadcast()
		
		isvoteing = true
	end
	
	function FindWinningMap()
		local winning = 1
		for k,v in pairs(MapVotes) do
			if #v > #MapVotes[winning] then
				winning = k
			end
		end
		
		net.Start( "WinVote" )
			net.WriteInt(winning,32)
		net.Broadcast()
		
		local map2,map3 = SQLCheckLast3Maps()
		SQLUpdateLast3Maps(game.GetMap(),map2,map3)
		
		timer.Simple(3, function() RunConsoleCommand("ChangeLevel",VoteMaps[winning]) end)
	end
	
	function UpdateVotes()
		if !isvoteing then return end
		net.Start( "GetMapVotesTable" )
			net.WriteTable( MapVotes )
		net.Broadcast()
	end
	
	net.Receive( "SendMyVote", function( len, ply )
		if votetimeleft < 1 then return end
		local mapnum = net.ReadInt(32)
		if MapVotes[mapnum] == nil then MapVotes[mapnum] = {} end
		
		if table.HasValue( MapVotes[mapnum], ply ) then return end
		
		for k,v in pairs(MapVotes) do
			if v == nil then continue end
			for i,e in pairs(MapVotes[k]) do
				if e == ply then
					table.remove(MapVotes[k],i)
				end
			end
		end
		
		table.insert(MapVotes[mapnum], ply)
		
		UpdateVotes()
	end)
	
	function CheckForMapSwitch()
		-- Check for mapswitch
		local rounds_left = math.max(0, GetGlobalInt("ttt_rounds_left", 6) - 1)
		SetGlobalInt("ttt_rounds_left", rounds_left)
		local time_left = math.max(0, (GetConVar("ttt_time_limit_minutes"):GetInt() * 60) - CurTime())
		local nextmap = string.upper(game.GetMapNext())
		local switchmap = false
		if rounds_left <= 0 or time_left <= 0 then
			LANG.Msg("limit_vote")
			switchmap = true
		end
		if switchmap then
			timer.Simple(3,StartVoteMap)
		else
			LANG.Msg("limit_left", {num = rounds_left,
			time = math.ceil(time_left / 60),
			mapname = "with a votemap"})
		end
		return 
	end
	
	hook.Add("TTTDelayRoundStartForVote", "Delay", function()
		return isvoteing
	end)
	
	hook.Add( "Initialize", "ReloadVoteMap", function()
		RunString( file.Read( "lua/autorun/ttt_votemap.lua", "GAME" )) --Hacky way to make sure script is run after ttt, ensures that CheckForMapSwitch() is overun
	end) 
end


if CLIENT then
	surface.CreateFont( "MapVoteFont", {
		font 		= "DebugFixed",
		size 		= 16,
		weight 		= 50,
		blursize 	= 0,
		scanlines 	= 0,
		antialias 	= true,
		underline 	= false,
		italic 		= false,
		strikeout 	= false,
		symbol 		= false,
		rotary 		= false,
		shadow 		= true,
		additive 	= false,
		outline 	= false
	})

	surface.CreateFont( "MapVoteFontTitle", {
		font 		= "DebugFixed",
		size 		= 34,
		weight 		= 50,
		blursize 	= 0,
		scanlines 	= 0,
		antialias 	= true,
		underline 	= false,
		italic 		= false,
		strikeout 	= false,
		symbol 		= false,
		rotary 		= false,
		shadow 		= true,
		additive 	= false,
		outline 	= false
	})

	surface.CreateFont( "MapVoteFontLarge", {
		font 		= "DebugFixed",
		size 		= 22,
		weight 		= 50,
		blursize 	= 0,
		scanlines 	= 0,
		antialias 	= true,
		underline 	= false,
		italic 		= false,
		strikeout 	= false,
		symbol 		= false,
		rotary 		= false,
		shadow 		= true,
		additive 	= false,
		outline 	= false
	})
	
	local VoteMaps = {}
	local MapVotes = {}
	local seconds = 30
	
	local function ShowMapMenu()
		function UpdateSeconds()
			if seconds > 0 then 
				seconds = seconds - 1 
				timer.Simple(1, UpdateSeconds)
				UpdateMapVoteList()
			end
		end
		timer.Simple(1, UpdateSeconds)
		
		local MenuPanel = vgui.Create( "DFrame" )
		MenuPanel:SetSize( ScrW()*0.8, ScrH()*0.7 )
		MenuPanel:Center()
		MenuPanel:SetTitle( "" )
		MenuPanel:SetVisible( true )
		MenuPanel:SetDraggable( false )
		MenuPanel:ShowCloseButton( false )
		MenuPanel:MakePopup()
		MenuPanel.Paint = function(s, w, h)
			draw.RoundedBox(6, 0, 0, w, h, Color(50, 50, 50, 150))
		end
		
		local Titlelbl = vgui.Create("DLabel", MenuPanel)
		Titlelbl:SetFont("MapVoteFontTitle")
		Titlelbl:SetText("Map Voting has started!")
		Titlelbl:SizeToContents()
		Titlelbl:SetTextColor(Color(255,255,255,255))
		Titlelbl:SetPos(25,5)
		
		local xlbl = vgui.Create("DLabel", MenuPanel)
		xlbl:SetFont("MapVoteFontLarge")
		xlbl:SetText("Vote for the map you want to play next.
"..seconds.." seconds left!")
		xlbl:SizeToContents()
		xlbl:SetTextColor(Color(255,255,255,255))
		xlbl:SetPos(25,5 + Titlelbl:GetTall())
		
		local voteslbl = vgui.Create("DLabel", MenuPanel)
		voteslbl:SetFont("MapVoteFontLarge")
		voteslbl:SetText("Votes:")
		voteslbl:SizeToContents()
		voteslbl:SetTextColor(Color(255,255,255,255))
		voteslbl:SetPos(25,MenuPanel:GetTall() * 0.2 + 25)
		
		local VoteListPan = vgui.Create( "DPanel", MenuPanel )
		VoteListPan:SetPos( 25, MenuPanel:GetTall() * 0.2 + 50 )
		VoteListPan:SetSize( MenuPanel:GetWide()*0.2, MenuPanel:GetTall() - 75 - MenuPanel:GetTall() * 0.2 )
		VoteListPan.Paint = function(s, w, h)
			draw.RoundedBox( 6, 0, 0, w, h, Color(100, 100, 100, 150))
		end
		
		local MapIconListPan = vgui.Create( "DPanel", MenuPanel )
		MapIconListPan:SetPos(MenuPanel:GetWide()*0.2 + 50, 100)
		MapIconListPan:SetSize(MenuPanel:GetWide()*0.8 - 75, MenuPanel:GetTall() - 125)
		MapIconListPan.Paint = function(s, w, h)
			draw.RoundedBox( 6, 0, 0, w, h, Color(100, 100, 100, 150))
		end
			
		local MapVoteList = vgui.Create( "DPanelList", VoteListPan )
		
		local MapIconList = vgui.Create( "DIconLayout", MapIconListPan )
		MapIconList:SetPos( 20, 20 )
		MapIconList:SetSize( MapIconListPan:GetWide(), 0 )
		MapIconList:SetSpaceY( 15 )
		MapIconList:SetSpaceX( 15 )
		MapIconList.Paint = function(s, w, h)
			surface.SetDrawColor( 0, 0, 0, 0 )
			surface.DrawRect( 0, 0, w, h )
		end
		
		local PlayerAvatars = {}
		
		for k,v in pairs(player.GetAll()) do		
			local av = vgui.Create("AvatarImage", MapIconListPan)
			av:SetPos(MapIconListPan:GetWide() - (k * 18), MapIconListPan:GetTall() - 18)
			av:SetSize(16, 16)
			av:SetPlayer( v, 16 )
			av:LerpPositions(10)
			PlayerAvatars[v]  = av
		end
		
		local AvatarMapList = {}
		local MapFrames = {}
		 
		for k,v in ipairs(VoteMaps) do
			if k > 12 then break end
			local ListPanel = MapIconList:Add( "DPanel" )
			ListPanel:SetSize( (MapIconListPan:GetWide()-80)/3, (MapIconListPan:GetTall()-90)/4 )
			ListPanel.BGColor = Color(200,200,200,50)
			ListPanel.Paint = function(s,w,h)
				draw.RoundedBox( 6, 0, 0, w, h, s.BGColor)
			end
			MapFrames[k] = ListPanel
			local mapImg = vgui.Create("DImage", ListPanel)
			
			mapImg:SetSize(ListPanel:GetWide()-20,ListPanel:GetTall() - 30)
			mapImg:SetPos(ListPanel:GetWide()/2 - (mapImg:GetWide()/2),5)
			if file.Exists( "materials/tttvotemap/" ..v.. ".jpg", "GAME" ) then 
				mapImg:SetMaterial( "tttvotemap/" ..v.. ".jpg" )
			else 
				mapImg:SetMaterial( "../maps/noicon.png" )
			end
			
			AvatarMapList[k] = mapImg

			if !file.Exists( "maps/"..v..".bsp", "GAME") then
				local misLbl = vgui.Create("DLabel", ListPanel)
				misLbl:SetFont("MapVoteFont")
				misLbl:SetText("Map Missing")
				misLbl:SizeToContents()
				misLbl:SetPos(ListPanel:GetWide()/2 - (misLbl:GetWide()/2),5 + mapImg:GetTall()/2 - misLbl:GetTall()/2)
				misLbl:SetTextColor(Color(255,255,255,255))
			end
			
			local MapAvatarList = vgui.Create( "DIconLayout", mapImg )
			MapAvatarList:SetPos( 0, 0 )
			MapAvatarList:SetSize( mapImg:GetWide(), mapImg:GetTall() )
			MapAvatarList:SetSpaceY( 2 )
			MapAvatarList:SetSpaceX( 2 )
			MapAvatarList.Paint = function(s, w, h)
				surface.SetDrawColor( 0, 0, 0, 0 )
				surface.DrawRect( 0, 0, w, h )
			end
			
			local mapLbl = vgui.Create("DLabel", ListPanel)
			mapLbl:SetFont("MapVoteFont")
			mapLbl:SetText(v)
			mapLbl:SizeToContents()
			mapLbl:SetTextColor(Color(255,255,255,255))
			mapLbl:SetPos(ListPanel:GetWide()/2 - (mapLbl:GetWide()/2), mapImg:GetTall() + 10)
			
			local MapsButton = vgui.Create( "DButton", ListPanel )
			MapsButton:SetSize( ListPanel:GetWide(), ListPanel:GetTall() )
			MapsButton:SetPos(0,0)
			MapsButton:SetText("")
			MapsButton.Paint = function()
			end
			MapsButton.DoClick = function()
				net.Start( "SendMyVote" )
					net.WriteInt(k, 32)
				net.SendToServer()
			end
		end
		
		function WinMapFlash( winnum )
			local winFrame = MapFrames[winnum]
			local oldCol = winFrame.BGColor
			timer.Simple( 0.0, function() winFrame.BGColor = Color( 0, 255, 255, 50 ) surface.PlaySound( "hl1/fvox/blip.wav" ) end )
			timer.Simple( 0.2, function() winFrame.BGColor = oldCol end )
			timer.Simple( 0.4, function() winFrame.BGColor = Color( 0, 255, 255, 50 ) surface.PlaySound( "hl1/fvox/blip.wav" ) end )
			timer.Simple( 0.6, function() winFrame.BGColor = oldCol end )
			timer.Simple( 0.8, function() winFrame.BGColor = Color( 0, 255, 255, 50 ) surface.PlaySound( "hl1/fvox/blip.wav" ) end )
			timer.Simple( 1.0, function() winFrame.BGColor = oldCol end )
			timer.Simple( 3.5, function() MenuPanel:Remove() end )
		end
		
		function UpdateMapVoteList()
			local OffSettab = {
				{1,1},
				{2,1},
				{3,1},
				{1,2},
				{2,2},
				{3,2},
				{1,3},
				{2,3},
				{3,3},
				{1,4},
				{2,4},
				{3,4}
			}
		
			MapVoteList:Remove()
			
			MapVoteList = vgui.Create( "DPanelList", VoteListPan )
			MapVoteList:SetPos(2.5, 2.5)
			MapVoteList:SetSize(VoteListPan:GetWide(), VoteListPan:GetTall())		
			MapVoteList:SetSpacing(5)
			
			local sortedMapVotes = {}
			
			for k,v in pairs(MapVotes) do
				table.insert(sortedMapVotes, {mapnum = k, mapvotes = #v})
			end
			
			table.sort(sortedMapVotes, function(a,b) return a.mapvotes > b.mapvotes end)
			
			for k,v in pairs(sortedMapVotes) do
				if v == nil or next(v) == nil or v.mapvotes < 1 then continue end
				local lbl = vgui.Create("DLabel")
				lbl:SetFont("MapVoteFont")
				lbl:SetText(VoteMaps[v.mapnum].." ("..v.mapvotes..")")
				lbl:SizeToContents()
				lbl:SetSize(lbl:GetWide(), lbl:GetTall() + 5)
				lbl:SetTextColor(Color(0, 0, 0, 0))
				local wid,hei = lbl:GetWide(),lbl:GetTall()
				lbl.Paint = function(s, w, h)
					draw.RoundedBox( 6, 0, 0, w, h, Color(200, 200, 200, 50))
					 
					surface.SetTextColor(Color(255, 255, 255, 255))
					surface.SetFont("MapVoteFont")
					surface.SetTextPos(w/2 - wid/2, h/2 - hei/3 ) 
					surface.DrawText(lbl:GetText())
				end
				MapVoteList:AddItem(lbl)
			end
			
			for k,v in pairs(MapVotes) do
				if v == nil or next(v) == nil then continue end				
				for i,e in pairs(v) do
					if PlayerAvatars[e] == nil then continue end
					local numx = OffSettab[k][1]
					local numy = OffSettab[k][2]
					local yOffset = 0
					local xOffset = (-((i-1) * 21))%-189
					if i > 9 then yOffset = 1 end
					if i > 18 then yOffset = 2 end
					if i > 27 then yOffset = 3 end
					if i > 36 then yOffset = 4 end
					yOffset = yOffset * -21
					local xpos = (MapIconListPan:GetWide()-80)/3 * (numx) + (15 * (numx - 1)) - ((MapIconListPan:GetWide()-80)/6 - (AvatarMapList[k]:GetWide()/2)) + xOffset
					local ypos = (MapIconListPan:GetTall()-90)/4 * (numy) + (15 * (numy - 1)) - 25 + yOffset
					PlayerAvatars[e]:SetPos(xpos, ypos)
				end				
			end
			
			xlbl:SetText("Vote for the map you want to play next.
"..seconds.." seconds left!")
			xlbl:SizeToContents()
		end
		
		net.Receive( "GetMapVotesTable", function(len) 
			MapVotes = net.ReadTable()
			UpdateMapVoteList()
		end)
		
		net.Receive( "WinVote", function(len) 
			WinMapFlash( net.ReadInt(32) )
		end)
	end
	net.Receive( "GetVoteMapTable", function(len)
		VoteMaps = net.ReadTable()
		seconds = 30
		ShowMapMenu()
	end)
end


I don’t think anyone works in some kind of scripting charity.
Your best bet would be to try in Coder hire/recruitment thread.

Okay, thanks for the heads up.