fix(ESX.UI): Close Opened Menus on Resource Stop

I have encountered several frustrating instances when accidentally restarting a script that still had an open ESX UI. This situation prevents the UI from closing properly and leads to a cascade of errors, ultimately forcing a game restart. To address this issue, I propose the following code changes.

The code introduces an event handler for the onResourceStop event, enabling us to loop through all open ESX UIs and identify any opened menus within the same namespace as the resource name. Following the best practice, the namespace should ideally align with the resource name.

I believe implementing these changes will provide a smoother user experience. I look forward to your feedback and merging these improvements into the main branch.
This commit is contained in:
Ilias Rbayti
2023-08-07 21:45:58 +02:00
parent a95e0397b0
commit ce90c6bc47
+11
View File
@@ -1343,6 +1343,17 @@ AddEventHandler('esx:showHelpNotification', function(msg, thisFrame, beep, durat
ESX.ShowHelpNotification(msg, thisFrame, beep, duration)
end)
AddEventHandler('onResourceStop', function(resourceName)
for i = 1, #ESX.UI.Menu.Opened, 1 do
if ESX.UI.Menu.Opened[i] then
if ESX.UI.Menu.Opened[i].namespace == resourceName then
ESX.UI.Menu.Opened[i].close()
ESX.UI.Menu.Opened[i] = nil
end
end
end
end)
---@param model number|string
---@return string
function ESX.GetVehicleType(model)