diff --git a/lua/autorun/mapvote.lua b/lua/autorun/mapvote.lua index 7e1baf4..6f58abd 100644 --- a/lua/autorun/mapvote.lua +++ b/lua/autorun/mapvote.lua @@ -14,24 +14,24 @@ MapVoteConfigDefault = { } --Default Config -hook.Add( "Initialize", "MapVoteConfigSetup", function() - if not file.Exists( "mapvote", "DATA") then - file.CreateDir( "mapvote" ) +hook.Add("Initialize", "MapVoteConfigSetup", function() + if not file.Exists("mapvote", "DATA") then + file.CreateDir("mapvote") end - if not file.Exists( "mapvote/config.txt", "DATA" ) then - file.Write( "mapvote/config.txt", util.TableToJSON( MapVoteConfigDefault ) ) + if not file.Exists("mapvote/config.txt", "DATA") then + file.Write("mapvote/config.txt", util.TableToJSON(MapVoteConfigDefault)) end -end ) +end) function MapVote.HasExtraVotePower(ply) - -- Example that gives admins more voting power - --[[ + -- Example that gives admins more voting power + --[[ if ply:IsAdmin() then - return true - end + return true + end ]] - return false + return false end @@ -51,4 +51,4 @@ if SERVER then include("mapvote/rtv.lua") else include("mapvote/cl_mapvote.lua") -end +end \ No newline at end of file diff --git a/lua/autorun/server/sv_autovote.lua b/lua/autorun/server/sv_autovote.lua index 443ebe6..7567dfe 100644 --- a/lua/autorun/server/sv_autovote.lua +++ b/lua/autorun/server/sv_autovote.lua @@ -1,41 +1,68 @@ -hook.Add( "Initialize", "AutoTTTMapVote", function() - if GAMEMODE_NAME == "terrortown" then +hook.Add("Initialize", "AutoTTTMapVote", function() + if GAMEMODE_NAME == "terrortown" then 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 switchmap = false - local nextmap = string.upper(game.GetMapNext()) - + -- 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 switchmap = false + local nextmap = string.upper(game.GetMapNext()) + if rounds_left <= 0 then - LANG.Msg("limit_round", {mapname = nextmap}) - switchmap = true + LANG.Msg("limit_round", {mapname = nextmap}) + switchmap = true elseif time_left <= 0 then - LANG.Msg("limit_time", {mapname = nextmap}) - switchmap = true + LANG.Msg("limit_time", {mapname = nextmap}) + switchmap = true end if switchmap then timer.Stop("end2prep") MapVote.Start(nil, nil, nil, nil) end end - end - - if GAMEMODE_NAME == "deathrun" then - function RTV.Start() - MapVote.Start(nil, nil, nil, nil) - end - end - - if GAMEMODE_NAME == "zombiesurvival" then - hook.Add("LoadNextMap", "MAPVOTEZS_LOADMAP", function() - MapVote.Start(nil, nil, nil, nil) - return true - end ) - end + end + + if GAMEMODE_NAME == "prop_hunt" then + function CheckForMapSwitch() + -- Check for mapswitch + local rounds_left = math.max(0, GetGlobalInt("ph_rounds_left", 6) - 1) + SetGlobalInt("ph_rounds_left", rounds_left) + + local time_left = math.max(0, (GetConVar("ph_time_limit_minutes"):GetInt() * 60) - CurTime()) + local switchmap = false + local nextmap = string.upper(game.GetMapNext()) + + if rounds_left <= 0 then + LANG.Msg("limit_round", {mapname = nextmap}) + switchmap = true + elseif time_left <= 0 then + LANG.Msg("limit_time", {mapname = nextmap}) + switchmap = true + end + if switchmap then + timer.Stop("end2prep") + MapVote.Start(nil, nil, nil, nil) + end + end + end -end ) + if GAMEMODE_NAME == "murder" then + function GAMEMODE:ChangeMap() + MapVote.Start(nil, nil, nil, nil) + end + end + if GAMEMODE_NAME == "deathrun" then + function RTV.Start() + MapVote.Start(nil, nil, nil, nil) + end + end + if GAMEMODE_NAME == "zombiesurvival" then + hook.Add("LoadNextMap", "MAPVOTEZS_LOADMAP", function() + MapVote.Start(nil, nil, nil, nil) + return true + end) + end +end) \ No newline at end of file diff --git a/lua/mapvote/cl_mapvote.lua b/lua/mapvote/cl_mapvote.lua index 357749f..16036b2 100644 --- a/lua/mapvote/cl_mapvote.lua +++ b/lua/mapvote/cl_mapvote.lua @@ -14,7 +14,7 @@ surface.CreateFont("RAM_VoteFontCountdown", { shadow = true }) -surface.CreateFont("RAM_VoteSysButton", +surface.CreateFont("RAM_VoteSysButton", { font = "Marlett", size = 13, weight = 0, @@ -28,41 +28,41 @@ net.Receive("RAM_MapVoteStart", function() MapVote.CurrentMaps = {} MapVote.Allow = true MapVote.Votes = {} - + local amt = net.ReadUInt(32) - + for i = 1, amt do local map = net.ReadString() - + MapVote.CurrentMaps[#MapVote.CurrentMaps + 1] = map end - + MapVote.EndTime = CurTime() + net.ReadUInt(32) - - if(IsValid(MapVote.Panel)) then + + if (IsValid(MapVote.Panel)) then MapVote.Panel:Remove() end - + MapVote.Panel = vgui.Create("RAM_VoteScreen") MapVote.Panel:SetMaps(MapVote.CurrentMaps) end) net.Receive("RAM_MapVoteUpdate", function() local update_type = net.ReadUInt(3) - - if(update_type == MapVote.UPDATE_VOTE) then + + if (update_type == MapVote.UPDATE_VOTE) then local ply = net.ReadEntity() - - if(IsValid(ply)) then + + if (IsValid(ply)) then local map_id = net.ReadUInt(32) MapVote.Votes[ply:SteamID()] = map_id - - if(IsValid(MapVote.Panel)) then + + if (IsValid(MapVote.Panel)) then MapVote.Panel:AddVoter(ply) end end - elseif(update_type == MapVote.UPDATE_WIN) then - if(IsValid(MapVote.Panel)) then + elseif (update_type == MapVote.UPDATE_WIN) then + if (IsValid(MapVote.Panel)) then MapVote.Panel:Flash(net.ReadUInt(32)) end end @@ -75,31 +75,31 @@ net.Receive("RAM_MapVoteCancel", function() end) net.Receive("RTV_Delay", function() - chat.AddText(Color( 102,255,51 ), "[RTV]", Color( 255,255,255 ), " The vote has been rocked, map vote will begin on round end") + chat.AddText(Color(102,255,51), "[RTV]", Color(255,255,255), " The vote has been rocked, map vote will begin on round end") end) local PANEL = {} function PANEL:Init() self:ParentToHUD() - + self.Canvas = vgui.Create("Panel", self) self.Canvas:MakePopup() self.Canvas:SetKeyboardInputEnabled(false) - + self.countDown = vgui.Create("DLabel", self.Canvas) self.countDown:SetTextColor(color_white) self.countDown:SetFont("RAM_VoteFontCountdown") self.countDown:SetText("") self.countDown:SetPos(0, 14) - + self.mapList = vgui.Create("DPanelList", self.Canvas) - self.mapList:SetDrawBackground(false) + self.mapList:SetPaintBackground(false) self.mapList:SetSpacing(4) self.mapList:SetPadding(4) self.mapList:EnableHorizontal(true) self.mapList:EnableVerticalScrollbar() - + self.closeButton = vgui.Create("DButton", self.Canvas) self.closeButton:SetText("") @@ -133,10 +133,10 @@ end function PANEL:PerformLayout() local cx, cy = chat.GetChatBoxPos() - + self:SetPos(0, 0) self:SetSize(ScrW(), ScrH()) - + local extra = math.Clamp(300, 0, ScrW() - 640) self.Canvas:StretchToParent(0, 0, 0, 0) self.Canvas:SetWide(640 + extra) @@ -144,7 +144,7 @@ function PANEL:PerformLayout() self.Canvas:SetPos(0, 0) self.Canvas:CenterHorizontal() self.Canvas:SetZPos(0) - + self.mapList:StretchToParent(0, 90, 0, 0) local buttonPos = 640 + extra - 31 * 3 @@ -160,21 +160,17 @@ function PANEL:PerformLayout() self.minimButton:SetPos(buttonPos - 31 * 2, 4) self.minimButton:SetSize(31, 31) self.minimButton:SetVisible(true) - end -local heart_mat = Material("icon16/heart.png") local star_mat = Material("icon16/star.png") -local shield_mat = Material("icon16/shield.png") function PANEL:AddVoter(voter) for k, v in pairs(self.Voters) do - if(v.Player and v.Player == voter) then + if (v.Player and v.Player == voter) then return false end end - - + local icon_container = vgui.Create("Panel", self.mapList:GetCanvas()) local icon = vgui.Create("AvatarImage", icon_container) icon:SetSize(16, 16) @@ -192,17 +188,17 @@ function PANEL:AddVoter(voter) icon_container:SetSize(20, 20) icon:SetPos(2, 2) end - + icon_container.Paint = function(s, w, h) draw.RoundedBox(4, 0, 0, w, h, Color(255, 0, 0, 80)) - - if(icon_container.img) then + + if (icon_container.img) then surface.SetMaterial(icon_container.img) surface.SetDrawColor(Color(255, 255, 255)) surface.DrawTexturedRect(2, 2, 16, 16) end end - + table.insert(self.Voters, icon_container) end @@ -210,102 +206,95 @@ function PANEL:Think() for k, v in pairs(self.mapList:GetItems()) do v.NumVotes = 0 end - + for k, v in pairs(self.Voters) do - if(not IsValid(v.Player)) then + if (not IsValid(v.Player)) then v:Remove() else - if(not MapVote.Votes[v.Player:SteamID()]) then + if (not MapVote.Votes[v.Player:SteamID()]) then v:Remove() else local bar = self:GetMapButton(MapVote.Votes[v.Player:SteamID()]) - - if(MapVote.HasExtraVotePower(v.Player)) then + + if (MapVote.HasExtraVotePower(v.Player)) then bar.NumVotes = bar.NumVotes + 2 else bar.NumVotes = bar.NumVotes + 1 end - - if(IsValid(bar)) then - local CurrentPos = Vector(v.x, v.y, 0) + + if (IsValid(bar)) then local NewPos = Vector((bar.x + bar:GetWide()) - 21 * bar.NumVotes - 2, bar.y + (bar:GetTall() * 0.5 - 10), 0) - - if(not v.CurPos or v.CurPos ~= NewPos) then + + if (not v.CurPos or v.CurPos ~= NewPos) then v:MoveTo(NewPos.x, NewPos.y, 0.3) v.CurPos = NewPos end end end end - end - + local timeLeft = math.Round(math.Clamp(MapVote.EndTime - CurTime(), 0, math.huge)) - - self.countDown:SetText(tostring(timeLeft or 0).." seconds") + + self.countDown:SetText(tostring(timeLeft or 0) .. " seconds") self.countDown:SizeToContents() self.countDown:CenterHorizontal() end function PANEL:SetMaps(maps) self.mapList:Clear() - + for k, v in RandomPairs(maps) do local button = vgui.Create("DButton", self.mapList) button.ID = k button:SetText(v) - + button.DoClick = function() net.Start("RAM_MapVoteUpdate") net.WriteUInt(MapVote.UPDATE_VOTE, 3) net.WriteUInt(button.ID, 32) net.SendToServer() end - + do local Paint = button.Paint button.Paint = function(s, w, h) local col = Color(255, 255, 255, 10) - - if(button.bgColor) then + + if (button.bgColor) then col = button.bgColor end - + draw.RoundedBox(4, 0, 0, w, h, col) Paint(s, w, h) end end - + button:SetTextColor(color_white) button:SetContentAlignment(4) button:SetTextInset(8, 0) button:SetFont("RAM_VoteFont") - + local extra = math.Clamp(300, 0, ScrW() - 640) - - button:SetDrawBackground(false) + + button:SetPaintBackground(false) button:SetTall(24) button:SetWide(285 + (extra / 2)) button.NumVotes = 0 - + self.mapList:AddItem(button) end end function PANEL:GetMapButton(id) for k, v in pairs(self.mapList:GetItems()) do - if(v.ID == id) then return v end + if (v.ID == id) then return v end end - + return false end function PANEL:Paint() - --Derma_DrawBackgroundBlur(self) - - local CenterY = ScrH() / 2 - local CenterX = ScrW() / 2 - surface.SetDrawColor(0, 0, 0, 200) surface.DrawRect(0, 0, ScrW(), ScrH()) end @@ -314,15 +303,15 @@ function PANEL:Flash(id) self:SetVisible(true) local bar = self:GetMapButton(id) - - if(IsValid(bar)) then - timer.Simple( 0.0, function() bar.bgColor = Color( 0, 255, 255 ) surface.PlaySound( "hl1/fvox/blip.wav" ) end ) - timer.Simple( 0.2, function() bar.bgColor = nil end ) - timer.Simple( 0.4, function() bar.bgColor = Color( 0, 255, 255 ) surface.PlaySound( "hl1/fvox/blip.wav" ) end ) - timer.Simple( 0.6, function() bar.bgColor = nil end ) - timer.Simple( 0.8, function() bar.bgColor = Color( 0, 255, 255 ) surface.PlaySound( "hl1/fvox/blip.wav" ) end ) - timer.Simple( 1.0, function() bar.bgColor = Color( 100, 100, 100 ) end ) + + if (IsValid(bar)) then + timer.Simple(0.0, function() bar.bgColor = Color(0, 255, 255) surface.PlaySound("hl1/fvox/blip.wav") end) + timer.Simple(0.2, function() bar.bgColor = nil end) + timer.Simple(0.4, function() bar.bgColor = Color(0, 255, 255) surface.PlaySound("hl1/fvox/blip.wav") end) + timer.Simple(0.6, function() bar.bgColor = nil end) + timer.Simple(0.8, function() bar.bgColor = Color(0, 255, 255) surface.PlaySound("hl1/fvox/blip.wav") end) + timer.Simple(1.0, function() bar.bgColor = Color(100, 100, 100) end) end end -derma.DefineControl("RAM_VoteScreen", "", PANEL, "DPanel") +derma.DefineControl("RAM_VoteScreen", "", PANEL, "DPanel") \ No newline at end of file diff --git a/lua/mapvote/rtv.lua b/lua/mapvote/rtv.lua index c3dfe3c..0a7acca 100644 --- a/lua/mapvote/rtv.lua +++ b/lua/mapvote/rtv.lua @@ -1,11 +1,9 @@ RTV = RTV or {} RTV.ChatCommands = { - - "!rtv", - "/rtv", - "rtv" - + "!rtv", + "/rtv", + "rtv" } RTV.TotalVotes = 0 @@ -17,114 +15,109 @@ RTV._ActualWait = CurTime() + RTV.Wait RTV.PlayerCount = MapVote.Config.RTVPlayerCount or 3 function RTV.ShouldChange() - return RTV.TotalVotes >= math.Round(#player.GetAll()*0.66) + return RTV.TotalVotes >= math.Round(#player.GetAll() * 0.66) end function RTV.RemoveVote() - RTV.TotalVotes = math.Clamp( RTV.TotalVotes - 1, 0, math.huge ) + RTV.TotalVotes = math.Clamp(RTV.TotalVotes - 1, 0, math.huge) end function RTV.Start() - if GAMEMODE_NAME == "terrortown" then - net.Start("RTV_Delay") - net.Broadcast() - - hook.Add("TTTEndRound", "MapvoteDelayed", function() - MapVote.Start(nil, nil, nil, nil) - end) - elseif GAMEMODE_NAME == "deathrun" then - net.Start("RTV_Delay") - net.Broadcast() - - hook.Add("RoundEnd", "MapvoteDelayed", function() - MapVote.Start(nil, nil, nil, nil) - end) - else - PrintMessage( HUD_PRINTTALK, "The vote has been rocked, map vote imminent") - timer.Simple(4, function() - MapVote.Start(nil, nil, nil, nil) - end) - end + if GAMEMODE_NAME == "terrortown" then + net.Start("RTV_Delay") + net.Broadcast() + + hook.Add("TTTEndRound", "MapvoteDelayed", function() + MapVote.Start(nil, nil, nil, nil) + end) + elseif GAMEMODE_NAME == "prop_hunt" then + net.Start("RTV_Delay") + net.Broadcast() + + hook.Add("PHEndRound", "MapvoteDelayed", function() + MapVote.Start(nil, nil, nil, nil) + end) + elseif GAMEMODE_NAME == "deathrun" then + net.Start("RTV_Delay") + net.Broadcast() + + hook.Add("RoundEnd", "MapvoteDelayed", function() + MapVote.Start(nil, nil, nil, nil) + end) + else + PrintMessage(HUD_PRINTTALK, "The vote has been rocked, map vote imminent") + timer.Simple(4, function() + MapVote.Start(nil, nil, nil, nil) + end) + end end -function RTV.AddVote( ply ) - - if RTV.CanVote( ply ) then - RTV.TotalVotes = RTV.TotalVotes + 1 - ply.RTVoted = true - MsgN( ply:Nick().." has voted to Rock the Vote." ) - PrintMessage( HUD_PRINTTALK, ply:Nick().." has voted to Rock the Vote. ("..RTV.TotalVotes.."/"..math.Round(#player.GetAll()*0.66)..")" ) - - if RTV.ShouldChange() then - RTV.Start() - end - end +function RTV.AddVote(ply) + if RTV.CanVote(ply) then + RTV.TotalVotes = RTV.TotalVotes + 1 + ply.RTVoted = true + MsgN(ply:Nick() .. " has voted to Rock the Vote.") + PrintMessage(HUD_PRINTTALK, ply:Nick() .. " has voted to Rock the Vote. (" .. RTV.TotalVotes .. "/" .. math.Round(#player.GetAll() * 0.66) .. ")") + if RTV.ShouldChange() then + RTV.Start() + end + end end -hook.Add( "PlayerDisconnected", "Remove RTV", function( ply ) - - if ply.RTVoted then - RTV.RemoveVote() - end - - timer.Simple( 0.1, function() - - if RTV.ShouldChange() then - RTV.Start() - end +hook.Add("PlayerDisconnected", "Remove RTV", function(ply) + if ply.RTVoted then + RTV.RemoveVote() + end - end ) + timer.Simple(0.1, function() + if RTV.ShouldChange() then + RTV.Start() + end + end) +end) -end ) +function RTV.CanVote(ply) + local plyCount = table.Count(player.GetAll()) -function RTV.CanVote( ply ) - local plyCount = table.Count(player.GetAll()) - - if RTV._ActualWait >= CurTime() then - return false, "You must wait a bit before voting!" - end + if RTV._ActualWait >= CurTime() then + return false, "You must wait a bit before voting!" + end - if GetGlobalBool( "In_Voting" ) then - return false, "There is currently a vote in progress!" - end + if GetGlobalBool("In_Voting") then + return false, "There is currently a vote in progress!" + end - if ply.RTVoted then - return false, "You have already voted to Rock the Vote!" - end + if ply.RTVoted then + return false, "You have already voted to Rock the Vote!" + end - if RTV.ChangingMaps then - return false, "There has already been a vote, the map is going to change!" - end - if plyCount < RTV.PlayerCount then + if RTV.ChangingMaps then + return false, "There has already been a vote, the map is going to change!" + end + if plyCount < RTV.PlayerCount then return false, "You need more players before you can rock the vote!" end - return true - + return true end -function RTV.StartVote( ply ) - - local can, err = RTV.CanVote(ply) - - if not can then - ply:PrintMessage( HUD_PRINTTALK, err ) - return - end +function RTV.StartVote(ply) + local can, err = RTV.CanVote(ply) - RTV.AddVote( ply ) + if not can then + ply:PrintMessage(HUD_PRINTTALK, err) + return + end + RTV.AddVote(ply) end +concommand.Add("rtv_start", RTV.StartVote) -concommand.Add( "rtv_start", RTV.StartVote ) - -hook.Add( "PlayerSay", "RTV Chat Commands", function( ply, text ) - - if table.HasValue( RTV.ChatCommands, string.lower(text) ) then - RTV.StartVote( ply ) - return "" - end - -end ) \ No newline at end of file +hook.Add("PlayerSay", "RTV Chat Commands", function(ply, text) + if table.HasValue(RTV.ChatCommands, string.lower(text)) then + RTV.StartVote(ply) + return "" + end +end) \ No newline at end of file diff --git a/lua/mapvote/sv_mapvote.lua b/lua/mapvote/sv_mapvote.lua index f5e17ce..05f0565 100644 --- a/lua/mapvote/sv_mapvote.lua +++ b/lua/mapvote/sv_mapvote.lua @@ -6,34 +6,34 @@ util.AddNetworkString("RTV_Delay") MapVote.Continued = false net.Receive("RAM_MapVoteUpdate", function(len, ply) - if(MapVote.Allow) then - if(IsValid(ply)) then - local update_type = net.ReadUInt(3) - - if(update_type == MapVote.UPDATE_VOTE) then - local map_id = net.ReadUInt(32) - - if(MapVote.CurrentMaps[map_id]) then - MapVote.Votes[ply:SteamID()] = map_id - - net.Start("RAM_MapVoteUpdate") - net.WriteUInt(MapVote.UPDATE_VOTE, 3) - net.WriteEntity(ply) - net.WriteUInt(map_id, 32) - net.Broadcast() - end + if (MapVote.Allow and IsValid(ply)) then + local update_type = net.ReadUInt(3) + + if (update_type == MapVote.UPDATE_VOTE) then + local map_id = net.ReadUInt(32) + + if (MapVote.CurrentMaps[map_id]) then + MapVote.Votes[ply:SteamID()] = map_id + + net.Start("RAM_MapVoteUpdate") + net.WriteUInt(MapVote.UPDATE_VOTE, 3) + net.WriteEntity(ply) + net.WriteUInt(map_id, 32) + net.Broadcast() end end end end) -if file.Exists( "mapvote/recentmaps.txt", "DATA" ) then +if file.Exists("mapvote/recentmaps.txt", "DATA") then recentmaps = util.JSONToTable(file.Read("mapvote/recentmaps.txt", "DATA")) else recentmaps = {} end -if file.Exists( "mapvote/config.txt", "DATA" ) then +if file.Exists("mapvote/config_" .. engine.ActiveGamemode() .. ".txt", "DATA") then + MapVote.Config = util.JSONToTable(file.Read("mapvote/config_" .. engine.ActiveGamemode() .. ".txt", "DATA")) +elseif file.Exists("mapvote/config.txt", "DATA") then MapVote.Config = util.JSONToTable(file.Read("mapvote/config.txt", "DATA")) else MapVote.Config = {} @@ -42,11 +42,11 @@ end function CoolDownDoStuff() cooldownnum = MapVote.Config.MapsBeforeRevote or 3 - if table.getn(recentmaps) == cooldownnum then + if #recentmaps == cooldownnum then table.remove(recentmaps) end - local curmap = game.GetMap():lower()..".bsp" + local curmap = game.GetMap():lower() .. ".bsp" if not table.HasValue(recentmaps, curmap) then table.insert(recentmaps, 1, curmap) @@ -66,9 +66,9 @@ function MapVote.Start(length, current, limit, prefix, callback) local is_expression = false if not prefix then - local info = file.Read(GAMEMODE.Folder.."/"..GAMEMODE.FolderName..".txt", "GAME") + local info = file.Read(GAMEMODE.Folder .. "/" .. GAMEMODE.FolderName .. ".txt", "GAME") - if(info) then + if (info) then local info = util.KeyValuesToTable(info) prefix = info.maps else @@ -81,81 +81,78 @@ function MapVote.Start(length, current, limit, prefix, callback) prefix = {prefix} end end - + local maps = file.Find("maps/*.bsp", "GAME") - + local vote_maps = {} - + local amt = 0 for k, map in RandomPairs(maps) do - local mapstr = map:sub(1, -5):lower() - if(not current and game.GetMap():lower()..".bsp" == map) then continue end - if(cooldown and table.HasValue(recentmaps, map)) then continue end + if (not current and game.GetMap():lower() .. ".bsp" == map) then continue end + if (cooldown and table.HasValue(recentmaps, map)) then continue end if is_expression then - if(string.find(map, prefix)) then -- This might work (from gamemode.txt) + if (string.find(map, prefix)) then -- This might work (from gamemode.txt) vote_maps[#vote_maps + 1] = map:sub(1, -5) amt = amt + 1 end else for k, v in pairs(prefix) do - if string.find(map, "^"..v) then + if string.find(map, "^" .. v) then vote_maps[#vote_maps + 1] = map:sub(1, -5) amt = amt + 1 break end end end - - if(limit and amt >= limit) then break end + + if (limit and amt >= limit) then break end end - + net.Start("RAM_MapVoteStart") net.WriteUInt(#vote_maps, 32) - + for i = 1, #vote_maps do net.WriteString(vote_maps[i]) end - + net.WriteUInt(length, 32) net.Broadcast() - + MapVote.Allow = true MapVote.CurrentMaps = vote_maps MapVote.Votes = {} - + timer.Create("RAM_MapVote", length, 1, function() MapVote.Allow = false local map_results = {} - + for k, v in pairs(MapVote.Votes) do - if(not map_results[v]) then + if (not map_results[v]) then map_results[v] = 0 end - + for k2, v2 in pairs(player.GetAll()) do - if(v2:SteamID() == k) then - if(MapVote.HasExtraVotePower(v2)) then + if (v2:SteamID() == k) then + if (MapVote.HasExtraVotePower(v2)) then map_results[v] = map_results[v] + 2 else map_results[v] = map_results[v] + 1 end end end - end - + CoolDownDoStuff() local winner = table.GetWinningKey(map_results) or 1 - + net.Start("RAM_MapVoteUpdate") net.WriteUInt(MapVote.UPDATE_WIN, 3) - net.WriteUInt(winner, 32) net.Broadcast() - + local map = MapVote.CurrentMaps[winner] local gamemode = nil @@ -177,7 +174,7 @@ function MapVote.Start(length, current, limit, prefix, callback) else print("not enabled") end - + timer.Simple(4, function() if (hook.Run("MapVoteChange", map) ~= false) then if (callback) then @@ -194,11 +191,11 @@ function MapVote.Start(length, current, limit, prefix, callback) end) end -hook.Add( "Shutdown", "RemoveRecentMaps", function() - if file.Exists( "mapvote/recentmaps.txt", "DATA" ) then - file.Delete( "mapvote/recentmaps.txt" ) - end -end ) +hook.Add("Shutdown", "RemoveRecentMaps", function() + if file.Exists("mapvote/recentmaps.txt", "DATA") then + file.Delete("mapvote/recentmaps.txt") + end +end) function MapVote.Cancel() if MapVote.Allow then @@ -207,6 +204,6 @@ function MapVote.Cancel() net.Start("RAM_MapVoteCancel") net.Broadcast() - timer.Destroy("RAM_MapVote") + timer.Remove("RAM_MapVote") end -end +end \ No newline at end of file diff --git a/lua/ulx/modules/sh/mapvote.lua b/lua/ulx/modules/sh/mapvote.lua index aa33d62..4c08c00 100644 --- a/lua/ulx/modules/sh/mapvote.lua +++ b/lua/ulx/modules/sh/mapvote.lua @@ -1,18 +1,18 @@ local CATEGORY_NAME = "MapVote" ------------------------------ VoteMap ------------------------------ -function AMB_mapvote( calling_ply, votetime, should_cancel ) - if not should_cancel then - MapVote.Start(votetime, nil, nil, nil) - ulx.fancyLogAdmin( calling_ply, "#A called a votemap!" ) - else - MapVote.Cancel() - ulx.fancyLogAdmin( calling_ply, "#A canceled the votemap" ) - end +function AMB_mapvote(calling_ply, votetime, should_cancel) + if not should_cancel then + MapVote.Start(votetime, nil, nil, nil) + ulx.fancyLogAdmin(calling_ply, "#A called a votemap!") + else + MapVote.Cancel() + ulx.fancyLogAdmin(calling_ply, "#A canceled the votemap") + end end -local mapvotecmd = ulx.command( CATEGORY_NAME, "mapvote", AMB_mapvote, "!mapvote" ) -mapvotecmd:addParam{ type=ULib.cmds.NumArg, min=15, default=25, hint="time", ULib.cmds.optional, ULib.cmds.round } -mapvotecmd:addParam{ type=ULib.cmds.BoolArg, invisible=true } -mapvotecmd:defaultAccess( ULib.ACCESS_ADMIN ) -mapvotecmd:help( "Invokes the map vote logic" ) -mapvotecmd:setOpposite( "unmapvote", {_, _, true}, "!unmapvote" ) \ No newline at end of file +local mapvotecmd = ulx.command(CATEGORY_NAME, "mapvote", AMB_mapvote, "!mapvote") +mapvotecmd:addParam{type = ULib.cmds.NumArg, min = 15, default = 25, hint = "time", ULib.cmds.optional, ULib.cmds.round} +mapvotecmd:addParam{type = ULib.cmds.BoolArg, invisible = true } +mapvotecmd:defaultAccess(ULib.ACCESS_ADMIN) +mapvotecmd:help("Invokes the map vote logic") +mapvotecmd:setOpposite("unmapvote", {_, _, true}, "!unmapvote") \ No newline at end of file