• Vote for godmode and etc
    5 replies, posted
I'm looking for something that can be used by players to either then enable or disable godmode, plpldamage and such. I know that some admin mods has this automatically, but I'm using Exsto, and I am not going to change that just for this one command.
I'll write it for you in a bit if someone doesn't do it before me.
SolidVote has godmode vote but not plpldamage, I don't know if it's compatible with Exsto, you should try it out and see.
This will set whatever setting on or off if half the server wants it. The right shows how many votes have been placed and how many are required. Type /votemenu in the chat to open/close the menu. [IMG]http://img268.imageshack.us/img268/3627/62217569.jpg[/IMG] [IMG]http://img339.imageshack.us/img339/9240/28045009.jpg[/IMG] Create a file(PlayerVoteSystem.lua) in garrysmod/lua/autorun and save this inside it. [lua] PVS = {} PVS.Options = { {Name = "God Mode", Command = "sbox_godmode", Votes = {}}, {Name = "Player vs Player", Command = "sbox_plpldamage", Votes = {}} } if SERVER then function PVS.OpenMenu(pl, txt, T, D) if string.lower(string.sub(txt, 1, 9)) == "/votemenu" then umsg.Start("TogglePVSVoteMenu", pl) umsg.End() return end end hook.Add("PlayerSay", "SayVote", PVS.OpenMenu) function PVS.AddVote(pl, cmd, arg) local Key = arg[1] if !PVS.Options[tonumber(Key)] then return end if table.HasValue(PVS.Options[tonumber(Key)].Votes, pl) then return end table.insert(PVS.Options[tonumber(Key)].Votes, pl) umsg.Start("UpdatePVS", player.GetAll()) umsg.Long(Key) umsg.Long(#PVS.Options[tonumber(Key)].Votes) umsg.End() if #PVS.Options[tonumber(Key)].Votes >= math.ceil(#player.GetAll()/2) then RunConsoleCommand(PVS.Options[tonumber(Key)].Command, "1") end end concommand.Add("PVS_AddVote", PVS.AddVote) function PVS.RemoveVote(pl, cmd, arg) local Key = arg[1] if !PVS.Options[tonumber(Key)] then return end if table.HasValue(PVS.Options[tonumber(Key)].Votes, pl) then for k, v in pairs(PVS.Options[tonumber(Key)].Votes) do if v == pl then table.remove(PVS.Options[tonumber(Key)].Votes, k) umsg.Start("UpdatePVS", player.GetAll()) umsg.Long(Key) umsg.Long(#PVS.Options[tonumber(Key)].Votes) umsg.End() if #PVS.Options[tonumber(Key)].Votes < math.ceil(#player.GetAll()/2) then RunConsoleCommand(PVS.Options[tonumber(Key)].Command, "0") end end end end end concommand.Add("PVS_RemoveVote", PVS.RemoveVote) else function PVS.ToggleVoteMenu() if !PVS.Menu then for k, v in pairs(PVS.Options) do v.Votes = 0 end PVS.Menu = vgui.Create("DFrame") PVS.Menu:SetSize(256, (#PVS.Options*19)+28) PVS.Menu:SetPos((ScrW()/2)-(PVS.Menu:GetWide()/2), (ScrH()/2)-PVS.Menu:GetTall()) PVS.Menu:SetTitle("Player Vote Menu") PVS.Menu:ShowCloseButton(true) PVS.Menu:SetDraggable(false) PVS.Menu:SetVisible(false) PVS.Menu.IsOpen = false PVS.Menu.Paint = function() surface.SetDrawColor(80, 80, 80, 180) surface.DrawRect(0 , 0, PVS.Menu:GetWide(), PVS.Menu:GetTall()) surface.SetDrawColor(000, 000, 000, 255) surface.DrawOutlinedRect(0 , 0, PVS.Menu:GetWide(), PVS.Menu:GetTall()) for k, v in pairs(PVS.Options) do draw.SimpleText(v.Votes.."/"..math.ceil(#player.GetAll()/2), "Default", PVS.Menu:GetWide() - 5, (19*(k-1))+26, color_white, 2, 0) end end PVS.Menu.Toggle = function() if !PVS.Menu.IsOpen then PVS.Menu.IsOpen = true RestoreCursorPosition() PVS.Menu:SetVisible(true) gui.EnableScreenClicker(true) else PVS.Menu:Close() end end PVS.Menu.Close = function() PVS.Menu.IsOpen = false RememberCursorPosition() PVS.Menu:SetVisible(false) gui.EnableScreenClicker(false) end for k, v in pairs(PVS.Options) do local Option = vgui.Create("DCheckBoxLabel", PVS.Menu) Option:SetText(v.Name) Option:SetPos(7, (19*(k-1))+26) Option:SetValue(0) Option:SizeToContents() Option.OnChange = function() if Option:GetChecked() then RunConsoleCommand("PVS_AddVote", k) else RunConsoleCommand("PVS_RemoveVote", k) end end end end PVS.Menu:Toggle(PVS.Menu.IsOpen) end usermessage.Hook("TogglePVSVoteMenu", PVS.ToggleVoteMenu) function PVS.Update(msg) local Key = msg:ReadLong() local Votes = msg:ReadLong() PVS.Options[tonumber(Key)].Votes = Votes end usermessage.Hook("UpdatePVS", PVS.Update) end [/lua]
Thank you a lot find me. Just what I were looking for. :)
You're welcome, I rushed through it and didn't think it out so there are a few problems that you might notice later on. They aren't really a big deal but they can be pesky. If I'm ever in the mood to code something I'll redo it and pm you about it.
Sorry, you need to Log In to post a reply to this thread.