I recently found [url]http://facepunch.com/showthread.php?t=1279250[/url], 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.
[code]
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("\n",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[i] = {}
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.\n"..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.Creat
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.
Sorry, you need to Log In to post a reply to this thread.