From ce90c6bc47e9f2cbe480310fe250de6b7f55e384 Mon Sep 17 00:00:00 2001 From: Ilias Rbayti <63159154+Kenshiin13@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:45:58 +0200 Subject: [PATCH] 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. --- [core]/es_extended/client/functions.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/[core]/es_extended/client/functions.lua b/[core]/es_extended/client/functions.lua index af1c9183..9e8656de 100644 --- a/[core]/es_extended/client/functions.lua +++ b/[core]/es_extended/client/functions.lua @@ -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)