Skip to content

Commit

Permalink
refactor: use lib.addKeybind instead of RegisterKeyMapping (#28)
Browse files Browse the repository at this point in the history
* Update main.lua

add lib.addKeybind open menu

* fix lint error

* fix formatting

---------

Co-authored-by: Manason <clanerp@gmail.com>
  • Loading branch information
Mesrine67 and Manason authored Jun 5, 2024
1 parent 9735f95 commit 697ac17
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,20 @@ AddEventHandler('onResourceStart', function(resourceName)
end)

-- Callbacks & Events
RegisterCommand('menu', function()
Wait(50)
local function settingsMenu()
if showMenu then return end
SetNuiFocus(true, true)
SendNUIMessage({action = 'open'})
showMenu = true
end, false)
end

lib.addKeybind({
name = 'hud_menu',
description = locale('info.open_menu'),
defaultKey = config.menuKey,
defaultMapper = 'keyboard',
onPressed = settingsMenu,
})

RegisterNUICallback('closeMenu', function(_, cb)
Wait(50)
Expand All @@ -104,8 +111,6 @@ RegisterNUICallback('closeMenu', function(_, cb)
cb('ok')
end)

RegisterKeyMapping('menu', locale('info.open_menu'), 'keyboard', config.menuKey)

-- Reset hud
local function restartHud()
exports.qbx_core:Notify(locale('notify.hud_restart'), 'error')
Expand Down

0 comments on commit 697ac17

Please sign in to comment.