Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if CLIENT then
- function ShowVoteFrame(desc, time)
- if VOTE_FRAME and VOTE_FRAME:IsValid() then VOTE_FRAME:Remove() end
- local frame = vgui.Create("DPanel")
- VOTE_FRAME = frame
- frame:SetSize(200, 200)
- frame:SetPos(30, 30)
- frame:SetBackgroundColor(Color(30, 30, 30, 255))
- frame:DockPadding(4,4,4,4)
- local lbl = vgui.Create("DLabel", frame)
- lbl:Dock(TOP)
- lbl:SetFont("Default")
- lbl:SetText(desc or "")
- lbl:SizeToContents()
- lbl:DockMargin(1,1,4,4)
- local info = vgui.Create("DPanel", frame)
- info:Dock(TOP)
- info:SetTall(frame:GetTall() / 2)
- local yes = vgui.Create("DLabel", info)
- yes:Dock(TOP)
- yes:SetFont("Trebuchet22")
- yes:SetText("Press F11 to vote YES")
- yes:SizeToContents()
- yes:DockMargin(1,1,4,4)
- local no = vgui.Create("DLabel", info)
- no:Dock(TOP)
- no:SetFont("Trebuchet22")
- no:SetText("Press F12 to vote NO")
- no:SizeToContents()
- no:DockMargin(1,1,4,4)
- info:SetTall(yes:GetTall() + no:GetTall() + 8)
- info:DockMargin(0,0,4,4)
- local list = vgui.Create("DPanelList", frame)
- list:EnableHorizontal(true)
- list:Dock(TOP)
- list:SetSpacing(2)
- list:SetPadding(4)
- local votes = {}
- for key, ply in pairs(player.GetHumans()) do
- local pnl = vgui.Create("DCheckBox")
- pnl:SetSize(16, 16)
- list:AddItem(pnl)
- votes[ply:UniqueID()] = pnl
- end
- list:SizeToContents()
- list:DockMargin(1,1,4,4)
- local _, y = list:LocalToScreen()
- y = y - list:GetTall()
- local _, _y = frame:GetPos()
- epoe.Print(_y - y)
- frame:SetTall(frame:GetTall() - (_y - y) - 8)
- local last = 0
- hook.Add( "Think", "VoteThink", function()
- for id, pnl in pairs(votes) do
- if pnl:IsValid() then
- local ply = player.GetByUniqueID(id) or NULL
- if ply:IsValid() then
- pnl:SetChecked(ply:GetNWBool("vote_answer") == 1)
- pnl:Toggle()
- pnl:Toggle()
- else
- votes[id]:Remove()
- list:InvalidateLayout()
- end
- else
- votes[id] = nil
- list:InvalidateLayout()
- end
- end
- if RealTime() > last + 1 then
- if input.IsKeyDown(KEY_F11) then
- RunConsoleCommand("voteyes")
- last = RealTime()
- elseif input.IsKeyDown(KEY_F12) then
- RunConsoleCommand("voteno")
- last = RealTime()
- end
- end
- end)
- timer.Simple(time or 10, function()
- if VOTE_FRAME and VOTE_FRAME:IsValid() then
- VOTE_FRAME:Remove()
- end
- hook.Remove("Think", "VoteThink")
- end)
- end
- usermessage.Hook("ShowVoteFrame", function(umr)
- local desc = umr:ReadString()
- local time = umr:ReadShort()
- ShowVoteFrame(desc, time)
- end)
- end
- if SERVER then
- local function start_vote(cmd, line)
- local tag = "vote" .. cmd .. line
- umsg.Start("ShowVoteFrame")
- umsg.String(cmd .. " " .. line)
- umsg.Short(10)
- umsg.End()
- timer.Simple(10, function()
- local count = 0
- local total = #player.GetHumans()
- for key, ply in pairs(player.GetHumans()) do
- local val = ply:GetNWBool("vote_answer")
- if val == -1 then
- --total = total - 1
- elseif val == 1 then
- count = count + 1
- end
- ply:SetNWBool("vote_answer", -1)
- end
- if count > 0 and total > 0 then
- count = count / total
- local percent = math.Round(count*100)
- Say(percent .. "% voted yes")
- if percent > 51 then
- vote_func()
- end
- end
- end)
- end
- hook.Add("PlayerSay", "vote", function(ply, str)
- local cmd, line = str:match("(vote)(.+)")
- if cmd == "vote" then
- cmd = line:match("(.-) ") or str:match("(.+)") or ""
- line = line:match(".- (.+)")
- if aowl.cmds[cmd] then
- vote_func = function()
- _G.CHAT = true
- aowl.CallCommand(ply, cmd, line, line and line:Split(",") or {}, true)
- _G.CHAT = nil
- end
- start_vote(cmd, line)
- else
- end
- end
- end)
- concommand.Add("voteyes", function(ply)
- print(ply, " ", " voted yes")
- ply:SetNWBool("vote_answer", 1)
- end)
- concommand.Add("voteno", function(ply)
- print(ply, " ", " voted no")
- ply:SetNWBool("vote_answer", 0)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment