Jump to content

[Help/Advice] Server Radio Script


Ma5ter

Recommended Posts

Well, i've been very confused lately trying to script this. The issue i've been having was getting my sound to be heard by every player and done through a link, for example "http://music.layer07.com/LinkinPark-InTheEnd.mp3" a direct hotlink. Basically all in all "/radio (link)" and then it plays the provided link. Help or advice would be appreciated.

Btw this is the code I tried to use :

function play() 
local x,y,z = getElementPosition(getElementsByType("player"))  
local sound = playSound3D("http://clients.savouryprojects.com/zauntourage/audio_player/track2.mp3",x, y, z, true) 
    setSoundMaxDistance (sound, 800) 
    end 
 addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource () ), play ) 
  

Link to comment

server:

  
function play(player,cmd,link) 
triggerClientEvent("onSoundPlayRequest",root,link) 
end 
addCommandHandler("playfromurl",play) 
  
--client 
  
addEvent("onSoundPlayRequest",true) 
  
function play(link) 
playSound(link) 
end 
addEventHandler("onSoundPlayRequest",root,play) 
  

Link to comment

You'll need to trigger a client-side event for all players via the server. That event in return plays the audio.

Read about these;

triggerClientEvent 
addEvent 

As for the command, you simply add an argument to the function attached to the command handler.

-- Server Side [usage: /stream [url=http://www.url.com]http://www.url.com[/url]] 
function exampleCommand_Handler(thePlayer, theCMD, theURL) 
    if(theURL ~= nil and theURL ~= "") then 
        outputChatBox(tostring(theURL)) 
        -- Trigger a Client event for all players, and pass along the URL with it. 
        triggerClientEvent("eventNameHere", getRootElement(), thePlayer, theURL) 
    end 
end 
addCommandHandler("Stream", exampleCommand_Handler, false, false) 
  
  
-- Client Side 
function examplePlayAudio_Handler(theStreamer, theURL) 
    if(getElementType(theStreamer == "player") then 
        if(theUrl ~= nil and theUrl ~= "") then 
            theSound = playSound(theURL) -- Play the sound and store the element in a variable. 
            outputChatBox(getPlayerName(theStreamer).." is now Streaming!") 
        end 
    end 
end 
addEvent("eventNameHere", true) 
addEventHandler("eventNameHere", getRootElement(), examplePlayAudio_Handler) 

(I'm at work currently so the code provided above is not tested and might contain some typo or whatnot, but should give you an idea of how it works.)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...