diff --git a/Items/Item.lua b/Items/Item.lua index de8abb4..92aab07 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,13 @@ local function NewItem(menu, title) end Citizen.CreateThread(function() - self.OnActivate() + if (self.OnActivate) then + while IsDisabledControlPressed(0, 24) do + Citizen.Wait(0) + end + + self.OnActivate() + end end) if (self.closeOnActivate) then @@ -127,7 +137,9 @@ local function NewItem(menu, title) end Citizen.CreateThread(function() - self.OnRelease() + if (self.OnRelease) then + self.OnRelease() + end end) end diff --git a/Menu/MenuPool.lua b/Menu/MenuPool.lua index da97a5a..43a0633 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 isKeyToggled = false +local isKeyToggledSinceLastTick = 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,7 @@ local function NewMenuPool() return end - if (IsControlJustPressed(0, self.keys.keyboard.holdForCursor) or IsDisabledControlJustPressed(0, self.keys.keyboard.holdForCursor)) then + if (isKeyToggled and not isKeyToggledSinceLastTick) then if (self:IsAnyMenuOpen()) then self:CloseAllMenus() end @@ -50,10 +52,12 @@ local function NewMenuPool() local resX, resY = GetActiveScreenResolution() resolution = vector2(resX, resY) + + isKeyToggledSinceLastTick = 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 (isKeyToggled and isKeyToggledSinceLastTick) then SetMouseCursorActiveThisFrame() local cursorPosition = GetCursorScreenPosition() @@ -159,17 +163,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 (isKeyToggledSinceLastTick) then self:Reset() + isKeyToggledSinceLastTick = false end end @@ -250,3 +247,13 @@ function MenuPool:AddAlternateFunction(_key, _Func) Func = _Func }) end + +RegisterCommand("+context_menu", function() + isKeyToggled = true +end, false) + +RegisterCommand("-context_menu", function() + isKeyToggled = false +end, false) + +RegisterKeyMapping("+context_menu", "Context Menu", "keyboard", "LMENU") \ No newline at end of file