Jump to content

Beach speaker help


Captain Cody

Recommended Posts

Posted

How can i make it so on command I can set the volume and with another command set the distance? And If it wouldnt hurt how would I make it so I can change radio station on command "/setstationbeach 1, 2,3 or 4

addEventHandler( 'onClientResourceStart', resourceRoot, 
    function( ) 
        local uSound = playSound3D( 'http://www.181.fm/asx.php?station=181-eagle', 484.724609375, -1830.3310546875, 5.415961265564)  
        setSoundMaxDistance( uSound, 110 ) 
  
    end 
) 

the wiki atricals I found I couldn't find a think on how to do this

And if its too much Im mostly trying to find out how to change the station

Wolf Inc Discord

Youtube channel
Github

Posted
  
addEventHandler( 'onClientResourceStart', resourceRoot, 
    function( ) 
        uSound = playSound3D( 'http://www.181.fm/asx.php?station=181-eagle', 484.724609375, -1830.3310546875, 5.415961265564) 
        setSoundMaxDistance( uSound, 110 ) 
  
    end 
) 
  
addCommandHandler("setsoundistance", function(command, distance) 
      local distance = tonumber(distance) 
      if not tonumber(tostring(distance)) then return end 
      if uSound then 
       setSoundMaxDistance(uSound, tonumber(tostring(distance))       
end 
end 
) 
  

Posted
  
  
addEventHandler( 'onClientResourceStart', resourceRoot, 
    function( ) 
        uSound = playSound3D( 'http://www.181.fm/asx.php?station=181-eagle', 484.724609375, -1830.3310546875, 5.415961265564) 
        setSoundMaxDistance( uSound, 110 ) 
  
    end 
) 
  
addCommandHandler("setsoundistance", function(command, distance) 
      local distance = tonumber(distance) 
      if not tonumber(tostring(distance)) then return end 
      if uSound then 
       setSoundMaxDistance(uSound, tonumber(tostring(distance))       
end 
end 
) 
  
addCommandHandler("setsound", function(command, soundURL) 
     if uSound then stopSound(uSound) end 
     backup = uSound 
     destroyElement(uSound) 
     uSound = nil 
     uSound = playSound3D(tostring(soundURL), 484.724609375, -1830.3310546875, 5.415961265564) 
      if uSound then 
       destroyElement(backup) 
       backup = nil 
       outputChatBox('Sound was successfully changed!') 
      else 
      uSound = nil 
      uSound = backup 
      destroyElement(backup) 
      backup = nil 
  end 
end 
) 
  

Posted
What I mean is there anyway to do it from a list of urls that I set in the lua file?

1. Make a GUI using something like GUIEditor.

2. Create a table looking something like this,

urls = { 
    {"www.youradress.com/song.mp3"}, 
} 

3. Get the data from that table,

for index, data in ipairs(urls) do 
   url = data[1] 
   -- Do something with that data, ex. 
   outputChatBox(data[1]) -- Outputs the url into the chatbox (not needed). 
end 

4. Set that data into a gridlist or something of your choice using something like this,

guiCreateGridList 
guiGridListAddColumn 
guiGridListAddRow 
guiGridListSetItemText  

Should turn into something like this (not tested, only an example)

window = guiCreateWindow(0, 0, 0, 0, "Example", false) 
gridlist = guiCreateGridList(0, 0, 0, 0, false, window) 
column = guiGridListAddColumn(gridlist, "URLs", 1) 
  
urls = { 
    {"http://www.181.fm/asx.php?station=181-eagle"}, 
} 
  
for index, data in ipairs(urls) do 
    local row = guiGridListAddRow(gridlist) 
    guiGridListSetItemText(gridlist, row, column, index, false, false) 
end 

And then ofcourse you would have to get that URL from the gridlist and play it using playSound or playSound3D.

Posted
The help was solved, I made it yesterday.

I think cody should've posted it here.

What I mean is there anyway to do it from a list of urls that I set in the lua file?

You posted a code where you could choose an URL directly from the command. I posted a little guide how

to do it with a GUI and a table.

Posted
@Anubav: You don't need to use tostring if you're converting it into a number.

(facepalm). What if a player did: /setsoundistance "5"

:o!

  • Moderators
Posted
@Anubav: You don't need to use tostring if you're converting it into a number.

(facepalm). What if a player did: /setsoundistance "5"

:o!

Then it still will be a nil.

  
outputChatBox  = outputChatBox or print -- For lua demo utility. 
  
outputChatBox(tonumber(tostring('"5"'))) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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...