Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.71 KB | None | 0 0
  1. if ( CLIENT ) then
  2.  
  3.     MsgN( "End Round Music by Cobalt loaded!" )
  4.  
  5. end
  6.  
  7. -- ULX Commands
  8. function ulx.playurl( calling_ply, url, volume )
  9.  
  10.     umsg.Start( "playurl", player.GetAll() )
  11.         umsg.String( url )
  12.         umsg.Long ( volume )
  13.     umsg.End()
  14.    
  15.     ulx.fancyLogAdmin( calling_ply, "#A played URL #s (type !stop to stop)", url )
  16.    
  17. end
  18. local playurl = ulx.command( "Fun", "ulx playurl", ulx.playurl, "!playurl" )
  19. playurl:addParam{ type=ULib.cmds.StringArg, hint="url" }
  20. playurl:addParam{ type=ULib.cmds.NumArg, min=0, max=100, default=50, hint="volume", ULib.cmds.optional, ULib.cmds.round }
  21. playurl:defaultAccess( ULib.ACCESS_ADMIN )
  22. playurl:help( "Play a sound from a URL." )
  23.  
  24. function ulx.playurlcl( calling_ply, url, volume )
  25.  
  26.     umsg.Start( "playurlcl", calling_ply )
  27.         umsg.String( url )
  28.         umsg.Long( volume )
  29.     umsg.End()
  30.    
  31.     ulx.fancyLog( { calling_ply }, "URL #s playing locally (type !stop to stop)", url )
  32.    
  33. end
  34. local playurlcl = ulx.command( "Fun", "ulx playurlcl", ulx.playurlcl, "!playurlcl" )
  35. playurlcl:addParam{ type=ULib.cmds.StringArg, hint="url" }
  36. playurlcl:addParam{ type=ULib.cmds.NumArg, min=0, max=100, default=50, hint="volume", ULib.cmds.optional, ULib.cmds.round }
  37. playurlcl:defaultAccess( ULib.ACCESS_ALL )
  38. playurlcl:help( "Play a sound from a URL for yourself." )
  39.  
  40. function ulx.playvolume( calling_ply, volume )
  41.  
  42.     umsg.Start( "playvolume", player.GetAll() )
  43.         umsg.Long( volume )
  44.     umsg.End()
  45.    
  46.     ulx.fancyLogAdmin( calling_ply, "#A set volume #s", volume )
  47.    
  48. end
  49.  
  50.  
  51. local playvolume = ulx.command( "Fun", "ulx playvolume", ulx.playvolume, "!playvolume" )
  52. playvolume:addParam{ type=ULib.cmds.NumArg, min=0, max=100, default=50, hint="times", ULib.cmds.optional, ULib.cmds.round }
  53. playvolume:defaultAccess( ULib.ACCESS_ADMIN )
  54. playvolume:help( "Sets the volume." )
  55.  
  56. function ulx.stopurl( calling_ply )
  57.  
  58.     umsg.Start( "stopurl", player.GetAll() )
  59.     umsg.End()
  60.    
  61.     ulx.fancyLogAdmin( calling_ply, "#A stopped the URL for the server" )
  62.    
  63. end
  64. local stopurl = ulx.command( "Fun", "ulx stopurl", ulx.stopurl, "!stopurl" )
  65. stopurl:defaultAccess( ULib.ACCESS_ADMIN )
  66. stopurl:help( "Play a sound from a URL." )
  67.  
  68. function ulx.endroundmenu( calling_ply )
  69.  
  70.     umsg.Start( "open_endround_menu", calling_ply )
  71.     umsg.End()
  72.    
  73. end
  74. local endroundmenu = ulx.command( "Fun", "ulx endroundmenu", ulx.endroundmenu, "!endround" )
  75. endroundmenu:defaultAccess( ULib.ACCESS_ALL )
  76. endroundmenu:help( "Open the end round music menu." )
  77.  
  78. function ulx.queuesong( calling_ply )
  79.    
  80.     if calling_ply:GetPData( "Cooldown" ) and tonumber( calling_ply:GetPData( "Cooldown" ) ) > 0 then
  81.         calling_ply:ChatPrint( "You are unable to queue a song right now. Try again in " .. calling_ply:GetPData( "Cooldown" ) .. " minute(s)." )
  82.         return
  83.     end
  84.    
  85.     umsg.Start( "EnterInfo", calling_ply )
  86.     umsg.End()
  87.    
  88. end
  89. local queuesong = ulx.command( "Fun", "ulx queuesong", ulx.queuesong, { "!queuesong", "!queue" } )
  90. queuesong:defaultAccess( ULib.ACCESS_ADMIN )
  91. queuesong:help( "Queue a song for the end of the round." )
  92.  
  93. function ulx.stopurlcl( calling_ply )
  94.  
  95.     umsg.Start( "stopurl", calling_ply )
  96.     umsg.End()
  97.    
  98. end
  99. local stopurlcl = ulx.command( "Fun", "ulx stopurlcl", ulx.stopurlcl, { "!stop", "!stopurlcl" } )
  100. stopurlcl:defaultAccess( ULib.ACCESS_ALL )
  101. stopurlcl:help( "Stop sounds for yourself." )
  102.  
  103. -- Serverside Networking
  104. if ( SERVER ) then
  105.  
  106.     util.AddNetworkString( "RequestTables" )
  107.     util.AddNetworkString( "RequestTablesCallback" )
  108.     util.AddNetworkString( "SendQueueInfo" )
  109.     util.AddNetworkString( "RequestQueue" )
  110.     util.AddNetworkString( "RequestQueueCallback" )
  111.     util.AddNetworkString( "Queue_Remove" )
  112.     util.AddNetworkString( "SendCooldownInfo" )
  113.    
  114.     local QueueTable = {}
  115.    
  116.     if GetConVar( "gamemode" ):GetString() == "terrortown" then
  117.    
  118.         hook.Add( "TTTEndRound", "PlayMusicOnEndRound", function( win )
  119.        
  120.             if table.Count( QueueTable ) > 0 then
  121.            
  122.                 local toPlay = QueueTable[ 1 ]
  123.                
  124.                 umsg.Start( "playurl", player.GetAll() )
  125.                     umsg.String( toPlay[ 3 ] )
  126.                     umsg.Long ( 50 )
  127.                 umsg.End()
  128.                
  129.                 umsg.Start( "SendSongName", player.GetAll() )
  130.                     umsg.String( toPlay[ 2 ] )
  131.                 umsg.End()
  132.                
  133.                 ulx.fancyLog( player.GetAll(), "Playing queued song #s requested by #s", toPlay[ 2 ], toPlay[ 1 ] )
  134.                
  135.                 table.remove( QueueTable, 1 )
  136.                
  137.             else
  138.            
  139.                 if win == WIN_INNOCENT then
  140.                
  141.                     local toPlay = table.Random( innowinsounds )
  142.                    
  143.                     umsg.Start( "playurl", player.GetAll() )
  144.                         umsg.String( toPlay[ 1 ] )
  145.                         umsg.Long ( 50 )                       
  146.                     umsg.End()
  147.                    
  148.                     umsg.Start( "SendSongName", player.GetAll() )
  149.                         umsg.String( toPlay[ 2 ] )
  150.                     umsg.End()
  151.                    
  152.                 elseif win == WIN_TRAITOR then
  153.                
  154.                     local toPlay = table.Random( traitorwinsounds )
  155.                    
  156.                     umsg.Start( "playurl", player.GetAll() )
  157.                         umsg.String( toPlay[ 1 ] )
  158.                         umsg.Long ( 50 )   
  159.                     umsg.End()
  160.                    
  161.                     umsg.Start( "SendSongName", player.GetAll() )
  162.                         umsg.String( toPlay[ 2 ] )
  163.                     umsg.End()
  164.                    
  165.                 elseif win == WIN_TIMELIMIT then
  166.                
  167.                     local toPlay = table.Random( timelimitsounds )
  168.                    
  169.                     umsg.Start( "playurl", player.GetAll() )
  170.                         umsg.String( toPlay[ 1 ] )
  171.                         umsg.Long ( 50 )   
  172.                     umsg.End()
  173.                    
  174.                     umsg.Start( "SendSongName", player.GetAll() )
  175.                         umsg.String( toPlay[ 2 ] )
  176.                     umsg.End()
  177.                    
  178.                 end
  179.                
  180.             end
  181.            
  182.         end )
  183.        
  184.         hook.Add( "TTTPrepareRound", "StopSounds", function()
  185.            
  186.             umsg.Start( "stop_preround", player.GetAll() )
  187.             umsg.End()
  188.            
  189.             umsg.Start( "StopHUDPaint", player.GetAll() )
  190.             umsg.End()
  191.            
  192.         end )
  193.        
  194.     end
  195.  
  196.     concommand.Add( "endround_menu", function( ply, cmd, args )
  197.    
  198.         umsg.Start( "open_endround_menu", ply )
  199.         umsg.End()
  200.        
  201.     end )
  202.    
  203.     net.Receive( "RequestTables", function( len, ply )
  204.        
  205.         net.Start( "RequestTablesCallback" )
  206.             net.WriteTable( innowinsounds )
  207.             net.WriteTable( traitorwinsounds )
  208.             net.WriteTable( timelimitsounds )
  209.             net.WriteTable( extrasounds )
  210.         net.Send( ply )
  211.        
  212.     end )
  213.    
  214.     net.Receive( "SendQueueInfo", function( len, ply )
  215.    
  216.         local sName = net.ReadString()
  217.         local sUrl = net.ReadString()
  218.        
  219.         if sName:len() > 0 and sUrl:len() > 0 then
  220.             table.insert( QueueTable, { ply:Nick(), sName, sUrl } )
  221.         end
  222.        
  223.         ulx.fancyLog( player.GetAll(), "#s queued song #s", ply:Nick(), sName )
  224.        
  225.     end )
  226.    
  227.     net.Receive( "RequestQueue", function( len, ply )
  228.    
  229.         if ply:IsValid() then
  230.        
  231.             net.Start( "RequestQueueCallback" )
  232.                 net.WriteTable( QueueTable )
  233.             net.Send( ply )
  234.            
  235.         end
  236.        
  237.     end )
  238.    
  239.     net.Receive( "Queue_Remove", function( len, ply )
  240.        
  241.         if not ply:IsAdmin() then
  242.             ply:ChatPrint( "You don't have access to this command, " .. ply:Nick() .. "!" )
  243.             return
  244.         end
  245.        
  246.         local name = net.ReadString()
  247.         local pos = net.ReadDouble()
  248.        
  249.         table.remove( QueueTable, pos )
  250.        
  251.         ulx.fancyLog( player.GetAll(), "#s removed song #s from the queue", ply:Nick(), name )
  252.        
  253.     end )
  254.    
  255.     net.Receive( "SendCooldownInfo", function( len, ply )
  256.    
  257.         ply:SetPData( "Cooldown", 3 )
  258.        
  259.     end )
  260.    
  261.     timer.Create( "CooldownTimer", 60, 0, function()
  262.    
  263.         for k, v in pairs( player.GetAll() ) do
  264.        
  265.             if v:GetPData( "Cooldown" ) and tonumber( v:GetPData( "Cooldown" ) ) > 0  then
  266.            
  267.                 if tonumber( v:GetPData( "Cooldown" ) ) - 1 == 0 then  
  268.                
  269.                     v:RemovePData( "Cooldown" )
  270.                     v:ChatPrint( "You are now able to request a song again." ) 
  271.                    
  272.                 else
  273.                     v:SetPData( "Cooldown", tonumber( v:GetPData( "Cooldown" ) ) - 1 )
  274.                 end
  275.                
  276.             end
  277.            
  278.         end
  279.        
  280.     end )
  281.  
  282. end
  283.  
  284.  
  285. -- Clientside networking and GUI
  286. if ( CLIENT ) then
  287.    
  288.     CreateClientConVar( "ttt_eor_music_enabled", "1", FCVAR_ARCHIVE )
  289.    
  290.     if not file.Exists( "radio", "DATA" ) then
  291.         file.CreateDir( "radio" )
  292.     end
  293.    
  294.     if not file.Exists( "radio/stations.txt", "DATA" ) then
  295.         file.Write( "radio/stations.txt" )
  296.     end
  297.    
  298.     usermessage.Hook( "playurlcl", function( um )
  299.    
  300.         local url = um:ReadString()
  301.         local volume = um:ReadLong() / 100
  302.         local ply = LocalPlayer()
  303.        
  304.         if ply.channel and IsValid( ply.channel ) then
  305.             ply.channel:Stop()
  306.         end
  307.        
  308.         sound.PlayURL( url, "", function( station )    
  309.             if station and IsValid( station ) then         
  310.                 station:Play()
  311.                 LocalPlayer().channel = station
  312.                 LocalPlayer().channel:SetVolume(volume)        
  313.             end        
  314.         end )
  315.        
  316.     end )  
  317.    
  318.     usermessage.Hook( "playurl", function( um )
  319.    
  320.         local url = um:ReadString()
  321.         local volume = um:ReadLong() / 100
  322.         local isEOR = um:ReadBool()
  323.        
  324.         if isEOR == false and GetConVar( "ttt_eor_music_enabled" ):GetInt() == 0 then
  325.             return
  326.         end
  327.        
  328.         local ply = LocalPlayer()
  329.        
  330.         if ply.channel and IsValid( ply.channel ) then
  331.             ply.channel:Stop()
  332.         end
  333.        
  334.         sound.PlayURL( url, "", function( station )
  335.             if station and IsValid( station ) then
  336.                 station:Play()
  337.                 LocalPlayer().channel = station
  338.                 LocalPlayer().channel:SetVolume(volume)
  339.             end
  340.         end )
  341.        
  342.     end )  
  343.  
  344.     usermessage.Hook( "playvolume", function( um )
  345.    
  346.         local volume = um:ReadLong() / 100
  347.         local ply = LocalPlayer()
  348.        
  349.         if ply.channel and IsValid( ply.channel ) then
  350.             ply.channel:SetVolume(volume)
  351.         end
  352.        
  353.     end )  
  354.    
  355.     usermessage.Hook( "stopurl", function( um )
  356.    
  357.         local ply = LocalPlayer()
  358.        
  359.         if ply.channel and IsValid( ply.channel ) then 
  360.             ply.channel:Stop()         
  361.             chat.AddText( "Sound stopped." )           
  362.         else       
  363.             chat.AddText( "No music playing!" )        
  364.         end
  365.        
  366.     end )  
  367.    
  368.     usermessage.Hook( "SendSongName", function( um )
  369.    
  370.         local name = um:ReadString()
  371.        
  372.         hook.Add( "HUDPaint", "DrawSongName", function()
  373.            
  374.             local width
  375.            
  376.             if string.len( name ) >= 15 then
  377.                 width = 18 * string.len( name )
  378.             else
  379.                 width = 270
  380.             end
  381.            
  382.             draw.WordBox( 8, 5, 5, "Now Playing: " .. name, "Trebuchet24", Color( 0, 0, 0, 100 ), Color( 255, 255, 255, 200 ) )
  383.            
  384.         end )
  385.        
  386.     end )  
  387.    
  388.     usermessage.Hook( "StopHUDPaint", function( um )
  389.    
  390.         hook.Remove( "HUDPaint", "DrawSongName" )
  391.        
  392.     end )
  393.    
  394.     usermessage.Hook( "stop_preround", function( um )
  395.        
  396.         if GetConVar( "ttt_eor_music_enabled" ):GetInt() == 0 then
  397.             return
  398.         end
  399.        
  400.         local ply = LocalPlayer()
  401.        
  402.         if ply.channel and IsValid( ply.channel ) then
  403.             ply.channel:Stop()
  404.         end
  405.        
  406.     end )
  407.    
  408.     usermessage.Hook( "EnterInfo", function()
  409.    
  410.         local name = ""
  411.         local url = ""
  412.        
  413.         Derma_StringRequest(
  414.             "Request Song",
  415.             "Enter the artist and song title",
  416.             "",
  417.            
  418.             function( text )
  419.            
  420.                 name = text
  421.                
  422.                 if text:len() >= 10 then
  423.                
  424.                     Derma_StringRequest(
  425.                         "Request Song",
  426.                         "Enter the .mp3 URL of the song",
  427.                         "",
  428.                        
  429.                         function( text2 )
  430.                        
  431.                             if string.sub( text2, 1, 4 ) == "http" then
  432.                            
  433.                                 url = text2
  434.                                
  435.                                 net.Start( "SendQueueInfo" )
  436.                                     net.WriteString( name )
  437.                                     net.WriteString( url )
  438.                                 net.SendToServer()
  439.                                
  440.                                 net.Start( "SendCooldownInfo" )
  441.                                 net.SendToServer()
  442.                                
  443.                             else
  444.                                 chat.AddText( "Invalid URL!" )
  445.                             end
  446.                            
  447.                         end,
  448.                        
  449.                         function()
  450.                             chat.AddText( "Song Queue Canceled." )
  451.                         end,
  452.                         "Finish"
  453.                        
  454.                     )
  455.                
  456.                 else
  457.                     chat.AddText( "This text must be ten or more characters." )
  458.                 end
  459.                
  460.             end,
  461.            
  462.             function()
  463.                 chat.AddText( "Song Queue Canceled." )
  464.             end,
  465.             "Next"
  466.         )
  467.        
  468.     end )
  469.    
  470.     usermessage.Hook( "open_endround_menu", function() 
  471.    
  472.         local main = vgui.Create( "DFrame" )   
  473.    
  474.         main:SetPos( 50,50 )
  475.         main:SetSize( 700, 500 )
  476.         main:SetTitle( "End Round Music Menu" )
  477.         main:SetVisible( true )
  478.         main:SetDraggable( true )
  479.         main:ShowCloseButton( true )
  480.         main:MakePopup()
  481.         main:Center()
  482.        
  483.         local PropertySheet = vgui.Create( "DPropertySheet", main )
  484.             PropertySheet:SetPos( 0, 25 )
  485.             PropertySheet:SetSize( 700, 475 )          
  486.            
  487.         local ulist = vgui.Create( "DListView", PropertySheet )
  488.             ulist:SetPos( 4, 27 )
  489.             ulist:SetSize( 692, 469 )
  490.             ulist:SetMultiSelect( false )
  491.             ulist:AddColumn( "Type" ):SetMaxWidth( 40 )
  492.             ulist:AddColumn( "Song Title" ):SetMaxWidth( 275 )
  493.             ulist:AddColumn( "URL" )       
  494.            
  495.                 net.Start( "RequestTables" )
  496.                 net.SendToServer()
  497.                
  498.                 net.Receive( "RequestTablesCallback", function()
  499.                
  500.                     local innowinsound = net.ReadTable()
  501.                     local traitorwinsound = net.ReadTable()
  502.                     local timelimitsound = net.ReadTable()
  503.                     local extrasound = net.ReadTable()
  504.                     ulist:Clear()
  505.                    
  506.                     for k, v in ipairs( innowinsound ) do
  507.                         ulist:AddLine( "Inno", v[ 2 ], v[ 1 ] )
  508.                     end
  509.                    
  510.                     for k, v in ipairs( traitorwinsound ) do
  511.                         ulist:AddLine( "Trator", v[ 2 ], v[ 1 ] )
  512.                     end
  513.                    
  514.                     for k, v in ipairs( timelimitsound ) do
  515.                         ulist:AddLine( "Time", v[ 2 ], v[ 1 ] )
  516.                     end
  517.                    
  518.                     if table.Count( extrasound ) > 0 then                  
  519.                         for k, v in ipairs( extrasound ) do
  520.                             ulist:AddLine( "Extra", v[ 2 ], v[ 1 ] )
  521.                         end
  522.                     end
  523.                    
  524.                 end )
  525.                
  526.             ulist.OnRowRightClick = function( main, line ) 
  527.            
  528.                 local menu = DermaMenu()
  529.                
  530.                     menu:AddOption( "Play for all", function()
  531.                         RunConsoleCommand( "ulx", "playurl", ulist:GetLine( line ):GetValue( 3 ) )
  532.                     end ):SetIcon( "icon16/control_play_blue.png" )    
  533.                    
  534.                     menu:AddOption( "Play for self", function()
  535.                         RunConsoleCommand( "ulx", "playurlcl" , ulist:GetLine( line ):GetValue( 3 ) )
  536.                     end ):SetIcon( "icon16/control_play.png")  
  537.                    
  538.                     menu:AddOption( "Stop all sounds", function()
  539.                         RunConsoleCommand( "ulx", "stopurl" )                  
  540.                     end ):SetIcon( "icon16/control_stop_blue.png" )    
  541.                    
  542.                     menu:AddOption( "Stop sounds for self", function()
  543.                    
  544.                         local ply = LocalPlayer()
  545.                        
  546.                         if ply.channel and IsValid( ply.channel ) then
  547.                             ply.channel:Stop()
  548.                             chat.AddText( "Sound stopped." )
  549.                         else
  550.                             chat.AddText( "No music playing!" )
  551.                         end
  552.                        
  553.                     end ):SetIcon("icon16/control_stop.png")   
  554.  
  555.                     menu:AddOption( "Queue Song", function()
  556.                    
  557.                         if ULib.ucl.query( LocalPlayer(), "ulx queuesong" ) then
  558.                             net.Start( "SendQueueInfo" )
  559.                                 net.WriteString( ulist:GetLine( line ):GetValue( 2 ) )
  560.                                 net.WriteString( ulist:GetLine( line ):GetValue( 3 ) )
  561.                             net.SendToServer()
  562.                            
  563.                             net.Start( "SendCooldownInfo" )
  564.                             net.SendToServer()
  565.                         else
  566.                             chat.AddText( "You don't have access to this command!" )
  567.                         end
  568.                        
  569.                     end ):SetIcon( "icon16/table_row_insert.png" )
  570.                    
  571.                 menu:Open()
  572.                
  573.             end
  574.            
  575.         PropertySheet:AddSheet( "Music", ulist, "icon16/music.png", false, false, "Show all songs in the webserver" )  
  576.        
  577.         local queuetab = vgui.Create( "DPanel", PropertySheet )
  578.        
  579.             queuetab:SetPos( 4, 27 )
  580.             queuetab:SetSize( 692, 469 )       
  581.        
  582.         local queue = vgui.Create( "DListView", queuetab )
  583.        
  584.             queue:SetPos( 4, 4 )
  585.             queue:SetSize( 572, 431 )
  586.             queue:SetMultiSelect( false )
  587.             queue:AddColumn( "User" )
  588.             queue:AddColumn( "Song Title" )
  589.             queue:AddColumn( "URL" )           
  590.             queue:SetSortable( false )
  591.            
  592.                 net.Start( "RequestQueue" )
  593.                 net.SendToServer()
  594.                
  595.                 net.Receive( "RequestQueueCallback", function()
  596.                
  597.                     local queuetab = net.ReadTable()
  598.                     queue:Clear()
  599.                    
  600.                     for k, v in ipairs( queuetab ) do
  601.                         queue:AddLine( v[ 1 ], v[ 2 ], v[ 3 ] )
  602.                     end
  603.                    
  604.                 end )
  605.                
  606.             queue.OnRowRightClick = function( main, line, number ) 
  607.            
  608.                 local menu = DermaMenu()
  609.                
  610.                     menu:AddOption( "Play for all", function()
  611.                         RunConsoleCommand( "ulx", "playurl", queue:GetLine( line ):GetValue( 3 ) )
  612.                     end ):SetIcon( "icon16/control_play_blue.png" )
  613.                    
  614.                     menu:AddOption( "Play for self", function()
  615.                         RunConsoleCommand( "ulx", "playurlcl", queue:GetLine( line ):GetValue( 3 ) )
  616.                     end ):SetIcon( "icon16/control_play.png" ) 
  617.                    
  618.                     menu:AddOption( "Remove", function()
  619.                    
  620.                         net.Start( "Queue_Remove" )
  621.                             net.WriteString( queue:GetLine( line ):GetValue( 2 ) )
  622.                             net.WriteDouble( tonumber( queue:GetSelectedLine( number ) ) )
  623.                         net.SendToServer()
  624.                        
  625.                         net.Start( "RequestQueue" )
  626.                         net.SendToServer()
  627.                        
  628.                         net.Receive( "RequestQueueCallback", function()
  629.                        
  630.                             local queuetab = net.ReadTable()
  631.                            
  632.                             queue:Clear()
  633.                            
  634.                             for k, v in ipairs( queuetab ) do
  635.                                 queue:AddLine( v[ 1 ], v[ 2 ], v[ 3 ] )
  636.                             end
  637.                            
  638.                         end )
  639.                        
  640.                     end ):SetIcon( "icon16/table_row_delete.png" )
  641.                    
  642.                 menu:Open()    
  643.                
  644.             end    
  645.  
  646.             local browse = vgui.Create( "DButton", queuetab )
  647.                 browse:SetSize( 100, 30 )
  648.                 browse:SetPos( 580, 4 )
  649.                 browse:SetText( "Browse .mp3s" )
  650.                 browse.DoClick = function( browse )
  651.                     gui.OpenURL( "http://mp3skull.com/" )
  652.             end        
  653.  
  654.             local q = vgui.Create( "DButton", queuetab )
  655.                 q:SetSize( 100, 30 )
  656.                 q:SetPos( 580, 40 )
  657.                 q:SetText( "Queue a song" )
  658.                 q.DoClick = function( q )
  659.                     RunConsoleCommand( "ulx", "queuesong" )
  660.             end
  661.            
  662.         PropertySheet:AddSheet( "Queue", queuetab, "icon16/table_go.png", false, false, "View Queued Songs" )
  663.        
  664.         local radio = vgui.Create( "DPanel", PropertySheet )
  665.        
  666.             radio:SetPos( 4, 27 )
  667.             radio:SetSize( 692, 469 )      
  668.            
  669.         local stations = vgui.Create( "DListView", radio )
  670.            
  671.             stations:SetPos( 4, 4 )
  672.             stations:SetSize( 572, 431 )
  673.             stations:SetMultiSelect( false )
  674.             stations:AddColumn( "Station" )    
  675.            
  676.                 local toAdd = file.Read( "radio/stations.txt", "DATA" )
  677.                
  678.                 if toAdd:len() > 0 then
  679.                
  680.                     local tab = string.Explode( "\n", toAdd )
  681.  
  682.                     for k, v in ipairs( tab ) do
  683.                         if v ~= "" then
  684.                             stations:AddLine( v )
  685.                         end
  686.                     end
  687.  
  688.                 end
  689.                
  690.             stations.OnRowRightClick = function( main, line, number )
  691.            
  692.                 local menu = DermaMenu()
  693.                
  694.                     menu:AddOption( "Start Radio", function()
  695.                         RunConsoleCommand( "ulx", "playurlcl", string.sub( stations:GetLine( line ):GetValue( 1 ), string.find( stations:GetLine( line ):GetValue( 1 ), "|" ) + 2 ) )
  696.                     end ):SetIcon( "icon16/control_play.png" ) 
  697.                    
  698.                     menu:AddOption( "Stop Radio", function()
  699.                         RunConsoleCommand( "ulx", "stopurlcl" )
  700.                     end ):SetIcon( "icon16/control_stop.png" )
  701.                    
  702.                     menu:AddOption( "Copy URL", function()
  703.                         SetClipboardText( string.sub( stations:GetLine( line ):GetValue( 1 ), string.find( stations:GetLine( line ):GetValue( 1 ), "|" ) + 2 ) )
  704.                         chat.AddText( "URL Copied." )
  705.                     end ):SetIcon( "icon16/tag_blue_edit.png" )
  706.                    
  707.                     menu:AddOption( "Remove Station", function()
  708.                        
  709.                         chat.AddText( "Station \"" .. string.sub( stations:GetLine( line ):GetValue( 1 ), 1, string.find( stations:GetLine( line ):GetValue( 1 ), "|" ) - 2 ) .. "\" removed." )
  710.                         stations:RemoveLine( line )
  711.                        
  712.                         local newTab2 = {}
  713.                        
  714.                         for k, v in pairs( stations:GetLines() ) do
  715.                             local url = v:GetValue( 1 )
  716.                             table.insert( newTab2, url )
  717.                         end
  718.                        
  719.                         file.Delete( "radio/stations.txt" )
  720.                         file.Write( "radio/stations.txt" )
  721.                        
  722.                         for k, v in pairs( newTab2 ) do
  723.                             file.Append( "radio/stations.txt", v .. "\n" )
  724.                         end
  725.                        
  726.                         stations:Clear()
  727.                        
  728.                         local toAdd = file.Read( "radio/stations.txt", "DATA" )
  729.                
  730.                         if toAdd:len() > 0 then
  731.                        
  732.                             local tab = string.Explode( "\n", toAdd )
  733.  
  734.                             for k, v in ipairs( tab ) do
  735.                                 stations:AddLine( v )
  736.                             end
  737.                        
  738.                         end
  739.                        
  740.                     end ):SetIcon( "icon16/table_row_delete.png" )
  741.                    
  742.                 menu:Open()    
  743.                
  744.             end    
  745.  
  746.         local browse = vgui.Create( "DButton", radio )
  747.             browse:SetSize( 100, 30 )
  748.             browse:SetPos( 580, 4 )
  749.             browse:SetText( "Browse Stations" )
  750.             browse.DoClick = function( browse )
  751.                 gui.OpenURL( "http://www.shoutcast.com/" )
  752.         end
  753.        
  754.         local add = vgui.Create( "DButton", radio )
  755.             add:SetSize( 100, 30 )
  756.             add:SetPos( 580, 40 )
  757.             add:SetText( "Add Station by URL" )
  758.             add.DoClick = function( add )
  759.            
  760.                 local name = ""
  761.                
  762.                 Derma_StringRequest(
  763.                     "Add Station",
  764.                     "Name this station",
  765.                     "",
  766.  
  767.                     function( text )   
  768.                    
  769.                         name = text
  770.                        
  771.                         Derma_StringRequest(
  772.                             "Add Station",
  773.                             "Enter the URL for this station",
  774.                             "",
  775.  
  776.                             function( text2 )  
  777.                            
  778.                                 file.Append( "radio/stations.txt", text .. " | " .. text2 .. "\n" )
  779.                                
  780.                                 stations:AddLine( text:Trim() .. " | " .. text2:Trim() )
  781.                                
  782.                                 local newTab = {}
  783.                                
  784.                                 for i = 1, #stations:GetLines() do
  785.                                     local url = stations:GetLine( i ):GetValue( 1 )
  786.                                     table.insert( newTab, url )
  787.                                 end
  788.                                
  789.                                 file.Delete( "radio/stations.txt" )
  790.                                 file.Write( "radio/stations.txt" )
  791.                                
  792.                                 for k, v in pairs( newTab ) do
  793.                                     file.Append( "radio/stations.txt", v .. "\n" )
  794.                                 end
  795.                                
  796.                             end,
  797.                            
  798.                             function()
  799.                                 chat.AddText( "Station Add Canceled." )
  800.                             end,
  801.                             "Add"
  802.                            
  803.                         )
  804.                        
  805.                     end,
  806.                    
  807.                     function()
  808.                             chat.AddText( "Station Add Canceled." )
  809.                         end,
  810.                     "Next"
  811.                    
  812.                 )
  813.                
  814.         end
  815.        
  816.         PropertySheet:AddSheet( "Radio", radio, "icon16/sound.png", false, false, "View Radio Stations" )
  817.        
  818.     end )
  819.    
  820.     local function AddSettings( dtabs )
  821.         local musicsettings = vgui.Create( "DPanelList", dtabs )
  822.         musicsettings:StretchToParent( 0, 0, padding, 0 )
  823.         musicsettings:EnableVerticalScrollbar( true )
  824.         musicsettings:SetPadding( 10 )
  825.         musicsettings:SetSpacing( 10 )
  826.  
  827.         local setting = nil
  828.         local Music = vgui.Create( "DForm", musicsettings )
  829.         Music:SetName( "End Round Music" )
  830.        
  831.         setting = Music:CheckBox( "Enable End Round Music", "ttt_eor_music_enabled" )
  832.         setting:SetTooltip( "Disable EOR Music" )
  833.  
  834.         musicsettings:AddItem( Music )
  835.  
  836.         dtabs:AddSheet( "EOR Music", musicsettings, "icon16/music.png", false, false, "End Round Music Settings" )
  837.     end
  838.     hook.Add( "TTTSettingsTabs", "AddSettings", AddSettings )
  839.    
  840. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement