micheal1230 Posted October 13, 2012 Posted October 13, 2012 When you press 'n' you get a siren sound, but when you press 'n' again you get a different siren sound but the second sound wont play! local sounds = { } -- Bind Keys required function bindKeys(res) bindKey("n", "down", toggleSirens) for key, value in ipairs(getElementsByType("vehicle")) do if isElementStreamedIn(value) then if getElementData(value, "lspd:siren") then sounds[value] = playSound3D("siren.wav", 0, 0, 0, true) attachElements( sounds[value], value ) setSoundVolume(sounds[value], 0.6) setSoundMaxDistance(sounds[value], 45) setElementDimension(sounds[value], getElementDimension(value)) setElementInterior(sounds[value], getElementInterior(value)) end end end end addEventHandler("onClientResourceStart", getResourceRootElement(), bindKeys) function toggleSirens() local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) if (theVehicle) then if getElementData(theVehicle, "lspd:siren") then triggerServerEvent("lspd:setSirenState", theVehicle, false) elseif (exports.global:hasItem(theVehicle, 85)) then triggerServerEvent("lspd:setSirenState", theVehicle, true) end end end addCommandHandler("togglecarsirens", toggleSirens, false) function streamIn() if getElementType( source ) == "vehicle" and getElementData( source, "lspd:siren" ) and not sounds[ source ] then sounds[source] = playSound3D("siren.wav", 0, 0, 0, true) attachElements( sounds[source], source ) setSoundVolume(sounds[source], 0.6) setSoundMaxDistance(sounds[source], 45) setElementDimension(sounds[source], getElementDimension(source)) setElementInterior(sounds[source], getElementInterior(source)) end end addEventHandler("onClientElementStreamIn", getRootElement(), streamIn) function streamOut() if getElementType( source ) == "vehicle" and sounds[source] then destroyElement( sounds[ source ] ) sounds[ source ] = nil end end addEventHandler("onClientElementStreamOut", getRootElement(), streamOut) function updateSirens( name ) if name == "lspd:siren" and isElementStreamedIn( source ) and getElementType( source ) == "vehicle" then local attached = getAttachedElements( source ) if attached then for key, value in ipairs( attached ) do if getElementType( value ) == "sound" and value ~= sounds[ source ] then destroyElement( value ) end end end if not getElementData( source, name ) then if sounds[ source ] then destroyElement( sounds[ source ] ) sounds[ source ] = nil end else if not sounds[ source ] then sounds[source] = playSound3D("siren.wav", 0, 0, 0, true) attachElements( sounds[source], source ) setSoundVolume(sounds[source], 0.6) setSoundMaxDistance(sounds[source], 45) setElementDimension(sounds[source], getElementDimension(source)) setElementInterior(sounds[source], getElementInterior(source)) end end end end addEventHandler("onClientElementDataChange", getRootElement(), updateSirens)
Anderl Posted October 14, 2012 Posted October 14, 2012 It won't play because you're only playing it if the sound doesn't exist. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
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