No siren (server side)

Client

function isPlayerOnline(PID)
local playerExists = DoesEntityExist(GetPlayerPed(GetPlayerFromServerId(PID)))
return playerExists
end
--  listen for keys
Citizen.CreateThread(function()
while true do
    Citizen.Wait(0)
	if IsControlJustPressed(1, 58) then
		if IsPedInAnyVehicle(GetPlayerPed(-1), true) then
			TriggerEvent('NoSiren')
		end
	end
end
end)

-- Updates sirens every 2 seconds
Citizen.CreateThread(function()
while true do
    Citizen.Wait(2000)
	local Ped = GetPlayerPed(-1)
	if IsPedInAnyVehicle(Ped, true) then
		local Veh = GetVehiclePedIsIn(Ped, false)

			local PF = GetVehiclePaintFade(Veh)
			local Toggle = false
			if PF < 0.04 then
				Toggle = true
			end

			TriggerServerEvent('SilentSiren', Toggle)

	end
end
end)

-- Initial siren enable/disable. Sends to server
AddEventHandler('NoSiren', function()
Citizen.CreateThread(function()
	local Ped = GetPlayerPed(-1)
	if IsPedInAnyVehicle(Ped, true) then
		local Veh = GetVehiclePedIsIn(Ped, false)

		if GetPedInVehicleSeat(Veh, -1) == Ped then

			local OldPF = GetVehiclePaintFade(Veh)
			local Toggle = false
			if OldPF < 0.04 then
				Toggle = true
			end

			local PF = 0.1
			if not Toggle then
				PF = 0.0
			end

			SetVehiclePaintFade(Veh, PF)
			TriggerServerEvent('SilentSiren', not Toggle)
		end
	end

end)
end)

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

Server

-- Sirens are stored in a table/array with playerid and toggle
local playersWithoutSiren = {}

RegisterServerEvent('SilentSiren')

AddEventHandler('SilentSiren', function(Toggle)
local netID = source
TriggerClientEvent('updateSirens', -1, netID, Toggle)
playersWithoutSiren[netID] = Toggle
end)

Download here: http://www.filedropper.com/siren

To disable your siren press G.

How does the paint fade have any affect on the siren? How exactly does that work?

It has nothing to do with the siren but is used for the logic. Since there is no “is siren off” flag, one needs to be made (PF less than 0.4) that does not make a noticeable difference on the vehicle.

Hey Apocalyptikz i have a question for you. Do we need to create the .lua files by ourself or not? And if i added it to my server, wich button do we need to press in order to mute the siren. Thanks in advance

I just provided the code you need to put in client and server lua files. The default key is G.

okay i dont have alot of experience with coding… but this would be awesome for my roleplay group… Any chance anyone can help me out with knowing exactly where to put these lines in so i dont mess anything up.

Thanks a bunch

@Apocalyptikz Hey. Is this what we should have?alt text

@grahamgarn ^ http://imgur.com/a/7ShP6

@grahamgarn first thing first… is your last name graham??? and second did you create those two files and where did u put them?? into your mods section then add them to the .loa in main directory to execute?

@killerik first name is graham… i created the files yeah.

interesting

@grahamgarn okay… my last name is graham… spelt the same… lol… but did you have any success with this?

lol. Yep! Great work.

Might be an idea to tell what controls would this have?
Maybe add a downloadlink to a complete package?

Just some ideas, great work.

where install that in server side clien and server ? where thanks

Added a download link. Extract the folder to your “resources” directory and add “siren” to your server’s resources.

i install that and when i press g not cut siren

alt text

works great for all client on server :slight_smile:

Anyone else get this strange siren “whoop” when muting your siren. Happens every few seconds but eventually stops. It also does it when entering and exiting your vehicle. It’s the same sound as if you click your siren key really fast twice in a row. Sometimes it does it, sometimes it don’t. I’m thinking I may have another script conflicting with it.