@@ -7,15 +7,21 @@ isMiniVisible = false
77-- Debugging Information
88isDebugging = true
99
10+ FrameworkConfig = nil
11+ Framework = nil
12+
1013function DebugMessage (message ,module )
1114if not isDebugging then return end
1215if module ~= nil then message = " [" .. module .. " ]" .. message end
1316print (message .. " \n " )
1417end
1518
1619-- Initialization Procedure
17- Citizen . CreateThread (function ()
20+ CreateThread (function ()
1821Wait (1000 )
22+ -- Request framework configuration from server
23+ TriggerServerEvent (" SonoranCAD::requestFrameworkConfig" )
24+
1925-- Set Default Module Sizes
2026InitModuleSize (" cad" )
2127InitModuleSize (" hud" )
@@ -37,6 +43,38 @@ Citizen.CreateThread(function()
3743
3844TriggerServerEvent (" SonoranCAD::mini:CallSync_S" )
3945
46+ -- Vehicle Exit/Enter Detection for Auto-Hide Mini-CAD
47+ if Config .AutoHideOnVehicleExit then
48+ local wasInVehicle = false
49+ local miniCadWasVisible = false
50+
51+ CreateThread (function ()
52+ while true do
53+ local playerPed = GetPlayerPed (- 1 )
54+ local isInVehicle = IsPedInAnyVehicle (playerPed ,false )
55+
56+ -- Check if player just exited a vehicle
57+ if wasInVehicle and not isInVehicle then
58+ if isMiniVisible then
59+ miniCadWasVisible = true
60+ DisplayModule (" hud" ,false )
61+ DebugMessage (" Auto-hiding mini-CAD on vehicle exit" )
62+ end
63+ -- Check if player just entered a vehicle
64+ elseif not wasInVehicle and isInVehicle then
65+ if miniCadWasVisible then
66+ DisplayModule (" hud" ,true )
67+ miniCadWasVisible = false
68+ DebugMessage (" Auto-showing mini-CAD on vehicle enter" )
69+ end
70+ end
71+
72+ wasInVehicle = isInVehicle
73+ Wait (50 )
74+ end
75+ end )
76+ end
77+
4078-- Disable Controls Loop
4179while true do
4280if nuiFocused then -- Disable controls while NUI is focused.
@@ -45,17 +83,15 @@ Citizen.CreateThread(function()
4583DisableControlAction (0 ,142 ,nuiFocused )-- MeleeAttackAlternate
4684DisableControlAction (0 ,106 ,nuiFocused )-- VehicleMouseControlOverride
4785end
48- Citizen . Wait (0 )-- Yield until next frame.
86+ Wait (0 )-- Yield until next frame.
4987end
5088end )
5189
5290function InitModuleSize (module )
53- -- Check if the size of the specified module is already configured.
5491local moduleWidth = GetResourceKvpString (module .. " width" )
5592local moduleHeight = GetResourceKvpString (module .. " height" )
5693if moduleWidth ~= nil and moduleHeight ~= nil then
5794DebugMessage (" retrieving saved presets" ,module )
58- -- Send message to NUI to resize the specified module.
5995SetModuleSize (module ,moduleWidth ,moduleHeight )
6096SendNUIMessage ({
6197type = " refresh" ,
@@ -68,7 +104,6 @@ function InitModuleConfig(module)
68104local moduleMaxRows = GetResourceKvpString (module .. " maxrows" )
69105if moduleMaxRows ~= nil then
70106DebugMessage (" retrieving config presets" ,module )
71- -- Send messsage to NUI to update config of specified module.
72107SetModuleConfigValue (module ," maxrows" ,moduleMaxRows )
73108SendNUIMessage ({
74109type = " refresh" ,
@@ -163,7 +198,11 @@ RegisterNetEvent("SonoranCAD::mini:OpenMini:Return")
163198AddEventHandler (' SonoranCAD::mini:OpenMini:Return' ,function (authorized ,ident )
164199myident = ident
165200if authorized then
166- DisplayModule (" hud" ,true )
201+ if not isMiniVisible then
202+ DisplayModule (" hud" ,true )
203+ else
204+ DisplayModule (" hud" ,false )
205+ end
167206if not GetResourceKvpString (" shownTutorial" )then
168207ShowHelpMessage ()
169208SetResourceKvp (" shownTutorial" ," yes" )
@@ -186,9 +225,68 @@ function ShowHelpMessage()
186225PrintChatMessage (" Keybinds: Attach/Detach [K], Details [L], Previous/Next [LEFT/RIGHT], changable in settings!" )
187226end
188227
228+ function IsInWhitelistedVehicle ()
229+ local ped = PlayerPedId ()
230+ if not IsPedInAnyVehicle (ped ,false )then return false end
231+ local veh = GetVehiclePedIsIn (ped ,false )
232+ if veh and veh ~= 0 then
233+ local model = GetEntityModel (veh )
234+ for _ ,allowed in ipairs (Config .AccessRestrictions .AllowedVehicles or {})do
235+ if model == GetHashKey (allowed )then
236+ return true
237+ end
238+ end
239+ end
240+ return false
241+ end
242+
243+ function CheckJobRestriction ()
244+ local jobAllowed = true
245+ if Config .AccessRestrictions .RestrictByJob then
246+ jobAllowed = false
247+ local playerJob = nil
248+
249+ -- Check if framework is initialized
250+ if FrameworkConfig .usingQBCore then
251+ local Player = Framework .Functions .GetPlayerData ()
252+ playerJob = Player .job .name
253+ else
254+ local xPlayer = Framework .GetPlayerData ()
255+ playerJob = xPlayer .job .name
256+ end
257+
258+ if playerJob then
259+ for _ ,allowedJob in pairs (Config .AccessRestrictions .AllowedJobs )do
260+ if playerJob == allowedJob then
261+ jobAllowed = true
262+ break
263+ end
264+ end
265+ end
266+ end
267+
268+ local vehicleAllowed = true
269+ if Config .AccessRestrictions .RestrictByVehicle then
270+ vehicleAllowed = IsInWhitelistedVehicle ()
271+ end
272+
273+ return jobAllowed and vehicleAllowed
274+ end
275+
189276-- Mini Module Commands
190277RegisterCommand (" minicad" ,function (source ,args ,rawCommand )
191- TriggerServerEvent (" SonoranCAD::mini:OpenMini" )
278+ if not CheckJobRestriction ()then
279+ PrintChatMessage (" You do not have permission to access the Mini-CAD." )
280+ return
281+ end
282+
283+ local ped = PlayerPedId ()
284+ local inVehicle = IsPedInAnyVehicle (ped ,false )
285+ if Config .AllowMiniCadOnFoot or inVehicle then
286+ TriggerServerEvent (" SonoranCAD::mini:OpenMini" )
287+ else
288+ PrintChatMessage (" You must be in a vehicle to access the Mini-CAD." )
289+ end
192290end ,false )
193291RegisterKeyMapping (' minicad' ,' Mini CAD' ,' keyboard' ,' ' )
194292
@@ -201,7 +299,7 @@ end, false)
201299RegisterKeyMapping (' minicadp' ,' Previous Call' ,' keyboard' ,' LEFT' )
202300
203301RegisterCommand (" minicada" ,function (source ,args ,rawCommand )
204- print (" ismini " .. tostring ( isMiniVisible ) )
302+ print (" attach " )
205303if not isMiniVisible then return end
206304SendNUIMessage ({type = " command" ,key = " attach" })
207305end ,false )
@@ -243,14 +341,25 @@ TriggerEvent('chat:addSuggestion', '/minicadrows', "Specify max number of call n
243341{name = " rows" ,help = " any number (default 10)" }
244342})
245343
344+
246345-- CAD Module Commands
247346RegisterCommand (" showcad" ,function (source ,args ,rawCommand )
347+ if not CheckJobRestriction ()then
348+ PrintChatMessage (" You do not have permission to access the CAD Tablet." )
349+ return
350+ end
248351DisplayModule (" cad" ,true )
249352toggleTabletDisplay (true )
250353SetFocused (true )
251354end ,false )
252355RegisterKeyMapping (' showcad' ,' CAD Tablet' ,' keyboard' ,' ' )
253356
357+ RegisterNetEvent (" SonoranCAD::showcad" ,function ()
358+ DisplayModule (" cad" ,true )
359+ toggleTabletDisplay (true )
360+ SetFocused (true )
361+ end )
362+
254363TriggerEvent (' chat:addSuggestion' ,' /cadsize' ," Resize CAD to specific width and height in pixels. Default is 1100x510" , {
255364{name = " Width" ,help = " Width in pixels" }, {name = " Height" ,help = " Height in pixels" }
256365})
@@ -392,4 +501,24 @@ end)
392501RegisterNetEvent (" sonoran:tablet:failed" )
393502AddEventHandler (" sonoran:tablet:failed" ,function (message )
394503errorLog (" Failed to set API ID:" .. tostring (message ))
395- end )
504+ end )
505+
506+ RegisterNetEvent (" SonoranCAD::receiveFrameworkConfig" )
507+ AddEventHandler (" SonoranCAD::receiveFrameworkConfig" ,function (frameworkConfig )
508+ if isDebugging then
509+ print (" Framework Configuration received:" )
510+ print (" Using QBCore:" .. tostring (frameworkConfig .usingQBCore ))
511+ for key ,value in pairs (frameworkConfig )do
512+ print (key .. " :" .. tostring (value ))
513+ end
514+ end
515+ if frameworkConfig .usingQBCore then
516+ FrameworkConfig = frameworkConfig
517+ Framework = exports [' qb-core' ]:GetCoreObject ()
518+ print (" Framework initialized: QBCore" )
519+ else
520+ FrameworkConfig = frameworkConfig
521+ Framework = exports .es_extended :getSharedObject ()
522+ print (" Framework initialized: ESX" )
523+ end
524+ end )