[Help] Trying to create my own menu using NativeUILua-Reloaded

Hey all,

I’m looking for some help, I’m trying to have a custom menu work with my vehicle spawning resource I’ve created. I’m fairly new to the FiveM Resources, so whether it be something obvious or not. I do apologise within advance.

Currently the resource loads ok on the server, yet fails to open the menu when I load into my local server.

This is my fxmanifest.lua file

-- Resource Metadata
fx_version 'cerulean'
game 'gta5'

author 'LordGoose'
version '0.1'

--What to Run
client_scripts {
    '@NativeUILua-Reloaded-master/NativeUI.lua',
    'spawnVehicle-c.lua',
    'menu.lua'
}

This is my menu.lua

_menuPool = NativeUI.CreatePool()
mainMenu = NativeUI.CreateMenu("Vehicle Spawner", "Select any car within GTA5")
_menuPool:Add(mainMenu)



function FirstItem(menu) -- This lists the items within the menu for the player to pick from.
    --Vehicle Array (Military)
    local vehicles = {
        "barracks",
        "barracks2",
        "crusader",
        "rhino",
        "dinghy2",
        "cargobob",
        "titan",
        "buzzard2"
    }
    local vehicleList = NativeUI.CreateListItem("Select your Car", vehicles, 1)
    menu:AddItem(vehicleList)
    menu.OnListSelect = function(sender, item, index)
        if item == vehicleList then
            local selectedCar = item:IndexToItem(index)
            spawnVehicle(selectedCar)
        end
    end
end

FirstItem(mainMenu)
_menuPool:RefreshIndex()

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        _menuPool:ProcessMenus()
        if IsControlJustPressed(1, 288) then --This is the F1 Key
            mainMenu:Visible(not mainMenu:Visible())
        end
    end
end)

--SpawnVehicle
function spawnVehicle(carName)
    local car = GetHashKey(carName)

    RequestModel(carName)
    while not HasModelLoaded(carName) do
        RequestModel(carName)
        Citizen.Wait(1)
    end

    local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false))
    local vehicle = CreateVehicle(carName, x + 3, y + 3, z + 1, 
    GetEntityHeading(GetPlayerPed(-1)), true, false)
end

---CreatePool
function NativeUI.CreatePool()
    return MenuPool.New()
end

--CreateMenu
function NativeUI.CreateMenu(Title, Subtitle, X, Y, TxtDictionary, TxtName, Heading, R, G, B, A)
    return UIMenu.New(Title, Subtitle, X, Y, TxtDictionary, TxtName, Heading, R, G, B, A)
end

---CreateListItem
---@param Text string
---@param Items number
---@param Index table
---@param Description string
function NativeUI.CreateListItem(Text, Items, Index, Description)
    return UIMenuListItem.New(Text, Items, Index, Description)
end

Again thanks in advance!

if IsControlJustPressed(1, 288) then --This is the F1 Key
    mainMenu:Visible(not mainMenu:Visible())
end

Have you made sure that this is actually getting called?
I believe the F1 key on keyboard is actually

IsControlJustPressed(0, 288)

I would suggest adding a print and making sure its called. e.g.

if IsControlJustPressed(0, 288) then --This is the F1 Key
    print('F1 Key was pressed')
    mainMenu:Visible(not mainMenu:Visible())
end

Thanks for the reply.

Since posting, I did use a trigger to try and debug, and also changed the Key from F1(288), To Q (52). This still didn’t work, but I’ve tried setting the padIndex from 1, to 0 to see if this helps.

This is now my menu.lua

_menuPool = NativeUI.CreatePool()
mainMenu = NativeUI.CreateMenu("Native UI", "~b~NATIVEUI SHOWCASE", nil, nil, nil, nil, nil, 255, 255, 255, 210)
_menuPool:Add(mainMenu)

--SpawnVehicle
function spawnVehicle(carName)
    local car = GetHashKey(carName)

    RequestModel(carName)
    while not HasModelLoaded(carName) do
        RequestModel(carName)
        Citizen.Wait(1)
    end

    local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false))
    local vehicle = CreateVehicle(carName, x + 3, y + 3, z + 1, 
    GetEntityHeading(GetPlayerPed(-1)), true, false)
end

function militaryVehicle(menu) -- This lists the items within the menu for the player to pick from.
    --Vehicle Array (Military)
    local vehicles = {
        "barracks", "barracks2", "crusader", "rhino",
        "dinghy2", "cargobob", "titan", "buzzard2"
    }
    local vehicleList = NativeUI.CreateListItem("Select your Car", vehicles, 1)
    menu:AddItem(vehicleList)
    menu.OnListChange = function(sender, item, index)
        if item == vehicleList then
            selectedCar = item:IndexToItem(index)
            spawnVehicle(selectedCar)
        end
    end
end

militaryVehicle(mainMenu)
_menuPool:RefreshIndex()

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(1)
        _menuPool:ProcessMenus()
        if IsControlJustPressed(0, 52) then
            TriggerEvent("chatMessage", "Menu key pressed")
            mainMenu:Visible(not mainMenu:Visible())
        end
    end
end)

Okay sorry to hear the didnt help.

Generally speaking, a pad index of 0 is for keyboard controls and a pad index of 2 is for controller.

1 Like

Ok, thanks.

I’m still trying to get this working. But I’m sure I’ll figure it out eventually :smiley:

I resolved this by going back to this version of NativeUI

Changed the folder name to just “NativeUI” and updated my fxmanifest.lua to be this:

-- Resource Metadata
fx_version 'cerulean'
game 'gta5'

author 'LordGoose'
version '0.1'

--What to Run
client_scripts {
    '@NativeUI/NativeUI.lua',
    'menu.lua'
}