From 5b28652840786fec96a67c25130ccda2f4eb2a95 Mon Sep 17 00:00:00 2001 From: 0xKunah Date: Wed, 3 Jan 2024 21:57:50 +0100 Subject: [PATCH 1/5] Added keybind feature using RegisterKeyMapping --- Menu/MenuPool.lua | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Menu/MenuPool.lua b/Menu/MenuPool.lua index da97a5a..bc4d189 100644 --- a/Menu/MenuPool.lua +++ b/Menu/MenuPool.lua @@ -3,6 +3,9 @@ local disabledControls = { 1, 2, 16, 17, 24, 25, 68, 69, 70, 91, 92, 330, 331, 347, 257 } +local isToggleKeyDown = false +local isToggleKeyDown2 = false + local function NewMenuPool() local self = setmetatable({}, MenuPool) @@ -10,7 +13,6 @@ local function NewMenuPool() self.keys = { keyboard = { - holdForCursor = holdKey or 19, interact = interactKey or 25, activateItem = activateItemKey or 24 } @@ -41,7 +43,8 @@ local function NewMenuPool() return end - if (IsControlJustPressed(0, self.keys.keyboard.holdForCursor) or IsDisabledControlJustPressed(0, self.keys.keyboard.holdForCursor)) then + if (isToggleKeyDown and not isToggleKeyDown2) then + print("truc 1") if (self:IsAnyMenuOpen()) then self:CloseAllMenus() end @@ -50,10 +53,12 @@ local function NewMenuPool() local resX, resY = GetActiveScreenResolution() resolution = vector2(resX, resY) + + isToggleKeyDown2 = true end --not self.settings.holdKeyWithMenuOpen and self:IsAnyMenuOpen() - if (IsControlPressed(0, self.keys.keyboard.holdForCursor) or IsDisabledControlPressed(0, self.keys.keyboard.holdForCursor)) then + if (isToggleKeyDown and isToggleKeyDown2) then SetMouseCursorActiveThisFrame() local cursorPosition = GetCursorScreenPosition() @@ -159,17 +164,10 @@ local function NewMenuPool() SetMouseCursorSprite(6) end - -- causes camera problems - --if (screenPosition.y > (resolution.y - 10.0) / resolution.y) then - -- SetGameplayCamRelativePitch(GetGameplayCamRelativePitch() - 25.0 * frameTime, 1.0) - -- SetMouseCursorSprite(9) - --elseif (screenPosition.y < 10.0 / resolution.y) then - -- SetGameplayCamRelativePitch(GetGameplayCamRelativePitch() + 25.0 * frameTime, 1.0) - -- SetMouseCursorSprite(8) - --end end - elseif (IsControlJustReleased(0, self.keys.keyboard.holdForCursor) or IsDisabledControlJustReleased(0, self.keys.keyboard.holdForCursor)) then + elseif (isToggleKeyDown2) then self:Reset() + isToggleKeyDown2 = false end end @@ -250,3 +248,13 @@ function MenuPool:AddAlternateFunction(_key, _Func) Func = _Func }) end + +RegisterCommand("+context_menu", function() + isToggleKeyDown = true +end, false) + +RegisterCommand("-context_menu", function() + isToggleKeyDown = false +end, false) + +RegisterKeyMapping("+context_menu", "Context Menu", "keyboard", "LMENU") \ No newline at end of file From f260c649a70b2ea89e680cf662102669eb8f4553 Mon Sep 17 00:00:00 2001 From: 0xKunah Date: Wed, 3 Jan 2024 22:00:28 +0100 Subject: [PATCH 2/5] Removed useless print --- Menu/MenuPool.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/Menu/MenuPool.lua b/Menu/MenuPool.lua index bc4d189..a16d228 100644 --- a/Menu/MenuPool.lua +++ b/Menu/MenuPool.lua @@ -44,7 +44,6 @@ local function NewMenuPool() end if (isToggleKeyDown and not isToggleKeyDown2) then - print("truc 1") if (self:IsAnyMenuOpen()) then self:CloseAllMenus() end From 64e1e320884bb4abd51c7221924be061591ec6a7 Mon Sep 17 00:00:00 2001 From: 0xKunah Date: Wed, 3 Jan 2024 22:02:22 +0100 Subject: [PATCH 3/5] Renamed variables --- Menu/MenuPool.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Menu/MenuPool.lua b/Menu/MenuPool.lua index a16d228..43a0633 100644 --- a/Menu/MenuPool.lua +++ b/Menu/MenuPool.lua @@ -3,8 +3,8 @@ local disabledControls = { 1, 2, 16, 17, 24, 25, 68, 69, 70, 91, 92, 330, 331, 347, 257 } -local isToggleKeyDown = false -local isToggleKeyDown2 = false +local isKeyToggled = false +local isKeyToggledSinceLastTick = false local function NewMenuPool() local self = setmetatable({}, MenuPool) @@ -43,7 +43,7 @@ local function NewMenuPool() return end - if (isToggleKeyDown and not isToggleKeyDown2) then + if (isKeyToggled and not isKeyToggledSinceLastTick) then if (self:IsAnyMenuOpen()) then self:CloseAllMenus() end @@ -53,11 +53,11 @@ local function NewMenuPool() local resX, resY = GetActiveScreenResolution() resolution = vector2(resX, resY) - isToggleKeyDown2 = true + isKeyToggledSinceLastTick = true end --not self.settings.holdKeyWithMenuOpen and self:IsAnyMenuOpen() - if (isToggleKeyDown and isToggleKeyDown2) then + if (isKeyToggled and isKeyToggledSinceLastTick) then SetMouseCursorActiveThisFrame() local cursorPosition = GetCursorScreenPosition() @@ -164,9 +164,9 @@ local function NewMenuPool() end end - elseif (isToggleKeyDown2) then + elseif (isKeyToggledSinceLastTick) then self:Reset() - isToggleKeyDown2 = false + isKeyToggledSinceLastTick = false end end @@ -249,11 +249,11 @@ function MenuPool:AddAlternateFunction(_key, _Func) end RegisterCommand("+context_menu", function() - isToggleKeyDown = true + isKeyToggled = true end, false) RegisterCommand("-context_menu", function() - isToggleKeyDown = false + isKeyToggled = false end, false) RegisterKeyMapping("+context_menu", "Context Menu", "keyboard", "LMENU") \ No newline at end of file From a75fa591193c38644e97ac80c061f609da3db1c3 Mon Sep 17 00:00:00 2001 From: Kunah Date: Sun, 29 Sep 2024 19:04:29 +0200 Subject: [PATCH 4/5] Fix bug with nui conflict --- Items/Item.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Items/Item.lua b/Items/Item.lua index de8abb4..d089541 100644 --- a/Items/Item.lua +++ b/Items/Item.lua @@ -57,11 +57,15 @@ local function NewItem(menu, title) if (self.hovered) then Citizen.CreateThread(function() - self.OnStartHover() + if (self.OnStartHover) then + self.OnStartHover() + end end) else Citizen.CreateThread(function() - self.OnEndHover() + if (self.OnEndHover) then + self.OnEndHover() + end end) end end @@ -113,7 +117,14 @@ local function NewItem(menu, title) end Citizen.CreateThread(function() - self.OnActivate() + if (self.OnActivate) then + while IsDisabledControlPressed(0, 24) do + Citizen.Wait(0) + print("ff") + end + + self.OnActivate() + end end) if (self.closeOnActivate) then @@ -127,7 +138,9 @@ local function NewItem(menu, title) end Citizen.CreateThread(function() - self.OnRelease() + if (self.OnRelease) then + self.OnRelease() + end end) end From 6e81b05fdf178e5a0b744cc209569f612954ae87 Mon Sep 17 00:00:00 2001 From: Kunah Date: Sun, 29 Sep 2024 19:10:22 +0200 Subject: [PATCH 5/5] Update Item.lua --- Items/Item.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/Items/Item.lua b/Items/Item.lua index d089541..92aab07 100644 --- a/Items/Item.lua +++ b/Items/Item.lua @@ -120,7 +120,6 @@ local function NewItem(menu, title) if (self.OnActivate) then while IsDisabledControlPressed(0, 24) do Citizen.Wait(0) - print("ff") end self.OnActivate()