Ma5ter Posted June 25, 2014 Share Posted June 25, 2014 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
#DRAGON!FIRE Posted June 25, 2014 Share Posted June 25, 2014 u mean u want command like this playSoundUrl Link Link to comment
Ma5ter Posted June 25, 2014 Author Share Posted June 25, 2014 u mean u want command like thisplaySoundUrl Link Yeah pretty much. Link to comment
Arnold-1 Posted June 25, 2014 Share Posted June 25, 2014 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
Dealman Posted June 25, 2014 Share Posted June 25, 2014 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
Ma5ter Posted June 25, 2014 Author Share Posted June 25, 2014 Thank you, the script provided works. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now