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)
Create a folder in your resources directory, name it whatever you want.
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.
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
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