Advertisement
Guest User

Untitled

a guest
Feb 28th, 2012
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 KB | None | 0 0
  1. if ( SERVER ) then
  2.     function DetermineMapWinner()
  3.         max = 0
  4.         winningcount = 0
  5.         winners = {}
  6.         for k,v in pairs( Results ) do
  7.             if v > max then
  8.                 max = v
  9.             end
  10.         end
  11.         for k,v in pairs( Results ) do
  12.             if v == max then
  13.                 winningcount = winningcount + 1
  14.                 winnerindex = table.Count( winners ) + 1
  15.                 winners[winnerindex] = k
  16.             end
  17.         end
  18.         if winningcount > 1 then
  19.             finalwinner = table.Random( winningcount )
  20.             return newmaplist[finalwinner]
  21.         else
  22.             return newmaplist[finalwinner]
  23.         end
  24.     end
  25.     hook.Add( "TTTEndRound", "ChangeMap", function()
  26.         rounds_left = math.max(0, GetGlobalInt("ttt_rounds_left", 6))
  27.         if rounds_left <= 0 then
  28.             if DoChangeMap or DoChangeMap == nil then
  29.                 DoChangeMap = false
  30.                 maplist =   {   "cs_assult",
  31.                                 "cs_compound",
  32.                                 "cs_havana",
  33.                                 "cs_militia",
  34.                                 "cs_office"
  35.                 }
  36.                 Results = { 0, 0, 0, 0, 0 }
  37.                 newmaplist = {}
  38.                 map = nil
  39.                 for i=1,5 do
  40.                     randommap = math.random( 1, #maplist )
  41.                     newmaplist[i] = maplist[randommap]
  42.                     table.remove( maplist, randommap )
  43.                     --print( newmaplist[i] )
  44.                 end
  45.                
  46.                 for k, v in pairs( player.GetAll() ) do
  47.                     timer.Simple( 5, function()
  48.                         umsg.Start( "SendVoteMsg" );
  49.                             for i=1,5 do
  50.                                 local map = newmaplist[i]
  51.                                 --print( map )
  52.                                 umsg.String( tostring( map ) )
  53.                             end
  54.                         umsg.End();
  55.                     end )
  56.                 end
  57.                
  58.                 timer.Simple( 10, function()
  59.                     local map = DetermineMapWinner()
  60.                     evolve.Notify( evolve.colors.red, map .. " has won the vote!" )
  61.                 end )
  62.                 timer.Simple( 15, function()
  63.                     RunConsoleCommand( "ev", "map", map )
  64.                 end )
  65.             end
  66.         end
  67.     end )
  68.     concommand.Add( "VoteForMap1", function()
  69.         Results[1] = Results[1] + 1
  70.     end )
  71.     concommand.Add( "VoteForMap2", function()
  72.         Results[2] = Results[2] + 1
  73.     end )
  74.     concommand.Add( "VoteForMap3", function()
  75.         Results[3] = Results[3] + 1
  76.     end )
  77.     concommand.Add( "VoteForMap4", function()
  78.         Results[4] = Results[4] + 1
  79.     end )
  80.     concommand.Add( "VoteForMap5", function()
  81.         Results[5] = Results[5] + 1
  82.     end )
  83. end
  84. if ( CLIENT ) then
  85.     usermessage.Hook( "SendVoteMsg", function( um )
  86.             VoteMapWindow = vgui.Create( "DFrame" )
  87.             VoteMapWindow:SetSize( 200,185 )
  88.             VoteMapWindow:SetPos( ScrW() / 2 - VoteMapWindow:GetWide() / 2, ScrH() / 2 - VoteMapWindow:GetTall() / 2 )
  89.             VoteMapWindow:SetTitle( "Map Vote" )           
  90.             VoteMapWindow:SetDraggable( false )
  91.             VoteMapWindow:ShowCloseButton( true )
  92.             VoteMapWindow:SetBackgroundBlur( true )
  93.             VoteMapWindow:MakePopup()
  94.            
  95.             local optionlist = vgui.Create( "DPanelList", VoteMapWindow )
  96.             optionlist:SetPos( 5, 25 )
  97.             optionlist:SetSize( 190, 155 )
  98.             optionlist:SetPadding( 5 )
  99.             optionlist:SetSpacing( 5 )
  100.                    
  101.             map1string = um:ReadString()
  102.             map2string = um:ReadString()
  103.             map3string = um:ReadString()
  104.             map4string = um:ReadString()
  105.             map5string = um:ReadString()
  106.            
  107.             local map1 = vgui.Create( "DButton" )
  108.             map1:SetText( map1string )
  109.             map1:SetTall( 25 )
  110.             map1.DoClick = function()
  111.                 RunConsoleCommand( "VoteForMap1" )
  112.                 VoteMapWindow:Close()
  113.             end
  114.            
  115.             local map2 = vgui.Create( "DButton" )
  116.             map2:SetText( map2string )
  117.             map2:SetTall( 25 )
  118.             map2.DoClick = function()
  119.                 RunConsoleCommand( "VoteForMap2" )
  120.                 VoteMapWindow:Close()
  121.             end
  122.            
  123.             local map3 = vgui.Create( "DButton" )
  124.             map3:SetText( map3string )
  125.             map3:SetTall( 25 )
  126.             map3.DoClick = function()
  127.                 RunConsoleCommand( "VoteForMap3" )
  128.                 VoteMapWindow:Close()
  129.             end
  130.            
  131.             local map4 = vgui.Create( "DButton" )
  132.             map4:SetText( map4string )
  133.             map4:SetTall( 25 )
  134.             map4.DoClick = function()
  135.                 RunConsoleCommand( "VoteForMap4" )
  136.                 VoteMapWindow:Close()
  137.             end
  138.            
  139.             local map5 = vgui.Create( "DButton" )
  140.             map5:SetText( map5string )
  141.             map5:SetTall( 25 )
  142.             map5.DoClick = function()
  143.                 RunConsoleCommand( "VoteForMap5" )
  144.                 VoteMapWindow:Close()
  145.             end
  146.            
  147.                
  148.             optionlist:AddItem( map1 )
  149.             optionlist:AddItem( map2 )
  150.             optionlist:AddItem( map3 )
  151.             optionlist:AddItem( map4 )
  152.             optionlist:AddItem( map5 )
  153.  
  154.     end )
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement