0% found this document useful (0 votes)
341 views5 pages

FiveM Menu Library Functions

Uploaded by

davidtressel1312
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
341 views5 pages

FiveM Menu Library Functions

Uploaded by

davidtressel1312
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

menulib = {}

currentMenu = nil
menus = {}
isMenuOpen = false
currentUI = "FUI"

function [Link](id, title, subtitle, options)


local menu = {
id = id,
title = title,
subtitle = subtitle,
options = options or {},
items = {},
parent = nil
}
menus[id] = menu
return menu
end

function [Link](id, parent, title, subtitle, options)


local submenu = [Link](id, title, subtitle, options)
[Link] = parent
return submenu
end

function [Link](label)
[Link]([Link], {id = #[Link] + 1, type =
"separator", label = label})
end

function [Link]()
[Link]([Link], {id = #[Link] + 1, type = "line"})
end

function [Link](label, options, action)


local button = {
id = #[Link] + 1,
type = "button",
label = label,
description = [Link],
info = [Link],
onSelected = action,
condition = [Link]
}

[Link]([Link], button)
updateButtonDisplay(button)
end

function [Link](label, list, options, action)


[Link]([Link], {
id = #[Link] + 1,
type = "list",
label = label,
list = list,
description = [Link],
onSelected = action,
currentSelect = 1
})
end

[Link](function()
while true do
[Link](0)
if currentMenu then
for _, item in ipairs([Link]) do
if [Link] == "button" and [Link] then
updateButtonDisplay(item)
end
end
end
end
end)

function updateButtonDisplay(button)
if not [Link] then return end

local conditionMet = [Link]()


local rightLabel = ""
if not conditionMet then
rightLabel = [[<svg width="16" height="16" viewBox="0 0 558 800"
fill="none" xmlns="[Link] transform="translate(-8, 0)">
<path d="M36.5758 800H521.424C541.507 800 557.788 783.719 557.788
763.636V351.515C557.788 331.433 541.507 315.152 521.424
315.152H485.061V206.061C485.061 92.4388 392.622 0 279 0C165.378 0 72.9394 92.4388
72.9394 206.061V315.152H36.5758C16.4934 315.152 0.212158 331.433 0.212158
351.515V763.636C0.212158 783.719 16.4934 800 36.5758 800ZM315.364
569.663V618.182C315.364 638.264 299.082 654.545 279 654.545C258.918 654.545 242.636
638.264 242.636 618.182V569.663C227.926 558.596 218.394 540.999 218.394
521.212C218.394 487.794 245.582 460.606 279 460.606C312.418 460.606 339.606 487.794
339.606 521.212C339.606 540.999 330.074 558.596 315.364 569.663ZM145.667
206.061C145.667 132.541 205.48 72.7273 279 72.7273C352.52 72.7273 412.333 132.541
412.333 206.061V315.152H145.667V206.061Z" fill="currentColor"/>
</svg>]]
end

SendNUIMessage({
eventName = "update_button",
metadata = {
id = [Link],
label = [Link],
rightLabel = rightLabel
}
})
end

function [Link](label, checked, options, onChecked, onUnchecked)


[Link]([Link], {
id = #[Link] + 1,
type = "checkbox",
label = label,
checked = checked,
description = [Link],
onChecked = onChecked,
onUnchecked = onUnchecked
})
end
function [Link](id)
if menus[id] then
currentMenu = menus[id]
local itemsToSend = {}
for i, item in ipairs([Link]) do
local itemToSend = {
id = [Link],
type = [Link],
label = [Link],
rightLabel = [Link],
description = [Link],
list = [Link],
checked = [Link],
info = [Link]
}
[Link](itemsToSend, itemToSend)
end
SendNUIMessage({
eventName = "open_menu",
metadata = {
id = [Link],
title = [Link],
subtitle = [Link],
items = itemsToSend
}
})
loadUITheme()
SetNuiFocus(true, false)
SetNuiFocusKeepInput(true)
isMenuOpen = true
else
print("Le menu n'existe pas: " .. id)
end
end

function [Link]()
if currentMenu then
SendNUIMessage({eventName = "close_menu"})
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
isMenuOpen = false
currentMenu = nil
end
end

function [Link]()
if currentMenu and [Link] then
[Link]([Link])
else
[Link]()
end
end

[Link](function()
while true do
[Link](0)

if isMenuOpen then
local scrollDirection = nil
if IsControlJustPressed(0, 172) then
scrollDirection = "up"
PlaySound([Link], [Link])
elseif IsControlJustPressed(0, 173) then
scrollDirection = "down"
PlaySound([Link], [Link])
end

if scrollDirection then
SendNUIMessage({eventName = "start_accelerated_scroll", metadata =
{direction = scrollDirection}})
end

if IsControlJustReleased(0, 172) or IsControlJustReleased(0, 173) then


SendNUIMessage({eventName = "stop_accelerated_scroll"})
end

if IsControlJustPressed(0, 174) then


SendNUIMessage({eventName = "left_selection"})
PlaySound([Link], [Link])
end
if IsControlJustPressed(0, 175) then
SendNUIMessage({eventName = "right_selection"})
PlaySound([Link], [Link])
end
if IsControlJustPressed(0, 176) then
SendNUIMessage({eventName = "select_item"})
SendNUIMessage({eventName = "play_custom_sound"})
end
if IsControlJustPressed(0, 177) then
[Link]()
end
else
[Link](150)
end
end
end)

RegisterNUICallback("updateButtonDisplay", function(data, cb)


local item = [Link][[Link]]
if item and [Link] == "button" and [Link] then
updateButtonDisplay(item)
end
cb('ok')
end)

RegisterNUICallback("onSelected", function(data, cb)


local item = [Link][[Link]]
if item and [Link] then
[Link]()
end
cb('ok')
end)

RegisterNUICallback("onListSelected", function(data, cb)


local item = [Link][[Link]]
if item and [Link] then
[Link]([Link])
end
cb('ok')
end)

RegisterNUICallback("onCheckboxSelected", function(data, cb)


local item = [Link][[Link]]
if item then
[Link] = [Link]
if [Link] and [Link] then
[Link]()
elseif not [Link] and [Link] then
[Link]()
end
updateMenuDisplay()
end
cb('ok')
end)

function updateMenuDisplay()
if currentMenu then
local itemsToSend = {}
for i, item in ipairs([Link]) do
local itemToSend = {
id = [Link],
type = [Link],
label = [Link],
rightLabel = [Link],
description = [Link],
list = [Link],
checked = [Link],
info = [Link]
}
[Link](itemsToSend, itemToSend)
end
SendNUIMessage({
eventName = "update_menu",
metadata = {
id = [Link],
title = [Link],
subtitle = [Link],
items = itemsToSend
}
})
end
end

function changeUi(ui)
currentUI = ui
SetResourceKvp("menu_ui_theme", ui)
SendNUIMessage({
eventName = "change_ui",
metadata = {
ui = ui
}
})
end

You might also like