Advertisement
Guest User

Untitled

a guest
Sep 4th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.85 KB | None | 0 0
  1. AddCSLuaFile()
  2. local receiving_side = CLIENT
  3. local NetworkStreamName = "RadioStreamName"
  4. local playing = false
  5. function string.starts(String,Start)
  6.    return string.sub(String,1,string.len(Start))==Start
  7. end
  8.  
  9. function string.ends(String,End)
  10.    return End=='' or string.sub(String,-string.len(End))==End
  11. end
  12.  
  13. function broadcast(message)
  14.     for count, ply in pairs( player.GetAll()) do
  15.          ply:ChatPrint(message)
  16.     end
  17. end
  18.  
  19. function string.split(s, split)
  20.     list = {}
  21.     index = 1
  22.         for value in string.gmatch(s, split) do
  23.             list [index] = value
  24.             index = index + 1    
  25.         end
  26.     return list
  27. end
  28.  
  29. function trim(s)
  30.   return (s:gsub("^%s*(.-)%s*$", "%1"))
  31. end
  32. if( receiving_side) then
  33.     local stop = false
  34.     local volume = 100
  35.     //Setting up a local "channel" so scripts outside of the sound function can access the channel
  36.     local chan = nil
  37.     net.Receive(NetworkStreamName, function (len)
  38.         local command = net.ReadString()
  39.         local args = string.split(command, "%S+")
  40.         local volume = 50
  41.         local stop = false
  42.         local resume = false
  43.         local pause = false
  44.         local play = true
  45.         //Runs when client wants to set the volume
  46.         if string.starts(command, "setvolume") then
  47.             PrintTable(args)
  48.             volume = args[2]
  49.             chan:SetVolume(tonumber(args[2]))
  50.             MsgAll("Volume command recived\n")
  51.         end
  52.        
  53.         //This stuff is deprecated
  54.         /*
  55.         // Pauses the stream when "use" is used
  56.         if string.starts(command, "pause") then
  57.             pause = true
  58.             chan:Pause()
  59.             MsgAll("Pause command recived\n")
  60.         end
  61.         // Continues the stream on resume
  62.        
  63.         if string.starts(command, "resume") then
  64.             MsgAll("Resume command recived\n")
  65.             resume = true
  66.             chan:Pause()
  67.         end */
  68.  
  69.         //Stops the stream when stop is received
  70.         if string.starts(command, "stop") then
  71.             print("Stopping channel!\n")
  72.             chan:Stop()
  73.             play = false
  74.         end
  75.        
  76.  
  77.         // This stuff only ever gets called when the client wants to "play" something
  78.         if string.starts(command, "play") then
  79.             local URL = args[2]
  80.             sound.PlayURL(URL, "play", function(channel)
  81.                 //asigning the channel to "chan" which was defined at the start clientside stuff
  82.                 chan = channel
  83.                 print("Playing " .. URL .. "!")
  84.                 playing = true
  85.                 chan:SetVolume(volume)
  86.                 print("Set volume to " .. volume)
  87.                 chan:Play()
  88.                
  89.                 if not chan:IsValid() then
  90.                     print("Song over!\n")
  91.                     broadcast("Song over!")
  92.                     playing = false
  93.                 end
  94.             end)
  95.         end
  96.     end)
  97. else
  98.     util.AddNetworkString(NetworkStreamName)
  99.     function process(player, strText, bTeamOnly, bPlayerIsDead)
  100.         if string.starts(string.lower(strText), "!say") then
  101.             local args = string.split(strText, "%S+")
  102.             local message = "";
  103.             for i=2,#args do
  104.                 message = message .. args[i] .. " "
  105.             end
  106.             broadcast(trim(message))
  107.             return false
  108.         end
  109.         if string.starts(string.lower(strText), "!music_play") then
  110.             local args = string.split(strText, "%S+");
  111.             if(#args == 2) then
  112.                 local stream = args[2]
  113.                 net.Start(NetworkStreamName)
  114.                 net.WriteString("play " .. args[2])
  115.                 net.Broadcast()
  116.             end
  117.         end
  118.         if string.starts(string.lower(strText), "!music_volume") then
  119.             local args = string.split(strText, "%S+");
  120.             if(#args == 2) then
  121.                 local volume = args[2]
  122.                 net.Start(NetworkStreamName)
  123.                 net.WriteString("setvolume " .. args[2])
  124.                 net.Broadcast()
  125.             end
  126.         end
  127.  
  128.         // This does the same as restarting the song. Just use music_play
  129.         /*if string.starts(string.lower(strText), "!music_resume") then
  130.             local args = string.split(strText, "%S+");     
  131.                 net.Start(NetworkStreamName)
  132.                 net.WriteString("resume " .. args[2])
  133.                 net.Broadcast()
  134.         end*/
  135.         // Same as stopping the song? Use music_stop
  136.         if string.starts(string.lower(strText), "!music_pause") then
  137.                 net.Start(NetworkStreamName)
  138.                 net.WriteString("pause ")
  139.                 net.Broadcast()
  140.         end
  141.         return true
  142.     end
  143.     hook.Add("PlayerSay", "TestHook", process)
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement