Hello, i have a question, what's is not correct in this?
So basicly, on the old script was only one sound, now it's 4.
Something is not correct in server side because, when i put old script with only one sound, it's works, but this not.
Client-side
function setSirenState()
elseif exports.global:hasItem(source, 85) then -- sirens
local curState = getElementData(source, "lspd:siren")
exports.anticheat:changeProtectedElementDataEx(source, "lspd:siren", not curState)
setVehicleSirensOn ( source , not curState )
end
end
addEvent( "lspd:setSirenState", true )
addEventHandler( "lspd:setSirenState", getRootElement(), setSirenState )
function updateSirens( name )
if (name == "lspd:siren" or name == "lspd:extrasiren") 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 sounds[ source ] then
destroyElement( sounds[ source ] )
sounds[ source ] = nil
end
if (getElementData( source, "lspd:siren" ) == 1 and getElementData( source, "lspd:extrasiren" ) == nil) then
sounds[source] = playSound3D("siren.wav", 0, 0, 0, true)
attachElements( sounds[source], source )
setSoundVolume(sounds[source], 0.3)
setSoundMaxDistance(sounds[source], 220)
setSoundMinDistance(sounds[source], 30)
setElementDimension(sounds[source], getElementDimension(source))
setElementInterior(sounds[source], getElementInterior(source))
elseif getElementData( source, "lspd:extrasiren" ) == 2 then
sounds[source] = playSound3D("2.wav", 0, 0, 0, true)
attachElements( sounds[source], source )
setSoundVolume(sounds[source], 0.4)
setSoundMaxDistance(sounds[source], 220)
setSoundMinDistance(sounds[source], 30)
setElementDimension(sounds[source], getElementDimension(source))
setElementInterior(sounds[source], getElementInterior(source))
elseif getElementData( source, "lspd:extrasiren" ) == 3 then
sounds[source] = playSound3D("3.wav", 0, 0, 0, true)
attachElements( sounds[source], source )
setSoundVolume(sounds[source], 0.4)
setSoundMaxDistance(sounds[source], 220)
setSoundMinDistance(sounds[source], 30)
setElementDimension(sounds[source], getElementDimension(source))
setElementInterior(sounds[source], getElementInterior(source))
elseif getElementData( source, "lspd:extrasiren" ) == 4 then
sounds[source] = playSound3D("4.wav", 0, 0, 0, true)
attachElements( sounds[source], source )
setSoundVolume(sounds[source], 0.4)
setSoundMaxDistance(sounds[source], 220)
setSoundMinDistance(sounds[source], 30)
setElementDimension(sounds[source], getElementDimension(source))
setElementInterior(sounds[source], getElementInterior(source))
end
end
end
addEventHandler("onClientElementDataChange", getRootElement(), updateSirens)
server-side
function setSirenState(state)
if state == 1 then
elseif exports.global:hasItem(source, 85) then -- sirens
local curState = getElementData(source, "lspd:siren")
exports.anticheat:changeProtectedElementDataEx(source, "lspd:siren", not curState)
setVehicleSirensOn ( source , not curState )
end
end
addEvent( "lspd:setSirenState", true )
addEventHandler( "lspd:setSirenState", getRootElement(), setSirenState )
Client-side
function bindKey2(res)
bindKey(",", "both", toggleSirens2)
bindKey(",", "up", removeExtra)
end
addEventHandler("onClientResourceStart", getResourceRootElement(), bindKey2)
function toggleSirens2()
local theVehicle = getPedOccupiedVehicle(getLocalPlayer())
if (theVehicle) then
local occupants = getVehicleOccupants(theVehicle)
if occupants[0]==getLocalPlayer() then
triggerServerEvent("lspd:setSirenState", theVehicle, 2)
end
end
end°