Guest User

Untitled

a guest
Feb 13th, 2012
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*-------------------------------------------------------------------------------------------------------------------------
  2.     Start a vote
  3. -------------------------------------------------------------------------------------------------------------------------*/
  4.  
  5. local PLUGIN = {}
  6. PLUGIN.Title = "Vote Kick"
  7. PLUGIN.Description = "Start a vote to kick a player."
  8. PLUGIN.Author = "Therius"
  9. PLUGIN.ChatCommand = "votekick"
  10. PLUGIN.Usage = '<player>'
  11. PLUGIN.Privileges = { "Vote Kick" }
  12.  
  13. function PLUGIN:VoteKickEnd( targetpl2 )
  14.     SendUserMessage( "EV_VoteKickEnd", nil )
  15.    
  16.     local msg = ""
  17.     randomtable =   {
  18.                         [1]="",
  19.                         [2]=""
  20.                     }
  21.                    
  22.     yes = votesyes
  23.     no = votesno
  24.     for i, _ in pairs( randomtable ) do
  25.         if i == 1 then
  26.             local percent = 0
  27.             if ( yes == 0 ) then percent = 0 else percent = math.Round( ( yes or 0 ) / self.VotingPlayers * 100 ) end
  28.            
  29.             msg = msg .. " Yes" .. " (" .. percent .. "%) and "
  30.             yespercent = percent
  31.                
  32.         elseif i == 2 then
  33.             local percent = 0
  34.             if ( no == 0 ) then percent = 0 else percent = math.Round( ( no or 0 ) / self.VotingPlayers * 100 ) end
  35.            
  36.             msg = msg .. "No" .. " (" .. percent .. "%)"
  37.            
  38.             nopercent = percent
  39.         end
  40.  
  41.     end
  42.    
  43.     --evolve:Notify( evolve.colors.blue, "Votekick for ", evolve.colors.red, targetpl2, evolve.colors.white, msg .. "." )
  44.     evolve:Notify( evolve.colors.blue, "Votekick for ", evolve.colors.red, targetpl2, evolve.colors.white, "Yes ( " .. yes .. " ) and No ( " .. no .. " )." )
  45.    
  46.     local kickplayer = evolve:FindPlayer( targetpl2 )
  47.    
  48.     if yes >= self.VotingPlayers * 0.67 then
  49.         kickplayer[1]:Kick( "Votekicked" )
  50.     end
  51.    
  52.     self.Voting = nil
  53.     self.votesno = nil
  54.     self.votesyes = nil
  55. end
  56.  
  57. concommand.Add( "EV_VoteYes", function( ply, cmd, args )
  58.     if !votesyes or votesyes == nil then votesyes = 0 end
  59.     votesyes = votesyes + 1
  60. end )
  61. concommand.Add( "EV_VoteNo", function( ply, cmd, args )
  62.     if !votesno or votesno == nil then votesno = 0 end
  63.     votesno = votesno + 1
  64. end )
  65.  
  66. function PLUGIN:Call( ply, args )
  67.     if ( ply:EV_HasPrivilege( "Vote Kick" ) ) then
  68.         if ( self.Voting ) then
  69.             evolve:Notify( ply, evolve.colors.red, "You can't start a new vote kick until the current one has finished!" )
  70.             return
  71.         elseif ( #player.GetAll() < 2 ) then
  72.             evolve:Notify( ply, evolve.colors.red, "There aren't enough players to start a vote kick!" )
  73.             return
  74.         end
  75.        
  76.         local targetpl = evolve:FindPlayer( args[1] )
  77.        
  78.         if ( #targetpl == 0 ) then
  79.             evolve:Notify( ply, evolve.colors.red, "You haven't specified a player!" )
  80.         elseif ( #targetpl > 1 ) then
  81.                 evolve:Notify( ply, evolve.colors.white, "Did you mean ", evolve.colors.red, evolve:CreatePlayerList( targetpl, true ), evolve.colors.white, "?" )
  82.                
  83.                 return
  84.         elseif ( #targetpl == 1 ) then
  85.             targetpl = targetpl[1]
  86.             uid = targetpl:UniqueID()
  87.            
  88.  
  89.             self.Voting = true
  90.             votesyes = 0
  91.             votesno = 0
  92.             self.Votes = {}
  93.             self.VotingPlayers = 0
  94.             self.VotingPlayers = table.Count( player.GetAll() )
  95.            
  96.             umsg.Start( "EV_VoteKickMenu" )
  97.                 umsg.String( tostring( targetpl:Nick() ) )
  98.                 umsg.Short( votesyes )
  99.                 umsg.Short( votesno )
  100.             umsg.End()
  101.            
  102.             timer.Create( "EV_VoteKickEnd", 10, 1, function() PLUGIN:VoteKickEnd( targetpl:Nick() ) end )
  103.            
  104.             evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " has started the vote kick for ", evolve.colors.red, targetpl:Nick(), evolve.colors.white, "." )
  105.         end
  106.     else
  107.         evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )
  108.     end
  109. end
  110.  
  111. if ( CLIENT ) then
  112.     function PLUGIN:ShowVoteKickMenu( players )
  113.         self.VoteWindow = vgui.Create( "DFrame" )
  114.         self.VoteWindow:SetSize( 200, 95 )
  115.         self.VoteWindow:SetPos( ScrW() / 2 - self.VoteWindow:GetWide() / 2, ScrH() / 2 - self.VoteWindow:GetTall() / 2 )
  116.         if players then
  117.             self.VoteWindow:SetTitle( "Votekick " .. players )
  118.         else
  119.             self.VoteWindow:SetTitle( "Votekick " )
  120.         end
  121.         self.VoteWindow:SetDraggable( false )
  122.         self.VoteWindow:ShowCloseButton( true )
  123.         self.VoteWindow:SetBackgroundBlur( true )
  124.         self.VoteWindow:MakePopup()
  125.        
  126.         local optionlist = vgui.Create( "DPanelList", self.VoteWindow )
  127.         optionlist:SetPos( 5, 25 )
  128.         optionlist:SetSize( 190, 65 )
  129.         optionlist:SetPadding( 5 )
  130.         optionlist:SetSpacing( 5 )
  131.        
  132.        
  133.         local voteyes = vgui.Create( "DButton" )
  134.         voteyes:SetText( "Yes" )
  135.         voteyes:SetTall( 25 )
  136.         voteyes.DoClick = function()
  137.             RunConsoleCommand( "EV_VoteYes" )
  138.             evolve:Notify( evolve.colors.white, "Someone has voted yes!" )
  139.             self.VoteWindow:Close()
  140.         end
  141.        
  142.         local voteno = vgui.Create( "DButton" )
  143.         voteno:SetText( "No" )
  144.         voteno:SetTall( 25 )
  145.         voteno.DoClick = function()
  146.             RunConsoleCommand( "EV_VoteNo" )
  147.             self.VoteWindow:Close()
  148.             evolve:Notify( evolve.colors.white, "Someone has voted no!" )
  149.         end
  150.            
  151.         optionlist:AddItem( voteyes )
  152.         optionlist:AddItem( voteno )
  153.  
  154.     end
  155.     --concommand.Add( "test_votekick", PLUGIN.ShowVoteKickMenu )
  156.    
  157.     usermessage.Hook( "EV_VoteKickMenu", function( um )
  158.         local players = um:ReadString()
  159.         PLUGIN:ShowVoteKickMenu( players )
  160.     end )
  161. end
  162.  
  163.  
  164. if ( SERVER ) then
  165.  
  166. end
  167.  
  168. usermessage.Hook( "EV_VoteKickEnd", function()
  169.     if ( PLUGIN.VoteWindow and PLUGIN.VoteWindow.Close ) then
  170.         PLUGIN.VoteWindow:Close()
  171.     end
  172. end )
  173.  
  174. evolve:RegisterPlugin( PLUGIN )
RAW Paste Data