From 54088abcb6bebf368c344680d7ffa689f4c8abbb Mon Sep 17 00:00:00 2001 From: Tony Stark <76168122+tony-stark-17@users.noreply.github.com> Date: Tue, 20 Dec 2022 23:10:06 +0530 Subject: [PATCH] Add canClose function to context menu Added a canClose parameter so that the user cannot close the menu by pressing ESC instead has to be force closed via code. --- [esx]/esx_context/main.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/[esx]/esx_context/main.lua b/[esx]/esx_context/main.lua index 5a879643..8a2769c9 100644 --- a/[esx]/esx_context/main.lua +++ b/[esx]/esx_context/main.lua @@ -12,10 +12,11 @@ function Post(fn,...) }) end -function Open(position,eles,onSelect,onClose) +function Open(position,eles,onSelect,onClose,canClose) activeMenu = { position = position, eles = eles, + canClose = canClose, onSelect = onSelect, onClose = onClose } @@ -74,11 +75,11 @@ end) -- NUI Callbacks -- [ closed | selected | changed ] -RegisterNUICallback("closed",function() - if not activeMenu then - return +RegisterNUICallback("closed",function(data,cb) + if not activeMenu or (activeMenu and not activeMenu.canClose) then + return cb(false) end - + cb(true) Closed() end) @@ -266,4 +267,4 @@ if Debug then exports["esx_context"]:Open(position,eles,onSelect,onClose) end) -end \ No newline at end of file +end