Jump to content

Siren on civilian car


tim260

Recommended Posts

i was searching for a script but i couldnt get it to work, i found this (©solidsnake14)

--client 
  
function startSirene ( vehicle ) 
            local x,y,z = getElementPosition( vehicle ) 
            sound = playSound3D( "sons\\sirene1.wav", x, y, z, true) 
            attachElements ( sound, vehicle) 
end 
addEvent( "startSirene", true ) 
addEventHandler("startSirene", getRootElement(), startSirene) 
  
function stopSirene() 
destroyElement(sound) 
end 
addEvent( "stopSirene", true ) 
addEventHandler("stopSirene", getRootElement(), stopSirene) 
  
--server 
  
function startSirene( player, cmd ) 
        local commandant = createVehicle ( 554, 1227.746, -1422.281, 13.5432, 0, 0, 0, "COMM1" ) 
        triggerClientEvent ( player, "startSirene", getRootElement(), commandant ) 
end 
addCommandHandler ( "sireneon", startSirene) 
  
function stopSirene( player, cmd ) 
        triggerClientEvent ( player, "stopSirene", getRootElement() ) 
end 
addCommandHandler ( "sireneoff", stopSirene) 

but cant get it to work ;/

EDIT: and dont understand it fully

Link to comment

try this:

addEventHandler("onVehicleEnter",getRootElement(), 
function(player,seat,jacked) 
    if (player) then 
    if (seat == 0) then 
        veh = getPedOccupiedVehicle(player) 
        bindKey(player,"l","down",sirens,veh) 
    end 
    end 
end) 
  
addEventHandler("onVehicleStartExit",getRootElement(), 
function(player,seat,jacked) 
    if (player) then 
    if (seat == 0) then 
        unbindKey(player,"l","down",sirens) 
    end 
    end 
end) 
  
function sirens(keyPresser,key,keyState,veh) 
    if (keyPresser) then 
        if (key == "l") and (keyState == "down") then 
            if not getVehicleSirensOn ( veh ) then 
                setVehicleSirensOn ( veh, true ) --Turn it on 
            else 
                setVehicleSirensOn ( veh, false ) --Turn it off 
            end 
        end 
    end 
end 

Link to comment
try this:
addEventHandler("onVehicleEnter",getRootElement(), 
function(player,seat,jacked) 
    if (player) then 
    if (seat == 0) then 
        veh = getPedOccupiedVehicle(player) 
        bindKey(player,"l","down",sirens,veh) 
    end 
    end 
end) 
  
addEventHandler("onVehicleStartExit",getRootElement(), 
function(player,seat,jacked) 
    if (player) then 
    if (seat == 0) then 
        unbindKey(player,"l","down",sirens) 
    end 
    end 
end) 
  
function sirens(keyPresser,key,keyState,veh) 
    if (keyPresser) then 
        if (key == "l") and (keyState == "down") then 
            if not getVehicleSirensOn ( veh ) then 
                setVehicleSirensOn ( veh, true ) --Turn it on 
            else 
                setVehicleSirensOn ( veh, false ) --Turn it off 
            end 
        end 
    end 
end 

@ Jaysds1: I know he could easily modify your script, but just to remind you, civilian vehicles cannot play the siren sound, so it means you need to attach a playSound3D function for the car. Your script was like another script, nothing from the original one.

@ tim260: Remember to add setSoundVolume and setSoundMaxDistance for the sound. Otherwise if you don't have the volume, you can't hear it.

Link to comment
try this:
addEventHandler("onVehicleEnter",getRootElement(), 
function(player,seat,jacked) 
    if (player) then 
    if (seat == 0) then 
        veh = getPedOccupiedVehicle(player) 
        bindKey(player,"l","down",sirens,veh) 
    end 
    end 
end) 
  
addEventHandler("onVehicleStartExit",getRootElement(), 
function(player,seat,jacked) 
    if (player) then 
    if (seat == 0) then 
        unbindKey(player,"l","down",sirens) 
    end 
    end 
end) 
  
function sirens(keyPresser,key,keyState,veh) 
    if (keyPresser) then 
        if (key == "l") and (keyState == "down") then 
            if not getVehicleSirensOn ( veh ) then 
                setVehicleSirensOn ( veh, true ) --Turn it on 
            else 
                setVehicleSirensOn ( veh, false ) --Turn it off 
            end 
        end 
    end 
end 

still i cant get it to work :/

Link to comment

try this or use /debugscript 3 to find where is the problem

addEventHandler("onVehicleEnter",getRootElement(), 
function(player,seat,jacked) 
    if (player) then 
    if (seat == 0) then 
        veh = getPedOccupiedVehicle(player) 
        bindKey(player,"l","down",sirens) 
    end 
    end 
end) 
  
addEventHandler("onVehicleStartExit",getRootElement(), 
function(player,seat,jacked) 
    if (player) then 
    if (seat == 0) then 
        unbindKey(player,"l","down") 
    end 
    end 
end) 
  
function sirens() 
    if not getVehicleSirensOn ( veh ) then 
                setVehicleSirensOn ( veh, true ) --Turn it on 
            else 
                setVehicleSirensOn ( veh, false ) --Turn it off 
            end 
        end 
  

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