diff --git a/Config.lua b/Config.lua deleted file mode 100644 index 970d3a5..0000000 --- a/Config.lua +++ /dev/null @@ -1,13 +0,0 @@ -return { - Controls = { - PoliceLights = 'Q', - policeHorn = 'E', - sirenToggle = 'LMENU', - sirenCycle = 'R', - }, - addonHorns = { - [`firetruk`] = 'VEHICLES_HORNS_FIRETRUCK_WARNING' - }, - - sirenShutOff = true -- Set to true if you want the siren to automatically shut off when the player exits the vehicle -} diff --git a/README.md b/README.md index 8cba024..4fe9972 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/client.lua b/client.lua index a4f30f5..7f19f00 100644 --- a/client.lua +++ b/client.lua @@ -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 @@ -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) @@ -42,7 +44,6 @@ local function isVehAllowed() return true end - -- Cleanup Loop -- CreateThread(function() while true do @@ -62,9 +63,6 @@ CreateThread(function() end end) - - - -- Cache Events -- lib.onCache('seat', function(seat) if seat ~= -1 then return end @@ -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 @@ -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 @@ -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 @@ -160,11 +158,8 @@ local policeLights = lib.addKeybind({ end }) - -- Police Horns -- - local restoreSiren = 0 - stateBagWrapper('horn', function(veh, value) local relHornId = hornVehicles[veh] @@ -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 @@ -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 @@ -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 @@ -316,4 +336,4 @@ lib.addKeybind({ end) end end -}) +}) \ No newline at end of file diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..6025ae0 --- /dev/null +++ b/config.lua @@ -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 + ---@field sirenModes table 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 + --- 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 + } + }, + } +} \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index d386525..317d9fe 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -13,4 +13,4 @@ client_script 'client.lua' server_script 'server.lua' -file 'Config.lua' +file 'config.lua'