Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions Config.lua

This file was deleted.

35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@ If you wish to change any keybinds you can do so in the client.lua
- Place both resources into your server (make sure ox_lib is started before renewed sirensync)
- and enjoy :)

## Addon Sirens
If you have a server sided siren pack you can replace the sirens used in the `config.lua`. You can create "groups" of models that use the same siren sounds.
You can refer to the type annotations, but here is an example:

```lua
sirens = {
-- make sure to keep the base sirens ABOVE the addon sirens
base = { ... },

addonSirenGroup1 = {
sirenModes = {
--[[
This table has to be in the correct order, only 3 sirenModes (or steps (when pressing R) if you prefer) are supported
(You can specify the index of the sirenMode, but it's not necessary)
(that's what i mean:)
[1] = { ... }
]]
{ audioName = 'VEHAUD_LSPD_NEW_SIREN_ADAM', audioRef = "VEHAUD_LSPD_NEW_SOUNDSET" }, -- First sirenMode
{ audioName = 'VEHAUD_LSPD_NEW_SIREN_BOY', audioRef = "VEHAUD_LSPD_NEW_SOUNDSET" }, -- Second sirenMode
{ audioName = 'VEHAUD_LSPD_NEW_SIREN_CHARLES', audioRef = "VEHAUD_LSPD_NEW_SOUNDSET" }, -- Third sirenMode
},

horn = {
audioName = 'VEHAUD_LSPD_NEW_HORN'
audioRef = "VEHAUD_LSPD_NEW_SOUNDSET"
},

models = {
[`police5`] = true,
[`polgauntlet`] = true,
}
},
}
```

## Credits

* [AvarianKnight](https://github.com/AvarianKnight) Original creator of PMA Sirensync.
Expand Down
82 changes: 51 additions & 31 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
local Config = require 'Config'
local config = lib.load('config')

-- soundId Tables --
local sirenVehicles = {}
local hornVehicles = {}


-- Natives Used --
local Wait = Wait
local TriggerServerEvent = TriggerServerEvent
Expand All @@ -24,6 +23,9 @@ local AddStateBagChangeHandler = AddStateBagChangeHandler
local NetworkGetEntityOwner = NetworkGetEntityOwner
local SetVehicleHasMutedSirens = SetVehicleHasMutedSirens
local SetVehicleSiren = SetVehicleSiren
local GetEntityModel = GetEntityModel
local GetVehicleEngineHealth = GetVehicleEngineHealth
local GetVehicleBodyHealth = GetVehicleBodyHealth

-- Localized Functions --
local function releaseSound(veh, soundId, forced)
Expand All @@ -42,7 +44,6 @@ local function isVehAllowed()
return true
end


-- Cleanup Loop --
CreateThread(function()
while true do
Expand All @@ -62,9 +63,6 @@ CreateThread(function()
end
end)




-- Cache Events --
lib.onCache('seat', function(seat)
if seat ~= -1 then return end
Expand All @@ -80,13 +78,13 @@ lib.onCache('seat', function(seat)
end

while cache.seat == -1 do
DisableControlAction(0, 80, true) -- R
DisableControlAction(0, 81, true) -- .
DisableControlAction(0, 82, true) -- ,
DisableControlAction(0, 83, true) -- =
DisableControlAction(0, 84, true) -- -
DisableControlAction(0, 85, true) -- Q
DisableControlAction(0, 86, true) -- E
DisableControlAction(0, 80, true) -- R
DisableControlAction(0, 81, true) -- .
DisableControlAction(0, 82, true) -- ,
DisableControlAction(0, 83, true) -- =
DisableControlAction(0, 84, true) -- -
DisableControlAction(0, 85, true) -- Q
DisableControlAction(0, 86, true) -- E
DisableControlAction(0, 172, true) -- Up arrow
Wait(0)
end
Expand All @@ -100,7 +98,7 @@ lib.onCache('vehicle', function(value)

if not state.stateEnsured then return end

if Config.sirenShutOff then
if config.sirenShutOff then
if state.sirenMode ~= 0 then
state:set('sirenMode', 0, true)
end
Expand Down Expand Up @@ -141,7 +139,7 @@ end)
local policeLights = lib.addKeybind({
name = 'policeLights',
description = 'Press this button to use your siren',
defaultKey = Config.Controls.PoliceLights,
defaultKey = config.controls.policeLights,
onPressed = function()
if not isVehAllowed() then return end

Expand All @@ -160,11 +158,8 @@ local policeLights = lib.addKeybind({
end
})


-- Police Horns --

local restoreSiren = 0

stateBagWrapper('horn', function(veh, value)
local relHornId = hornVehicles[veh]

Expand All @@ -179,15 +174,26 @@ stateBagWrapper('horn', function(veh, value)
local soundId = GetSoundId()

hornVehicles[veh] = soundId
local soundName = Config.addonHorns[GetEntityModel(veh)] or 'SIRENS_AIRHORN'
local vehModel = GetEntityModel(veh)
local audioName = 'SIRENS_AIRHORN' -- Default sound
local audioRef

for _, sirenConfig in pairs(config.sirens) do
if (not sirenConfig.models or sirenConfig.models[vehModel]) and sirenConfig.sirenModes.horn then
audioName = sirenConfig.sirenModes.horn?.audioName or audioName
audioRef = sirenConfig.sirenModes.horn?.audioRef or audioRef
-- no break here, allows it to take the base config and if there's another valid config after, replace it.
end
end

PlaySoundFromEntity(soundId, soundName, veh, 0, false, 0)
---@diagnostic disable-next-line: param-type-mismatch
PlaySoundFromEntity(soundId, audioName, veh, audioRef or 0, false, 0)
end)

local policeHorn = lib.addKeybind({
name = 'policeHorn',
description = 'Hold this button to use your vehicle Horn',
defaultKey = Config.Controls.policeHorn,
defaultKey = config.controls.policeHorn,
onPressed = function()
if not isVehAllowed() then return end

Expand Down Expand Up @@ -236,19 +242,34 @@ stateBagWrapper('sirenMode', function(veh, soundMode)
local soundId = GetSoundId()
sirenVehicles[veh] = soundId

if soundMode == 1 then
PlaySoundFromEntity(soundId, 'VEHICLES_HORNS_SIREN_1', veh, 0, false, 0)
elseif soundMode == 2 then
PlaySoundFromEntity(soundId, 'VEHICLES_HORNS_SIREN_2', veh, 0, false, 0)
elseif soundMode == 3 then
PlaySoundFromEntity(soundId, 'VEHICLES_HORNS_POLICE_WARNING', veh, 0, false, 0)
local audioName
local audioRef

if not config.disableDamagedSirens and (config.useEngineHealth and GetVehicleEngineHealth(cache.vehicle) or GetVehicleBodyHealth(cache.vehicle)) <= config.damageThreshold then
audioName = 'PLAYER_FUCKED_SIREN'
else
local vehModel = GetEntityModel(veh)
for _, sirenConfig in pairs(config.sirens) do
if (not sirenConfig.models or sirenConfig.models[vehModel]) and sirenConfig.sirenModes[soundMode] then
audioName = sirenConfig.sirenModes[soundMode]?.audioName or audioName
audioRef = sirenConfig.sirenModes[soundMode]?.audioRef or audioRef
-- no break here, allows it to take the base config and if there's another valid config after, replace it.
end
end
end

if not audioName then
return lib.print.error(('No sound found for siren mode %d on vehicle model (hash) %s'):format(soundMode, GetEntityModel(veh)))
end

---@diagnostic disable-next-line: param-type-mismatch
PlaySoundFromEntity(soundId, audioName, veh, audioRef or 0, false, 0)
end)

local sirenToggle = lib.addKeybind({
name = 'sirenToggle',
description = 'Press this button to use your siren',
defaultKey = Config.Controls.sirenToggle,
defaultKey = config.controls.sirenToggle,
onPressed = function()
if not isVehAllowed() then return end

Expand All @@ -264,12 +285,11 @@ local sirenToggle = lib.addKeybind({
end
})


local Rpressed = false
lib.addKeybind({
name = 'sirenCycle',
description = 'Press this button to cycle through your sirens',
defaultKey = Config.Controls.sirenCycle,
defaultKey = config.controls.sirenCycle,
onPressed = function()
if not isVehAllowed() then return end

Expand Down Expand Up @@ -316,4 +336,4 @@ lib.addKeybind({
end)
end
end
})
})
80 changes: 80 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
return {
---@class audioConfig
---@field audioName string
---@field audioRef? string the audioBank to use, if for example you use custom serverside sirens

---@class SirenConfigTable
---@field models? table<string, boolean>
---@field sirenModes table<number, audioConfig> the key is the siren mode
---@field horn? audioConfig

controls = {
policeLights = 'Q',
policeHorn = 'E',
sirenToggle = 'LMENU',
sirenCycle = 'R',
},

sirenShutOff = true, -- Set to true if you want the siren to automatically shut off when the player exits the vehicle

disableDamagedSirens = false, -- Set to true if you want to disable the damaged siren
useEngineHealth = false, -- Determine wether to use engine health over body health for siren damage
damageThreshold = 300, -- If the vehicle's health is below this value, the siren will be considered damaged

---@type table<string, SirenConfigTable>
--- Configure what siren sounds to use for a specific model and siren mode
sirens = {
base = {
sirenModes = {
{ audioName = 'VEHICLES_HORNS_SIREN_1' },
{ audioName = 'VEHICLES_HORNS_SIREN_2' },
{ audioName = 'VEHICLES_HORNS_POLICE_WARNING' },
},

horn = {
audioName = 'SIRENS_AIRHORN'
}
},

fire = {
sirenModes = {
{ audioName = 'RESIDENT_VEHICLES_SIREN_FIRETRUCK_QUICK_01' },
{ audioName = 'RESIDENT_VEHICLES_SIREN_FIRETRUCK_WAIL_01' },
{ audioName = 'VEHICLES_HORNS_AMBULANCE_WARNING' }
},

horn = {
audioName = 'VEHICLES_HORNS_FIRETRUCK_WARNING'
},

models = {
[`FIRETRUK`] = true,
[`ambulance`] = true,
}
},

unmarked = {
sirenModes = {
{ audioName = 'RESIDENT_VEHICLES_SIREN_WAIL_02' },
{ audioName = 'RESIDENT_VEHICLES_SIREN_QUICK_02' }
},

models = {
[`fbi`] = true,
[`fbi2`] = true,
[`police4`] = true,
}
},

bikes = {
sirenModes = {
{ audioName = 'RESIDENT_VEHICLES_SIREN_WAIL_03' },
{ audioName = 'RESIDENT_VEHICLES_SIREN_QUICK_03' }
},

models = {
[`policeb`] = true
}
},
}
}
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ client_script 'client.lua'

server_script 'server.lua'

file 'Config.lua'
file 'config.lua'