Jump to content

Mute sounds while playing..


Newbie

Recommended Posts

To mute radio:

 function makeRadioStayOff() 
  setRadioChannel(0) 
  cancelEvent() 
end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), makeRadioStayOff) 
addEventHandler("onClientPlayerRadioSwitch", getRootElement(), makeRadioStayOff) 

Link to comment
To mute radio:
 function makeRadioStayOff() 
  setRadioChannel(0) 
  cancelEvent() 
end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), makeRadioStayOff) 
addEventHandler("onClientPlayerRadioSwitch", getRootElement(), makeRadioStayOff) 

Thanks for your help, but that's a radio made by .pls streams

So, okay. Here's my sound (this should hear loudest)

addEvent("15s",true) 
addEventHandler("15s",getRootElement(), 
function () 
local sound1 = playSound("data/files/wreckingball.ogg") 
setSoundVolume(sound1, 1) 
end) 

And theres way to make him loudest, set all other sounds volume to 0.5 and keep my sounds as 1.

function muteSounds () 
for i, sound in ipairs(getElementsByType("sound")) do 
setSoundVolume(sound, 0.5) 
if sound == sound1 then 
setSoundVolume(sound1, 1) 
end 
end 
end 
  
addEventHandler("onClientResourceStart", root, 
function () 
setTimer(muteSounds, 50, 0) --To make sure that the sound is already playing 
end) 

It seems to be playing my sound at 0.5

Link to comment
local previousVolumes = {} 
function muteSounds(except, eVol, oVol) 
  --sound except — Which sound should stay un-muted 
  --float eVol — Volume of the 'except,' how loud the un-muted sound should be 
  --float oVol — How loud should all other sounds be (this should be lower than eVol, in your case) 
  for k, v in ipairs(getElementsByType("sound")) do 
    previousVolumes[v] = getSoundVolume(v) --Remember the previous volume so that you can return it when done 
    if v == except then 
      setSoundVolume(v, eVol) 
    else 
      setSoundVolume(v, oVol) 
    end 
  end 
end 
  
function unmuteSounds() 
  for k, v in pairs(previousVolumes) do 
    if isElement(k) then --Check if the sound element still exists 
      setSoundVolume(k, v) --Reset the sound back to normal 
    end 
  end 
  previousVolumes = {} --Reset the table 
end 

Link to comment

Thanks Tasty!

I've did it in my way, tested,working fine:

addEvent("15s",true) 
addEventHandler("15s",getRootElement(), 
function () 
for i, sound in ipairs(getElementsByType("sound")) do 
setSoundVolume(sound, 0.1) 
local sound1 = playSound("data/files/wreckingball.ogg") 
setSoundVolume(sound1, 1) 
local soundLength = getSoundLength(sound1) 
setTimer(unmuteSounds, soundLength*1000, 1) 
end 
end) 
----- 
  
function unmuteSounds () 
for i, sound in ipairs(getElementsByType("sound")) do 
setSoundVolume(sound, 1) 
end 
end 
  

Link to comment
He wanted to mute MTA sound elements (custom radio through .pls) whilst something else plays.
The thing is that i have to mute map songs or custom radio. Somehow.. StopSound Wouldn't do this i think

Well , if i understood good he want to mute MTA/GTA map/background sounds :)

Link to comment
The thing is that i have to mute map songs [map songs as in songs played by race map files or similar] or custom radio. Somehow.. StopSound Wouldn't do this i think

Thanks for your help, but that's a radio made by .pls streams

louder than any other server sounds.
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...