[Release] Disable siren-sound

Disables your siren when pressed G.

__resource.lua

client_script "siren_client.lua"
server_script "siren_server.lua"

siren_client.lua

function MyPed()
   return GetPlayerPed(-1)
end

SirenToggle = false
Citizen.CreateThread(function()
while true do
    Citizen.Wait(0)
	if IsControlJustPressed(1, 58) then -- G
            if IsPedInAnyVehicle(MyPed(), false) then
                Vehicle = GetVehiclePedIsUsing(MyPed())
				if GetPedInVehicleSeat(Vehicle, -1) == MyPed()then                      
                    if SirenToggle then                 
                        PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1)
                        SirenToggle = false
                        TriggerServerEvent('SilentSiren', SirenToggle)
                    else                                        
                        PlaySoundFrontend(-1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1)
                        SirenToggle = true
                        TriggerServerEvent('SilentSiren', SirenToggle)
                    end
                end
            end
        end
end
end)

-- Called by server to disable siren on any target vehicle
RegisterNetEvent('updateSirens')
AddEventHandler('updateSirens', function(PID, Toggle)
            local Veh = GetVehiclePedIsIn(GetPlayerPed(GetPlayerFromServerId(PID)), false)
            DisableVehicleImpactExplosionActivation(Veh, Toggle)
end)

siren_server.lua

-- Sends to all clients
RegisterServerEvent('SilentSiren')

AddEventHandler('SilentSiren', function(Toggle)
    TriggerClientEvent('updateSirens', -1, source, Toggle)
end)
2 Likes

I was the OP, thanks for re-posting. This doesn’t include any check if a player is online or any disposal of null vehicle IDs.

1 Like

could you tell me how to put this in my files because i dont know thank you

  1. Create a folder in your resources directory, name it whatever you want.
  2. Then create 3 text documents inside that folder and paste in the code above for each corresponding file. Be sure to save them as a .lua file and not a .txt file.
  3. Add the folder name to your citmp-server.yml.
1 Like

If done that but it dont work can you help me soon ?

the script doesnt work.

@roboticgamer Works fine for me and my server

can you send me ur script files maybe I did it wrong.

@roboticgamer Unzip and put the siren folder in your resources folder then enter it in your citmp.yml (- siren)
http://www.mediafire.com/file/op2mvb2f70iyv2b/siren.zip

ive done everything its asked me to do, but it still doesnt turn it off. What key is it if there is one or what

The magic key is G <—

its just not turning off

@Apocalyptikz done!

 

1 Like

Simplified code and added a sound for toggle. This ONLY sends siren status to connected players. Joining players will hear your siren unless you toggle it again.

Just wanted to give you a heads up that the client code uses a MyPed() function which is not included.
Replacing with GetPlayerPed(-1) works or setting that to a variable on key press.

Edit: My bad, hadn’t seen that MyPed() function up top

Did you change all 3 “MyPed()”? Mine is not working, even after changing them.

Apparently there is a MyPed() function that I did not see if you scroll the code up, however there are some other errors as well that must be fixed and it seems to work, although I haven’t tested it with other players.

These lines need to be changed in the client:

if IsControlJustPressed(1, 58) then -- G
     local myPed = GetPlayerPed(-1)
     if IsPedInAnyVehicle(myPed, false) then
          Vehicle = GetVehiclePedIsIn(myPed)
               if GetPedInVehicleSeat(Vehicle, -1) == myPed then
                    if IsPedInAnyPoliceVehicle(myPed) then
                         -- Siren Toggle if statements

And this small change in the server:

TriggerClientEvent('updateSirens', -1, source, Toggle)

source instead of netID since netID is never set to anything.

Added missing function MyPed() and fixed other variables. Sorry :neutral_face:

Still not working… When I press G nothing happens.

Don’t feel bad man, everyone makes mistakes. I’m happy to help.

To get it working you just need to change one more thing I believe,

  • Move GetPedVehicleSeat(MyPed()) to its own if statement below the Vehicle variable, then change it to GetPedInVehicleSeat(Vehicle, -1) == MyPed().

Like this:

if IsPedInAnyVehicle(MyPed(), false) then
     Vehicle = GetVehiclePedIsIn(MyPed())
          if GetPedInVehicleSeat(Vehicle, -1) == MyPed()then

Then it should work just fine, it does for me at least.

1 Like