errsousa Posted February 2, 2014 Share Posted February 2, 2014 Hi, So i'm making a map that has a custom song (music.mp3) and at one point in the map i play a custom sound (music2.mp3 - 3seconds). Unfortunately the second sound is not loud enough because of the bg music. So, can someone please provide me a simple script to fade out music.mp3 when music2.mp3 plays and then fade in music.mp3 again? I'm using this script for the custom sound (music2.mp3 -3 seconds). --speedboosts-- function start() SpeedBoost = { createMarker ( -1906.3000488281, -5613.7001953125, 117.30000305176, "corona", 0, 0, 0, 0, 255), } end addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), start ) Multiplier = 1 function SpeedBoost (player) if player ~= getLocalPlayer() then return end if getElementType(player) == "player" then if isPedInVehicle ( player ) then local car = getPedOccupiedVehicle(player) if getVehicleController(car) == player then speedx, speedy, speedz = getElementVelocity ( car ) speedcnx = (speedx*Multiplier) speedcny = (speedy*Multiplier) speedcnz = (speedz*Multiplier) setElementVelocity ( car, speedcnx, speedcny,speedcnz ) sound = playSound("files/liberty.mp3") setSoundVolume(sound, 1) end end end end addEventHandler ( "onClientMarkerHit", getResourceRootElement(getThisResource()), SpeedBoost ) Link to comment
Bonsai Posted February 3, 2014 Share Posted February 3, 2014 Despite the fact that maps with big mp3 files suck, I can't find neither music.mp3 nor music2.mp3 in your script. Just set the volume of that song to zero where you use playSound on the other one. Link to comment
errsousa Posted February 3, 2014 Author Share Posted February 3, 2014 2nd song is in another script. Is it possible to put both in the same script? song 1 starts with map and fades out when song 2 comes in (can be by a cp, a marker, wtv) - song 2 fades out and song 1 comes back again. Link to comment
Gallardo9944 Posted February 3, 2014 Share Posted February 3, 2014 Unstested though. local song = playSound("music3.mp3") -- your song local turn = true -- unfaded by default function startFading() turn = false end function stopFading() turn = true end function renderFade() local sounds = getElementsByType("sound") for i,v in ipairs(sounds) do if not (v == song) then -- if it's not your song then local volume = getSoundVolume(v) if turn == true then volume = volume + 0.03 -- fade in 3% each frame else volume = volume - 0.03 -- fade out 3% each frame end if volume > 1.0 then -- volume can't exceed 100% volume = 1.0 elseif volume < 0.2 then -- your minimal volume volume = 0.2 end setSoundVolume(v,volume) end end end addEventHandler("onClientRender",getRootElement(),renderFade) 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