Initial Reupload
This commit is contained in:
329
gamemodes/prop_hunt/gamemode/mapvote/cl_mapvote.lua
Normal file
329
gamemodes/prop_hunt/gamemode/mapvote/cl_mapvote.lua
Normal file
@@ -0,0 +1,329 @@
|
||||
surface.CreateFont("RAM_VoteFont", {
|
||||
font = "Trebuchet MS",
|
||||
size = 19,
|
||||
weight = 700,
|
||||
antialias = true,
|
||||
shadow = true
|
||||
})
|
||||
|
||||
surface.CreateFont("RAM_VoteFontCountdown", {
|
||||
font = "Tahoma",
|
||||
size = 32,
|
||||
weight = 700,
|
||||
antialias = true,
|
||||
shadow = true
|
||||
})
|
||||
|
||||
surface.CreateFont("RAM_VoteSysButton",
|
||||
{ font = "Marlett",
|
||||
size = 13,
|
||||
weight = 0,
|
||||
symbol = true,
|
||||
})
|
||||
|
||||
MapVote.EndTime = 0
|
||||
MapVote.Panel = false
|
||||
|
||||
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
|
||||
MapVote.Panel:Remove()
|
||||
end
|
||||
|
||||
MapVote.Panel = vgui.Create("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
|
||||
local ply = net.ReadEntity()
|
||||
|
||||
if(IsValid(ply)) then
|
||||
local map_id = net.ReadUInt(32)
|
||||
MapVote.Votes[ply:SteamID()] = map_id
|
||||
|
||||
if(IsValid(MapVote.Panel)) then
|
||||
MapVote.Panel:AddVoter(ply)
|
||||
end
|
||||
end
|
||||
elseif(update_type == MapVote.UPDATE_WIN) then
|
||||
if(IsValid(MapVote.Panel)) then
|
||||
MapVote.Panel:Flash(net.ReadUInt(32))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
net.Receive("RAM_MapVoteCancel", function()
|
||||
if IsValid(MapVote.Panel) then
|
||||
MapVote.Panel:Remove()
|
||||
end
|
||||
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")
|
||||
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:SetSpacing(4)
|
||||
self.mapList:SetPadding(4)
|
||||
self.mapList:EnableHorizontal(true)
|
||||
self.mapList:EnableVerticalScrollbar()
|
||||
|
||||
self.closeButton = vgui.Create("DButton", self.Canvas)
|
||||
self.closeButton:SetText("")
|
||||
|
||||
self.closeButton.Paint = function(panel, w, h)
|
||||
derma.SkinHook("Paint", "WindowCloseButton", panel, w, h)
|
||||
end
|
||||
|
||||
self.closeButton.DoClick = function()
|
||||
print("MapVote has started...")
|
||||
self:SetVisible(false)
|
||||
end
|
||||
|
||||
self.maximButton = vgui.Create("DButton", self.Canvas)
|
||||
self.maximButton:SetText("")
|
||||
self.maximButton:SetDisabled(true)
|
||||
|
||||
self.maximButton.Paint = function(panel, w, h)
|
||||
derma.SkinHook("Paint", "WindowMaximizeButton", panel, w, h)
|
||||
end
|
||||
|
||||
self.minimButton = vgui.Create("DButton", self.Canvas)
|
||||
self.minimButton:SetText("")
|
||||
self.minimButton:SetDisabled(true)
|
||||
|
||||
self.minimButton.Paint = function(panel, w, h)
|
||||
derma.SkinHook("Paint", "WindowMinimizeButton", panel, w, h)
|
||||
end
|
||||
|
||||
self.Voters = {}
|
||||
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)
|
||||
// self.Canvas:SetTall(cy -60)
|
||||
self.Canvas:SetTall(640)
|
||||
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
|
||||
|
||||
self.closeButton:SetPos(buttonPos - 31 * 0, 4)
|
||||
self.closeButton:SetSize(31, 31)
|
||||
self.closeButton:SetVisible(true)
|
||||
|
||||
self.maximButton:SetPos(buttonPos - 31 * 1, 4)
|
||||
self.maximButton:SetSize(31, 31)
|
||||
self.maximButton:SetVisible(true)
|
||||
|
||||
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
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local icon_container = vgui.Create("Panel", self.mapList:GetCanvas())
|
||||
local icon = vgui.Create("AvatarImage", icon_container)
|
||||
icon:SetSize(16, 16)
|
||||
icon:SetZPos(1000)
|
||||
icon:SetTooltip(voter:Name())
|
||||
icon_container.Player = voter
|
||||
icon_container:SetTooltip(voter:Name())
|
||||
icon:SetPlayer(voter, 16)
|
||||
|
||||
if MapVote.HasExtraVotePower(voter) then
|
||||
icon_container:SetSize(40, 20)
|
||||
icon:SetPos(21, 2)
|
||||
icon_container.img = star_mat
|
||||
else
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
v:Remove()
|
||||
else
|
||||
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
|
||||
bar.NumVotes = bar.NumVotes + 2
|
||||
else
|
||||
bar.NumVotes = bar.NumVotes + 1
|
||||
end
|
||||
|
||||
if(IsValid(bar)) then
|
||||
local CurrentPos = Vector(v.x, v.y, 0)
|
||||
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
|
||||
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: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
|
||||
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: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
|
||||
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
|
||||
|
||||
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 )
|
||||
end
|
||||
end
|
||||
|
||||
derma.DefineControl("VoteScreen", "", PANEL, "DPanel")
|
||||
114
gamemodes/prop_hunt/gamemode/mapvote/rtv.lua
Normal file
114
gamemodes/prop_hunt/gamemode/mapvote/rtv.lua
Normal file
@@ -0,0 +1,114 @@
|
||||
RTV = RTV or {}
|
||||
|
||||
RTV.ChatCommands = {
|
||||
"!rtv",
|
||||
"/rtv",
|
||||
"rtv"
|
||||
}
|
||||
|
||||
RTV.TotalVotes = 0
|
||||
|
||||
RTV.Wait = 60 -- The wait time in seconds. This is how long a player has to wait before voting when the map changes.
|
||||
|
||||
RTV._ActualWait = CurTime() + RTV.Wait
|
||||
|
||||
RTV.PlayerCount = MapVote.Config.RTVPlayerCount or 3
|
||||
|
||||
function RTV.ShouldChange()
|
||||
return RTV.TotalVotes >= math.Round(#player.GetAll()*0.66)
|
||||
end
|
||||
|
||||
function RTV.RemoveVote()
|
||||
RTV.TotalVotes = math.Clamp( RTV.TotalVotes - 1, 0, math.huge )
|
||||
end
|
||||
|
||||
function RTV.Start()
|
||||
PrintMessage( HUD_PRINTTALK, "The vote has been rocked, map vote imminent")
|
||||
timer.Simple(4, function()
|
||||
MapVote.Start(nil, nil, nil, nil)
|
||||
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 (#player.GetAll() < 1 && !GetConVar("mv_change_when_no_player"):GetBool()) then
|
||||
print("MapVote: There is no player to force change map...")
|
||||
else
|
||||
if RTV.ShouldChange() then
|
||||
RTV.Start()
|
||||
end
|
||||
end
|
||||
end )
|
||||
|
||||
end )
|
||||
|
||||
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 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 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
|
||||
|
||||
end
|
||||
|
||||
function RTV.StartVote( ply )
|
||||
|
||||
local can, err = RTV.CanVote(ply)
|
||||
|
||||
if not can then
|
||||
ply:PrintMessage( HUD_PRINTTALK, err )
|
||||
return
|
||||
end
|
||||
|
||||
RTV.AddVote( ply )
|
||||
|
||||
end
|
||||
|
||||
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 )
|
||||
257
gamemodes/prop_hunt/gamemode/mapvote/sv_mapvote.lua
Normal file
257
gamemodes/prop_hunt/gamemode/mapvote/sv_mapvote.lua
Normal file
@@ -0,0 +1,257 @@
|
||||
util.AddNetworkString("RAM_MapVoteStart")
|
||||
util.AddNetworkString("RAM_MapVoteUpdate")
|
||||
util.AddNetworkString("RAM_MapVoteCancel")
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
if file.Exists( "mapvote/recentmaps.txt", "DATA" ) then
|
||||
recentmaps = util.JSONToTable(file.Read("mapvote/recentmaps.txt", "DATA"))
|
||||
else
|
||||
recentmaps = {}
|
||||
end
|
||||
|
||||
if ConVarExists("mv_maplimit") then
|
||||
printVerbose("[MapVote] Loading ConVars...")
|
||||
MapVote.Config = {
|
||||
MapLimit = GetConVar("mv_maplimit"):GetInt(),
|
||||
TimeLimit = GetConVar("mv_timelimit"):GetInt(),
|
||||
AllowCurrentMap = GetConVar("mv_allowcurmap"):GetBool(),
|
||||
EnableCooldown = GetConVar("mv_cooldown"):GetBool(),
|
||||
MapsBeforeRevote = GetConVar("mv_mapbeforerevote"):GetBool(),
|
||||
RTVPlayerCount = GetConVar("mv_rtvcount"):GetInt(),
|
||||
MapPrefixes = string.Explode(",", GetConVar("mv_mapprefix"):GetString():lower())
|
||||
}
|
||||
else
|
||||
MapVote.Config = {}
|
||||
end
|
||||
|
||||
local conv = {
|
||||
["mv_maplimit"] = function(cvar,old,new)
|
||||
if new && (new != nil || new != "") then
|
||||
MapVote.Config.MapLimit = tonumber(new)
|
||||
end
|
||||
end,
|
||||
["mv_timelimit"] = function(cvar,old,new)
|
||||
if new && (new != nil || new != "") then
|
||||
MapVote.Config.TimeLimit = tonumber(new)
|
||||
end
|
||||
end,
|
||||
["mv_allowcurmap"] = function(cvar,old,new)
|
||||
if new && (new != nil || new != "") then
|
||||
MapVote.Config.AllowCurrentMap = tobool(new)
|
||||
end
|
||||
end,
|
||||
["mv_cooldown"] = function(cvar,old,new)
|
||||
if new && (new != nil || new != "") then
|
||||
MapVote.Config.EnableCooldown = tobool(new)
|
||||
end
|
||||
end,
|
||||
["mv_mapbeforerevote"] = function(cvar,old,new)
|
||||
if new && (new != nil || new != "") then
|
||||
MapVote.Config.MapsBeforeRevote = tobool(new)
|
||||
end
|
||||
end,
|
||||
["mv_rtvcount"] = function(cvar,old,new)
|
||||
if new && (new != nil || new != "") then
|
||||
MapVote.Config.RTVPlayerCount = tonumber(new)
|
||||
end
|
||||
end,
|
||||
["mv_mapprefix"] = function(cvar,old,new)
|
||||
if new && (new != nil || new != "") then
|
||||
MapVote.Config.MapPrefixes = string.Explode(",", new:lower())
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
-- Precheck when the convar is changed
|
||||
for cvar,func in pairs(conv) do
|
||||
printVerbose("[MapVote] Adding ConVar Callbacks for: "..cvar)
|
||||
cvars.AddChangeCallback(cvar, func)
|
||||
end
|
||||
|
||||
function CoolDownDoStuff()
|
||||
cooldownnum = MapVote.Config.MapsBeforeRevote or 3
|
||||
|
||||
if table.getn(recentmaps) == cooldownnum then
|
||||
table.remove(recentmaps)
|
||||
end
|
||||
|
||||
local curmap = game.GetMap():lower()..".bsp"
|
||||
|
||||
if not table.HasValue(recentmaps, curmap) then
|
||||
table.insert(recentmaps, 1, curmap)
|
||||
end
|
||||
|
||||
file.Write("mapvote/recentmaps.txt", util.TableToJSON(recentmaps))
|
||||
end
|
||||
|
||||
function MapVote.GetFromULX()
|
||||
if (ulx == nil) then
|
||||
print("[!PH: Enhanced] Warning: ULX is not installed!")
|
||||
return false
|
||||
end
|
||||
|
||||
if (ulx.votemaps) then
|
||||
return ulx.votemaps
|
||||
end
|
||||
end
|
||||
|
||||
function MapVote.Start(length, current, limit, prefix)
|
||||
current = current or MapVote.Config.AllowCurrentMap or false
|
||||
length = length or MapVote.Config.TimeLimit or 28
|
||||
limit = limit or MapVote.Config.MapLimit or 24
|
||||
cooldown = MapVote.Config.EnableCooldown or true
|
||||
prefix = prefix or MapVote.Config.MapPrefixes
|
||||
|
||||
local is_expression = false
|
||||
local ulxmap = MapVote.GetFromULX()
|
||||
|
||||
if not prefix then
|
||||
local info = file.Read(GAMEMODE.Folder.."/"..GAMEMODE.FolderName..".txt", "GAME")
|
||||
|
||||
if(info) then
|
||||
local info = util.KeyValuesToTable(info)
|
||||
prefix = info.maps
|
||||
else
|
||||
error("MapVote Prefix can not be loaded from gamemode")
|
||||
end
|
||||
|
||||
is_expression = true
|
||||
else
|
||||
if prefix and type(prefix) ~= "table" then
|
||||
prefix = {prefix}
|
||||
end
|
||||
end
|
||||
|
||||
local maps = {}
|
||||
|
||||
if GetConVar("mv_use_ulx_votemaps"):GetBool() && ulxmap ~= false then
|
||||
for _,map in pairs(ulxmap) do
|
||||
table.insert(maps, map..".bsp")
|
||||
end
|
||||
else
|
||||
maps = file.Find("maps/*.bsp", "GAME")
|
||||
end
|
||||
|
||||
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 is_expression then
|
||||
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
|
||||
vote_maps[#vote_maps + 1] = map:sub(1, -5)
|
||||
amt = amt + 1
|
||||
break
|
||||
end
|
||||
end
|
||||
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
|
||||
map_results[v] = 0
|
||||
end
|
||||
|
||||
for k2, v2 in pairs(player.GetAll()) do
|
||||
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]
|
||||
|
||||
|
||||
|
||||
timer.Simple(4, function()
|
||||
hook.Run("MapVoteChange", map)
|
||||
RunConsoleCommand("changelevel", map)
|
||||
end)
|
||||
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
|
||||
MapVote.Allow = false
|
||||
|
||||
net.Start("RAM_MapVoteCancel")
|
||||
net.Broadcast()
|
||||
|
||||
timer.Destroy("RAM_MapVote")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user