Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #88 from Jordan2139/master
Browse files Browse the repository at this point in the history
Update bodycam initialization
  • Loading branch information
SonoranBrian authored Mar 15, 2024
2 parents 75bab1b + 3ed1ffb commit 78c23a8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 21 deletions.
55 changes: 36 additions & 19 deletions sonorancad/core/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,26 @@ AddEventHandler('SonoranCAD::core:recvClientConfig', function(config)
Config.inited = true
debugLog('Configuration received')
debugLog('Bodycam config ready')
Wait(5000)
end)

--[[
SonoranCAD Bodycam Callback if unit is not found in CAD
]]
RegisterNetEvent('SonoranCAD::core::ScreenshotOff', function()
bodyCamOn = false
SendNUIMessage({
type = 'toggleGif'
})
TriggerEvent('chat:addMessage', {
args = {
'Sonoran Bodycam',
'Bodycam disabled - You must be in CAD to enable bodycam'
}
})
end)

RegisterNetEvent('SonoranCAD::Core::InitBodycam', function()
print('Bodycam init')
-- Command to toggle bodycam on and off
RegisterCommand(Config.bodycamCommandToggle, function(source, args, rawCommand)
if Config.apiVersion < 4 then
Expand All @@ -124,7 +143,10 @@ AddEventHandler('SonoranCAD::core:recvClientConfig', function(config)
'Bodycam disabled.'
}
})
SendNUIMessage({type = 'toggleGif', location = Config.bodycamOverlayLocation})
SendNUIMessage({
type = 'toggleGif',
location = Config.bodycamOverlayLocation
})
else
bodyCamOn = true
TriggerEvent('chat:addMessage', {
Expand All @@ -133,7 +155,10 @@ AddEventHandler('SonoranCAD::core:recvClientConfig', function(config)
'Bodycam enabled.'
}
})
SendNUIMessage({type = 'toggleGif', location = Config.bodycamOverlayLocation})
SendNUIMessage({
type = 'toggleGif',
location = Config.bodycamOverlayLocation
})
end
end, false)
-- Command to change the frequency of bodycam screenshots
Expand Down Expand Up @@ -164,14 +189,14 @@ AddEventHandler('SonoranCAD::core:recvClientConfig', function(config)
TriggerEvent('chat:addMessage', {
args = {
'Sonoran Bodycam',
('Frequency set to %s.'):format((bodyCamFrequency/1000))
('Frequency set to %s.'):format((bodyCamFrequency / 1000))
}
})
else
TriggerEvent('chat:addMessage', {
args = {
'Sonoran Bodycam',
('Current bodycam frequency is %s.'):format((bodyCamFrequency/1000))
('Current bodycam frequency is %s.'):format((bodyCamFrequency / 1000))
}
})
end
Expand All @@ -186,19 +211,6 @@ AddEventHandler('SonoranCAD::core:recvClientConfig', function(config)
})
end)

--[[
SonoranCAD Bodycam Callback if unit is not found in CAD
]]
RegisterNetEvent('SonoranCAD::core::ScreenshotOff', function()
bodyCamOn = false
TriggerEvent('chat:addMessage', {
args = {
'Sonoran Bodycam',
'Bodycam disabled - You must be in CAD to enable bodycam'
}
})
end)

CreateThread(function()
while not Config.inited do
Wait(10)
Expand All @@ -221,6 +233,7 @@ local inited = false
AddEventHandler('playerSpawned', function()
TriggerServerEvent('SonoranCAD::core:PlayerReady')
inited = true
TriggerServerEvent('SonoranCAD::Core::RequestBodycam')
end)

RegisterNetEvent('SonoranCAD::core:debugModeToggle')
Expand Down Expand Up @@ -251,7 +264,11 @@ CreateThread(function()
Wait(1)
if Config.bodycamPlayBeeps then
if bodyCamOn then
SendNUIMessage({type = 'playSound', transactionFile = 'beeps', transactionVolume = 0.3})
SendNUIMessage({
type = 'playSound',
transactionFile = 'beeps',
transactionVolume = 0.3
})
Wait(Config.bodycamBeepFrequency)
end
end
Expand Down
37 changes: 37 additions & 0 deletions sonorancad/core/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ AddEventHandler('SonoranCAD::core:sendClientConfig', function()
}
TriggerClientEvent('SonoranCAD::core:recvClientConfig', source, config)
end)

CreateThread(function()
Wait(2000) -- wait for server to settle
if Config.critError then
Expand Down Expand Up @@ -294,6 +295,42 @@ CreateThread(function()
if isPluginLoaded('livemap') then
warnLog('The livemap plugin is no longer being used due to the map being native to the CAD. You can remove this plugin.')
end

local attempts = 0
local max_retries = 20
while attempts <= max_retries do
Wait(1000)
attempts = attempts + 1
if attempts == max_retries then
errorLog('Failed to initialize bodycam due to missing web_baseUrl convar.')
end
if GetConvar('web_baseUrl', '') ~= '' then
TriggerClientEvent('SonoranCAD::Core::InitBodycam', -1)
Config.proxyUrl = ('https://%s/sonorancad/'):format(GetConvar('web_baseUrl', ''))
break;
end
end
end)

RegisterNetEvent('SonoranCAD::Core::RequestBodycam', function()
local attempts = 0
local max_retries = 20
local source = source
if Config.proxyUrl ~= '' then
TriggerClientEvent('SonoranCAD::Core::InitBodycam', source)
else
while attempts <= max_retries do
Wait(1000)
attempts = attempts + 1
if attempts == max_retries then
errorLog('Failed to initialize bodycam due to missing web_baseUrl convar.')
end
if GetConvar('web_baseUrl', '') ~= '' then
TriggerClientEvent('SonoranCAD::Core::InitBodycam', source)
break;
end
end
end
end)

CreateThread(function()
Expand Down
2 changes: 1 addition & 1 deletion sonorancad/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ games {'gta5'}

author 'Sonoran CAD'
description 'Sonoran CAD FiveM Integration'
version '2.9.25'
version '2.9.26'

server_scripts {
'core/http.js'
Expand Down
2 changes: 1 addition & 1 deletion sonorancad/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"resource" : "2.9.25",
"resource" : "2.9.26",
"testedFxServerVersion": "5932"
}

0 comments on commit 78c23a8

Please sign in to comment.