Jump to content

Command to play a sound


myonlake

Recommended Posts

Hello,

As you know, using addCommandHandler with playSound3D works just fine, BUT the problem is that others cannot hear it, what should I do else on the below script to make it work for everybody, not just for myself.

-- Funny song 
function playSong1() 
    local song1 = playSound3D("sounds/cool.mp3", -1491, 763, 9, false) 
     
    setSoundVolume(song1, 0.7) 
    setSoundMaxDistance(song1, 100) 
end 
addCommandHandler("cool", playSong1) 
 

I have tried timers too but they didn't work either.

Edited by myonlake
Link to comment

hmmm try this :D

function song1 ( player, command ) 
    local sound = playSound("sounds/cool.mp3") -Play the sound 
    setSoundVolume(sound, 1.0) -The Volume 
end 
addCommandHandler ( "song1", song1 ) 
  

Edited by Guest
Link to comment
you need the server to tell all the clients what to do. so the same code would be executed on all clients, not just one who typed the command.

there is an event system for that.

Heh! Thank you! :P

hmmm try this :D
function song1 ( player, command ) 
    local sound = playSound("sounds/cool.mp3") 
    setSoundVolume(sound, 1.0) 
end 
addCommandHandler ( "song1", song1 ) 
  

That would not work... setSoundMaxDistance is the distance of the sound, it doesn't effect, because I can hear the sound normally, others don't. By the events I did it ;)

Link to comment

Server side

addCommandHandler("cool", 
function () 
triggerClientEvent ( root, "StartSong", root ) 
end) 

Client Side

function Sound () 
    local song1 = playSound3D("sounds/cool.mp3", -1491, 763, 9, false) 
    setSoundVolume(song1, 0.7) 
    setSoundMaxDistance(song1, 100) 
end 
addEvent( "StartSong", true ) 
addEventHandler( "StartSong", getRootElement(), Sound ) 

Link to comment
Server side
addCommandHandler("cool", 
function () 
triggerClientEvent ( root, "StartSong", root ) 
end) 

Client Side

function Sound () 
    local song1 = playSound3D("sounds/cool.mp3", -1491, 763, 9, false) 
    setSoundVolume(song1, 0.7) 
    setSoundMaxDistance(song1, 100) 
end 
addEvent( "StartSong", true ) 
addEventHandler( "StartSong", getRootElement(), Sound ) 

Problem was already solved if you didn't know :/

  • Like 1
Link to comment
  • 6 years later...

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