Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-------------------------------------------------------------------------------------------------------------------------
- Start a vote
- -------------------------------------------------------------------------------------------------------------------------*/
- local PLUGIN = {}
- PLUGIN.Title = "Vote Kick"
- PLUGIN.Description = "Start a vote to kick a player."
- PLUGIN.Author = "Therius"
- PLUGIN.ChatCommand = "votekick"
- PLUGIN.Usage = '<player>'
- PLUGIN.Privileges = { "Vote Kick" }
- function PLUGIN:VoteKickEnd( targetpl2 )
- SendUserMessage( "EV_VoteKickEnd", nil )
- local msg = ""
- randomtable = {
- [1]="",
- [2]=""
- }
- yes = votesyes
- no = votesno
- for i, _ in pairs( randomtable ) do
- if i == 1 then
- local percent = 0
- if ( yes == 0 ) then percent = 0 else percent = math.Round( ( yes or 0 ) / self.VotingPlayers * 100 ) end
- msg = msg .. " Yes" .. " (" .. percent .. "%) and "
- yespercent = percent
- elseif i == 2 then
- local percent = 0
- if ( no == 0 ) then percent = 0 else percent = math.Round( ( no or 0 ) / self.VotingPlayers * 100 ) end
- msg = msg .. "No" .. " (" .. percent .. "%)"
- nopercent = percent
- end
- end
- --evolve:Notify( evolve.colors.blue, "Votekick for ", evolve.colors.red, targetpl2, evolve.colors.white, msg .. "." )
- evolve:Notify( evolve.colors.blue, "Votekick for ", evolve.colors.red, targetpl2, evolve.colors.white, "Yes ( " .. yes .. " ) and No ( " .. no .. " )." )
- local kickplayer = evolve:FindPlayer( targetpl2 )
- if yes >= self.VotingPlayers * 0.67 then
- kickplayer[1]:Kick( "Votekicked" )
- end
- self.Voting = nil
- self.votesno = nil
- self.votesyes = nil
- end
- concommand.Add( "EV_VoteYes", function( ply, cmd, args )
- if !votesyes or votesyes == nil then votesyes = 0 end
- votesyes = votesyes + 1
- end )
- concommand.Add( "EV_VoteNo", function( ply, cmd, args )
- if !votesno or votesno == nil then votesno = 0 end
- votesno = votesno + 1
- end )
- function PLUGIN:Call( ply, args )
- if ( ply:EV_HasPrivilege( "Vote Kick" ) ) then
- if ( self.Voting ) then
- evolve:Notify( ply, evolve.colors.red, "You can't start a new vote kick until the current one has finished!" )
- return
- elseif ( #player.GetAll() < 2 ) then
- evolve:Notify( ply, evolve.colors.red, "There aren't enough players to start a vote kick!" )
- return
- end
- local targetpl = evolve:FindPlayer( args[1] )
- if ( #targetpl == 0 ) then
- evolve:Notify( ply, evolve.colors.red, "You haven't specified a player!" )
- elseif ( #targetpl > 1 ) then
- evolve:Notify( ply, evolve.colors.white, "Did you mean ", evolve.colors.red, evolve:CreatePlayerList( targetpl, true ), evolve.colors.white, "?" )
- return
- elseif ( #targetpl == 1 ) then
- targetpl = targetpl[1]
- uid = targetpl:UniqueID()
- self.Voting = true
- votesyes = 0
- votesno = 0
- self.Votes = {}
- self.VotingPlayers = 0
- self.VotingPlayers = table.Count( player.GetAll() )
- umsg.Start( "EV_VoteKickMenu" )
- umsg.String( tostring( targetpl:Nick() ) )
- umsg.Short( votesyes )
- umsg.Short( votesno )
- umsg.End()
- timer.Create( "EV_VoteKickEnd", 10, 1, function() PLUGIN:VoteKickEnd( targetpl:Nick() ) end )
- evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " has started the vote kick for ", evolve.colors.red, targetpl:Nick(), evolve.colors.white, "." )
- end
- else
- evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )
- end
- end
- if ( CLIENT ) then
- function PLUGIN:ShowVoteKickMenu( players )
- self.VoteWindow = vgui.Create( "DFrame" )
- self.VoteWindow:SetSize( 200, 95 )
- self.VoteWindow:SetPos( ScrW() / 2 - self.VoteWindow:GetWide() / 2, ScrH() / 2 - self.VoteWindow:GetTall() / 2 )
- if players then
- self.VoteWindow:SetTitle( "Votekick " .. players )
- else
- self.VoteWindow:SetTitle( "Votekick " )
- end
- self.VoteWindow:SetDraggable( false )
- self.VoteWindow:ShowCloseButton( true )
- self.VoteWindow:SetBackgroundBlur( true )
- self.VoteWindow:MakePopup()
- local optionlist = vgui.Create( "DPanelList", self.VoteWindow )
- optionlist:SetPos( 5, 25 )
- optionlist:SetSize( 190, 65 )
- optionlist:SetPadding( 5 )
- optionlist:SetSpacing( 5 )
- local voteyes = vgui.Create( "DButton" )
- voteyes:SetText( "Yes" )
- voteyes:SetTall( 25 )
- voteyes.DoClick = function()
- RunConsoleCommand( "EV_VoteYes" )
- evolve:Notify( evolve.colors.white, "Someone has voted yes!" )
- self.VoteWindow:Close()
- end
- local voteno = vgui.Create( "DButton" )
- voteno:SetText( "No" )
- voteno:SetTall( 25 )
- voteno.DoClick = function()
- RunConsoleCommand( "EV_VoteNo" )
- self.VoteWindow:Close()
- evolve:Notify( evolve.colors.white, "Someone has voted no!" )
- end
- optionlist:AddItem( voteyes )
- optionlist:AddItem( voteno )
- end
- --concommand.Add( "test_votekick", PLUGIN.ShowVoteKickMenu )
- usermessage.Hook( "EV_VoteKickMenu", function( um )
- local players = um:ReadString()
- PLUGIN:ShowVoteKickMenu( players )
- end )
- end
- if ( SERVER ) then
- end
- usermessage.Hook( "EV_VoteKickEnd", function()
- if ( PLUGIN.VoteWindow and PLUGIN.VoteWindow.Close ) then
- PLUGIN.VoteWindow:Close()
- end
- end )
- evolve:RegisterPlugin( PLUGIN )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement