I found this on gm.org and some reason after the map is voted the map changes to the previous map that was played. I went to the data/ttt_map.txt file and edited it but it saves and then I refresh the file and it doesn't save?
[code]AddCSLuaFile()
print("Simple Map Vote loaded!")
Mapvote = {}
Mapvote.mapselection = {}
--TODO: Clean up this code. A lot.
if GetConVarString("gamemode") == "terrortown" and SERVER then
util.AddNetworkString("mapvote_prompt")
util.AddNetworkString("mapvote_castvote")
--Instantiate our variables and tables.
Mapvote.votes = {}
Mapvote.playerlist = {}
Mapvote.voted = false
Mapvote.voting = false
Mapvote.maps = {}
Mapvote.rtvScheduled = false
Mapvote.Initialize = function()
--Establish CVars. They are grouped according to the set they were introduced with.
if not ConVarExists("mapvote_randommaps") then CreateConVar("mapvote_randommaps",3,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_oldestmaps") then CreateConVar("mapvote_oldestmaps",2,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_shuffle") then CreateConVar("mapvote_shuffle",1,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_cycle_delay") then CreateConVar("mapvote_cycle_delay",5,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_rtv") then CreateConVar("mapvote_rtv",1,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_rtv_ratio") then CreateConVar("mapvote_rtv_ratio",0.66,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_rtv_minrounds") then CreateConVar("mapvote_rtv_minrounds",2,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_rtv_minplayers") then CreateConVar("mapvote_rtv_minplayers",2,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_rtv_forcevote") then CreateConVar("mapvote_rtv_forcevote",0,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_start_timeleft") then CreateConVar("mapvote_start_timeleft",0,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_start_roundsleft") then CreateConVar("mapvote_start_roundsleft",1,{ FCVAR_ARCHIVE }) end
if not ConVarExists("mapvote_cycle_forcechange") then CreateConVar("mapvote_cycle_forcechange",1,{ FCVAR_ARCHIVE }) end
--if not ConVarExists("mapvote_rtv_anonymous") then CreateConVar("mapvote_rtv_anonymous",0,{ FCVAR_REPLICATED, FCVAR_ARCHIVE }) end --That was probably a bad idea for a feature.
--Create the file containing the map whitelist.
--This code was originally from the maplist for the game creation menu, and adapted for a more robust map menu.
if file.Exists("ttt_mapcycle.txt", "DATA") == false then
local g_MapList = {}
for k, v in pairs( file.Find( "maps/*.bsp", "GAME" ) ) do
-- Don't add useless maps
local lowername = string.lower( v )
if (string.find( lowername, "^de_") or string.find( lowername, "^ttt_")) then
local Mat = nil
local name = string.gsub( v, ".bsp", "" )
--The map icons are added as clientside assets in case a custom GUI wants to include a preview or something.
Mat = "../maps/"..name..".png"
--We don't need to send these I suppose. Especially if they are causing FastDL issues.
--resource.AddFile(Mat)
g_MapList[ v ] = { Material = Mat, Name = name}
end
end
print("First run, built custom maplist(CSS and TTT)")
print("Writing to maplist file data/ttt_maplist.txt")
for k,v in pairs(g_MapList) do
file.Append("ttt_mapcycle.txt", v.Name.."\n")
end
end
Mapvote.maps = string.Explode("\n",file.Read("ttt_mapcycle.txt", "DATA"))
table.remove(Mapvote.maps) --When reading the file there is a blank entry at the end; remove that.
if not table.HasValue(Mapvote.maps,game.GetMap()) then
print("Current map not on rotation! Adding to map list.")
table.insert(Mapvote.maps,1,game.GetMap())
end
--Pop the current map to the end of the map list. Oldest maps first.
local curMap = table.remove(Mapvote.maps,table.KeyFromValue(Mapvote.maps,game.GetMap()))
table.insert(Mapvote.maps,curMap)
file.Write("ttt_mapcycle.txt", "")
for k,v in pairs(Mapvote.maps) do
file.Append("ttt_mapcycle.txt", v.."\n")
end
print("Server map list:")
PrintTable(Mapvote.maps)
--Generate the voting selection, first by inserting the oldest maps, and then by adding a random selection of maps.
Mapvote.mapselection = {}
local mCount = table.Count(Mapvote.maps)
--Check to make sure the counts are acceptable, so we don't get stuck in an infinite loop.
local oCount = GetConVarNumber("mapvote_oldestmaps")
local rCount = GetConVarNumber("mapvote_randommaps")
if oCount > mCount or oCount < 0 then
oCount = mCount
print("Warning! mapvote_oldestmaps is out of bounds, clamping oldest map count to "..oCount.."")
end
for i=1,oCount do
if Mapvote.maps[i] == nil then break end
table.insert(Mapvote.mapselection,Mapvote.maps[i])
end
if rCount > mCount - oCount or rCount < 0 then
rCount = mCount - oCount
print("Warning! mapvote_randommaps is out of bounds, clamping random map count to "..rCount.."")
rCount = 0
Mapvote.mapselection = Mapvote.maps --Since all maps then are being loaded, just set the selection to the map table.
end
for i=1,rCount do
local id = table.Random(Mapvote.maps)
local maxtries = 5000000+1000000*rCount --An escape should we become stuck in an infinite loop.
local try = 0
while (table.HasValue(Mapvote.mapselection, id) or id == curMap) and not (try > maxtries) do
id = table.Random(Mapvote.maps)
try = try + 1
end
if try > maxtries then
print("Unable to resolve new random maps after "..maxtries.." attempts, skipping.")
print("Consider lowering mapvote_randommaps, or adding more maps to the rotation.")
end
table.insert(Mapvote.mapselection,id)
end
local MapCount = table.Count(Mapvote.mapselection)
--Shuffle the selection
if GetConVarNumber("mapvote_shuffle") == 1 then
for i=1,MapCount do
local current = table.remove(Mapvote.mapselection,math.random(MapCount))
table.insert(Mapvote.mapselection,current)
end
end
print("Votemap map selection:")
PrintTable(Mapvote.mapselection)
end
hook.Add( "Initialize", "mapvote_Initialize", Mapvote.Initialize )
--[[The following hooks and functions are the actual voting component]]--
Mapvote.ReceiveVote = function(len,ply)
if table.HasValue(Mapvote.playerlist, ply) == false and Mapvote.voting == true then
local mapID = net.ReadInt(16)
if mapID <= table.Count(Mapvote.mapselection) and mapID >= 1 then --Make sure the data received is in a valid range.
Mapvote.votes[mapID] = (Mapvote.votes[mapID] or 0) + 1 --Increment mapID the vote was for, or start tally.
table.insert(Mapvote.playerlist, ply)
return
end
end
end
net.Receive( "mapvote_castvote", Mapvote.ReceiveVote )
--Return true if a vote should be started. Called when a new round begins preparing.
Mapvote.ShouldStartVote = function()
if Mapvote.voted == true then return false end
--Check if the server presently meets the requirements for RTV.
local plyCount = table.Count(player.GetAll())
if (GetConVarNumber("mapvote_rtv") or 1) == 1 and (GetConVarNumber("ttt_round_limit") - GetGlobalInt("ttt_rounds_left")) >= (GetConVarNumber("mapvote_rtv_minrounds") or 2) then
if Mapvote.rtvScheduled == true then
print("Starting Mapvote due to RTV")
return true
end
end
--MAXTIME IS IN MINUTES! IMPORTANT DETAIL!
local maxtime = GetConVarNumber("ttt_roundtime_minutes") or 10
if (GetConVarNumber("mapvote_start_timeleft") or 0) == 0 then
if (GetConVarNumber("ttt_haste") or 0) == 1 then
maxtime = (GetConVarNumber("ttt_haste_starting_minutes") or 5) + table.Count(player.GetAll())*(GetConVarNumber("ttt_haste_minutes_per_death") or 0.5)
end
maxtime = maxtime + GetConVarNumber("ttt_preptime_seconds")/60 + GetConVarNumber("ttt_posttime_seconds")/60
else
maxtime = GetConVarNumber("mapvote_start_timeleft") or 15
end
if (GetConVarNumber("mapvote_start_round
Sorry, you need to Log In to post a reply to this thread.