• How to make this TTT Map Vote have a cooldown?
    6 replies, posted
How do I make the following code have a map cooldown? [lua] --Amount of players who have to request a vote, 1=all, 0.5=half of everyone local votereqperc= 0.75 --Voting time local votetime = 20 --Checks if gamemode is terrortown if GetConVarString("gamemode") == "terrortown" then --Server side if SERVER then local votestarted = false local voteoverride = false local votestartrequests={} local currentvotes={} local playerlist={} util.AddNetworkString("serverWantsAVote") util.AddNetworkString("userChangedVote") util.AddNetworkString("broadcastUserVoteChange") util.AddNetworkString("mapVotingClosed") util.AddNetworkString("playerWantsToStartVote") RunConsoleCommand("mapcyclefile", "data/mapscyclething.txt") if file.Exists("mapcyclething.txt", "DATA") != false then file.Delete("mapcyclething.txt") end local maplist={} for k,v in pairs(file.Find("maps/*.bsp", "GAME") ) do local lowercasename = string.lower(v) if (string.find(lowercasename, "yeahhh") or string.find(lowercasename, "wham_city") or string.find(lowercasename, "^ttt_")) then local mat = nil local Category = "Other" local name= string.gsub(v, ".bsp", "") mat="../maps/"..name..".png" resource.AddFile(mat) maplist[v]={Material = mat, Name = name} end end for k,v in pairs(maplist) do file.Append("mapcyclething.txt", v.Name.."\n") end local maps = string.Explode("\n",file.Read("mapcyclething.txt","DATA")) table.remove(maps) if not table.HasValue(maps,game.GetMap()) then table.insert(maps, 1, game.GetMap()) end local curmap=table.remove(maps,table.KeyFromValue(maps, game.GetMap())) table.insert(maps, curmap) file.Write("mapcyclething.txt","") for k,v in pairs(maps) do file.Append("mapcyclething.txt", v.."\n") end net.Receive("userChangedVote",function(len, ply) local mapID=net.ReadInt(16) playerlist[ply:UniqueID()]=mapID net.Start("broadcastUserVoteChange") net.WriteInt(mapID,16) net.WriteString(ply:UniqueID()) net.Broadcast() end) function votingEnded() for k,v in pairs(playerlist) do currentvotes[v]=currentvotes[v]+1 end local currmap=1 local maxvotes=0 for i=1,table.Count(maps) do if currentvotes[i]>maxvotes then maxvotes=currentvotes[i] currmap=i end end print("Winning map is "..maps[currmap]) for _, v in pairs(player.GetAll()) do v:ChatPrint( "Winning map is "..maps[currmap].."! Loading..." ) end timer.Simple(5,function() RunConsoleCommand("changelevel", maps[currmap]) end) net.Start("mapVotingClosed") net.Broadcast() votestarted=false end --hook.Add("TTTBeginRound", "roundReallyStart", votingEnded) local voteover=false function startVoteMaybe() local maxtime = GetConVarNumber("ttt_roundtime_minutes") or 10 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") + GetConVarNumber("ttt_posttime_seconds") if GetGlobalInt("ttt_rounds_left", 6) == 1 or math.floor(((GetGlobalInt("ttt_time_limit_minutes") or 30)*60 - (CurTime()/60))) <= maxtime or voteoverride then if voteover == false then voteoverride = false print("Sending vote request") votestarted=true net.Start("serverWantsAVote") for i=1,table.Count(maps) do currentvotes[i]=0 end net.WriteTable(maps) net.Broadcast() timer.Simple(votetime, function() votingEnded() end ) voteover=true return true end end return false end -- hook.Add( "TTTPrepareRound", "roundStartThingy",startVoteMaybe) hook.Add( "TTTDelayRoundStartForVote", "roundStartThingy",startVoteMaybe) function voterequested(ply,strText,plyalive) if string.Explode(" ", strText)[1] == "!letsvote" then if voteoverride == false then if votestartrequests[ply:UniqueID()] == 1 then return "" end votestartrequests[ply:UniqueID()] = 1 local playercount=table.Count(player:GetAll()) playercount=math.floor(playercount*votereqperc) if playercount < 1 then playercount = 1 end local votes=0 for k,v in pairs(player:GetAll()) do if votestartrequests[v:UniqueID()] == 1 then votes=votes+1 end end if votes >= playercount then voteoverride=true end net.Start("playerWantsToStartVote") net.WriteString(ply:GetName()) net.WriteInt(playercount,16) net.WriteInt(votes,16) net.Broadcast() return "" end end return strText end hook.Add("PlayerSay", "startvotemaybe", voterequested) end end --Client Side if CLIENT then util.PrecacheSound("UI/buttonclick.wav") local cl_mapvote = nil local votebuttons = {} local avatars = {} local playerlists = {} local currentvotes= {} local oldvotes = {} local playerVelX={} local playerVelY={} local playerPosX={} local playerPosY={} local listopened=false local btnW=400 local btnH=20 local spacing=4 --Update loop function thinking() if cl_mapvote != nil and listopened then gui.EnableScreenClicker(true) cl_mapvote:MoveToFront() for k,v in pairs(player.GetAll()) do local id = v:UniqueID() if avatars[id] != nil and currentvotes[id]!=0 then local position = 1 for k,v in pairs(playerlists[currentvotes[id]]) do if v == id then position = k end end local x = playerPosX[id] local y = playerPosY[id] local vx = playerVelX[id] local vy = playerVelY[id] local x2,y2 = votebuttons[currentvotes[id]]:GetPos() x2 = x2+btnW-(btnH*(position)) local speed = 0.01 local dx = (x2-x) local dy = (y2-y) local dist = math.sqrt(dx*dx + dy*dy) if dist > 0 then dx=dx/dist dy=dy/dist end vx= (vx+dx)*0.98 vy= (vy+dy)*0.98 if dist < 0.8 then vx= vx*0.1 vy= vy*0.1 local vdist= math.sqrt(vx*vx + vy*vy) if vdist < 1 then vx = 0 vy = 0 x=x2 y=y2 end end --[[if math.abs(dx) <= 1.0 then x=x2 end if math.abs(dy) <= 1.0 then y=y2 end ]]-- x = x + vx y = y + vy playerPosX[id] = x playerPosY[id] = y playerVelX[id] = vx playerVelY[id] = vy avatars[id]:SetPos(x,y) end end end end hook.Add("Think", "updateloop", thinking) --Will display how many votes there are for starting a vote and stuff. net.Receive("playerWantsToStartVote", function() local votename=net.ReadString() local playercount=net.ReadInt(16) local votecount=net.ReadInt(16) if votecount < playercount then chat.AddText( "", Color(100,244,0,255), votename, " wants to start a map vote! Type !letsvote if you also want to!\n", Color(200,255,0,255), "Votes: "..votecount.."/"..playercount ) else chat.AddText( Color(100,244,0,255), votename.." voted, and filled the voting quota!\nMap vote will begin at the end of this round." ) end surface.PlaySound("UI/buttonclick.wav") chat.PlaySound() end) --When a user has changed what map they want net.Receive("broadcastUserVoteChange", function() if listopened then local map=net.ReadInt(16) local user=net.ReadString() if currentvotes[user] != map then if currentvotes[user] != nil and currentvotes[user] != 0 then local position = 1 for k,v in pairs(playerlists[currentvotes[user]]) do if v == id then position = k end end table.remove(playerlists[currentvotes[user]],position) end table.insert(playerlists[map], user) --oldvotes[user]=currentvotes[user] currentvotes[user]=map end end end) --Closes the voting window function closeVotingWindow() if cl_mapvote != nil and listopened then listopened=false cl_mapvote:AlphaTo(0,0.5,0) timer.Simple(0.5,function() cl_mapv
Nobody?
Well you can make a table to control it. Something like this: [code] Map["Name.bsp"] = 0 Map["Name.bsp"] = 0 Map["AmapOnCooldown"] = 3 [/code] People are only able to vote for maps with 0. Each startup will decrease the number until it hits 0. Save the list to a txt file and don.
Could you tell me how I would put that in the code? I am lost. Also this means I would have to specify each map manually? Would this defeat the purpose of line 36? (I am fine with manual specification) How would I go about this?
there seriously has to be an easier way. I'm trying to figure out the same problem,but, no one seems to know how to fix it.
*snip*
that is very nice. I added you.
Sorry, you need to Log In to post a reply to this thread.