Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile()
- local receiving_side = CLIENT
- local NetworkStreamName = "RadioStreamName"
- local playing = false
- function string.starts(String,Start)
- return string.sub(String,1,string.len(Start))==Start
- end
- function string.ends(String,End)
- return End=='' or string.sub(String,-string.len(End))==End
- end
- function broadcast(message)
- for count, ply in pairs( player.GetAll()) do
- ply:ChatPrint(message)
- end
- end
- function string.split(s, split)
- list = {}
- index = 1
- for value in string.gmatch(s, split) do
- list [index] = value
- index = index + 1
- end
- return list
- end
- function trim(s)
- return (s:gsub("^%s*(.-)%s*$", "%1"))
- end
- if( receiving_side) then
- local stop = false
- local volume = 100
- //Setting up a local "channel" so scripts outside of the sound function can access the channel
- local chan = nil
- net.Receive(NetworkStreamName, function (len)
- local command = net.ReadString()
- local args = string.split(command, "%S+")
- local volume = 50
- local stop = false
- local resume = false
- local pause = false
- local play = true
- //Runs when client wants to set the volume
- if string.starts(command, "setvolume") then
- PrintTable(args)
- volume = args[2]
- chan:SetVolume(tonumber(args[2]))
- MsgAll("Volume command recived\n")
- end
- //This stuff is deprecated
- /*
- // Pauses the stream when "use" is used
- if string.starts(command, "pause") then
- pause = true
- chan:Pause()
- MsgAll("Pause command recived\n")
- end
- // Continues the stream on resume
- if string.starts(command, "resume") then
- MsgAll("Resume command recived\n")
- resume = true
- chan:Pause()
- end */
- //Stops the stream when stop is received
- if string.starts(command, "stop") then
- print("Stopping channel!\n")
- chan:Stop()
- play = false
- end
- // This stuff only ever gets called when the client wants to "play" something
- if string.starts(command, "play") then
- local URL = args[2]
- sound.PlayURL(URL, "play", function(channel)
- //asigning the channel to "chan" which was defined at the start clientside stuff
- chan = channel
- print("Playing " .. URL .. "!")
- playing = true
- chan:SetVolume(volume)
- print("Set volume to " .. volume)
- chan:Play()
- if not chan:IsValid() then
- print("Song over!\n")
- broadcast("Song over!")
- playing = false
- end
- end)
- end
- end)
- else
- util.AddNetworkString(NetworkStreamName)
- function process(player, strText, bTeamOnly, bPlayerIsDead)
- if string.starts(string.lower(strText), "!say") then
- local args = string.split(strText, "%S+")
- local message = "";
- for i=2,#args do
- message = message .. args[i] .. " "
- end
- broadcast(trim(message))
- return false
- end
- if string.starts(string.lower(strText), "!music_play") then
- local args = string.split(strText, "%S+");
- if(#args == 2) then
- local stream = args[2]
- net.Start(NetworkStreamName)
- net.WriteString("play " .. args[2])
- net.Broadcast()
- end
- end
- if string.starts(string.lower(strText), "!music_volume") then
- local args = string.split(strText, "%S+");
- if(#args == 2) then
- local volume = args[2]
- net.Start(NetworkStreamName)
- net.WriteString("setvolume " .. args[2])
- net.Broadcast()
- end
- end
- // This does the same as restarting the song. Just use music_play
- /*if string.starts(string.lower(strText), "!music_resume") then
- local args = string.split(strText, "%S+");
- net.Start(NetworkStreamName)
- net.WriteString("resume " .. args[2])
- net.Broadcast()
- end*/
- // Same as stopping the song? Use music_stop
- if string.starts(string.lower(strText), "!music_pause") then
- net.Start(NetworkStreamName)
- net.WriteString("pause ")
- net.Broadcast()
- end
- return true
- end
- hook.Add("PlayerSay", "TestHook", process)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement