[Release][Dev] NativeUILua

Is it possible to create a “main menu” script and then several other scripts as sub menus? Or do I need to have everything in one single script?

This is one of the things I’ve tried. Both scripts are in the same folder and got their respective entry in the __resource.lua

Main script (working as intended):

_menuPool = NativeUI.CreatePool()
mainMenu = NativeUI.CreateMenu("LLS Menü", "~b~Hauptmenü")
_menuPool:Add(mainMenu)

-- Output info as chat message (used for debugging)
function Chat(t)
    TriggerEvent("chatMessage", "DEBUG", {255, 0, 0}, "" .. tostring(t))
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        
        -- do menu things
        _menuPool:ProcessMenus()
        if IsControlJustReleased(0, Keys['F5']) then            
            GenerateMenu(mainMenu)
            mainMenu:Visible(not mainMenu:Visible())
        end
    end
end)

function GenerateMenu(menu)
	menu:Clear()
    
    local newitemChat = NativeUI.CreateItem("Trigger Chat Message", "Trigger Chat Message Description")
    menu:AddItem(newitemChat)
    
    menu.OnItemSelect = function(sender, item, index)
        if item == newitemChat then
            Chat("This menu works")
        end
    end
    
    -- refresh menu index
    _menuPool:RefreshIndex()
end

“sub script” (not working at all):

vehicleMenu = _menuPool:AddSubMenu(mainMenu, "> Fahrzeug Funktionen")
_menuPool:Add(vehicleMenu)

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        
        local newitemSubChat = NativeUI.CreateItem("Trigger Chat Message Sub", "Trigger Chat Message Sub Description")
        vehicleMenu:AddItem(newitemSubChat)
        
        vehicleMenu.OnItemSelect = function(sender, item, index)
            if item == newitemSubChat then
                Chat("This Sub Menu works")
            end
        end
    end
end)

And my goal is it, to get it working with independent scripts. Kinda like having “mainMenu”, “vehicleMenu”, “helpMenu” and so on without them having to be all in the same resource. This way, you can disable one of them without everything else being affected (except the main menu of course).

1 Like

Is it possible to trigger an event inside a submenu item. Such as

function AddMenuWeapons(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Weapons")
	for i = 1, 1 do
        submenu:AddItem(NativeUI.CreateItem("Glock 17", "Equip a glock 17.")) then
		TriggerEvent("glock17")
	end
function AddMenuWeapons(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Weapons")
	for i = 1, 1 do
        local item = NativeUI.CreateItem("Glock 17", "Equip a glock 17.")
        item.Activated = function(ParentMenu, SelectedItem)
           TriggerEvent("glock17")
        end
        submenu:AddItem(item)
	end

So to do multiple items I would do this

function AddMenuWeapons(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Weapons")
	for i = 1, 1 do
        local item = NativeUI.CreateItem("Glock 17", "Equip a glock 17.")
        item.Activated = function(ParentMenu, SelectedItem)
           TriggerEvent("glock17")
        end
        local item = NativeUI.CreateItem("gun2", "Equip gun2.")
        item.Activated = function(ParentMenu, SelectedItem)
           TriggerEvent("glock17")
        end
        submenu:AddItem(item)
        submenu:AddItem(item2)
	end

Okay that works, thanks very much man!

Also I’m curious about something is it possible to have a menu inside another menu, such as

function AddMenuWeapons(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Weapons")
	for i = 1, 1 do
	    local submenu = _menuPool:AddSubMenu(menu, "Pistols")
            local submenu = _menuPool:AddSubMenu(menu, "Shotguns")

Yes its possible. 2020

Okay thanks, I’ll look into it and try to do it, I’m writing a loadout menu for cops.

Hello i don’t know if its the best place for support but i actualy doing a Personal Menu with a menu Animations andin this Animation Menu, a put 5 Sub Menu to place the Animations.

But im stuck at this point because i don’t know how to put the animations in and how to do them work.
I looked into other Animations Menu but im lost, i new in the LUA and i need some help on understand gta code !

Here its the code (Its a French code because i’m French :slight_smile: ) :

-- Creer le parent des menus  avec un titre en gros et un petit pour la barre des titres --
_menuPool = NativeUI.CreatePool()
mainMenu = NativeUI.CreateMenu("Menu Personnel", "~b~Menu personnel", 1320, 0)
_menuPool:Add(mainMenu)

-- Creer un menu nommé InventaireMenu --
function InventaireMenu(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Inventaire")
    submenu:AddItem(NativeUI.CreateItem("Appuyer va déclancher une notification", "Déclenchement d'une notification !"))
end

-- Creer un menu nommé PortefeuilleMenu --
function PortefeuilleMenu(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Portefeuille")
end

-- Creer un menu nommé VetementMenu --
function VetementMenu(menu)
	local submenu = _menuPool:AddSubMenu(menu, "Vêtement")
	local lunette = {
		"Lunette 1",
		"Lunette 2",
	}
	local newitem = NativeUI.CreateListItem("Lunette", lunette, 1)
	submenu:AddItem(newitem)
	menu.OnListChange = function(sender, item, index)
		if item == newitem then
			dish = item:IndexToItem(index)
			ShowNotification("Vous avez remis vos ~b~" .. dish .. "~w~.")
		end
	end
	local chapeau = {
		"Chapeau 1",
		"Chapeau 2",
	}
	local newitem = NativeUI.CreateListItem("Chapeau", chapeau, 1)
	submenu:AddItem(newitem)
	menu.OnListChange = function(sender, item, index)
		if item == newitem then
			dish = item:IndexToItem(index)
			ShowNotification("Vous avez remis votre ~b~" .. dish .. "~w~.")
		end
	end
end

-- Creer un menu nommé AnimationMenu --
function AnimationMenu(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Animations")
	submenu:AddItem(NativeUI.CreateItem("Saluer", ""))
	submenu:AddItem(NativeUI.CreateItem("Humeur", ""))
	submenu:AddItem(NativeUI.CreateItem("Sportives", ""))
	submenu:AddItem(NativeUI.CreateItem("Festives", ""))
	submenu:AddItem(NativeUI.CreateItem("Autres", ""))
end

-- Creer un menu nommé GestionvehiculeMenu --
function GestionvehiculeMenu(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Gestion véhicule")
	submenu:AddItem(NativeUI.CreateItem("Allumer/Eteindre le moteur", ""))
	submenu:AddItem(NativeUI.CreateItem("Donner un double des clés", ""))
	submenu:AddItem(NativeUI.CreateItem("Ouvrir coffre", ""))
	submenu:AddItem(NativeUI.CreateItem("Ouvrir capôt avant", ""))
end

-- Creer un menu nommé GestionvehiculeMenu --
function DemarcheMenu(menu)
    local demarche = {
        "Nom de la démarche 1",
        "Nom de la démarche 2",
        "Nom de la démarche 3",
        "Nom de la démarche 4",
        "Nom de la démarche 5",
        "Nom de la démarche 6",
    }
    local newitem = NativeUI.CreateListItem("Démarche", demarche, 1)
    menu:AddItem(newitem)
    menu.OnListChange = function(sender, item, index)
        if item == newitem then
            dish = item:IndexToItem(index)
            ShowNotification("Changement de la démarche en ~b~" .. dish .. "~w~.")
        end
    end
end

-- Creer un menu nommé VoixMenu --
function VoixMenu(menu)
    local voix = {
        "Faible",
        "Normal",
        "Forte",
    }
    local newitem = NativeUI.CreateListItem("Niveau de la voix", voix, 1)
    menu:AddItem(newitem)
    menu.OnListChange = function(sender, item, index)
        if item == newitem then
            dish = item:IndexToItem(index)
            ShowNotification("Niveau de la voix : ~b~" .. dish .. "~w~.")
        end
    end
end

-- Creer un menu nommé ParametreMenu --
function ParametreMenu(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Paramètres")
	submenu:AddItem(NativeUI.CreateItem("Menu 1", ""))
	submenu:AddItem(NativeUI.CreateItem("Menu 2", ""))
	submenu:AddItem(NativeUI.CreateItem("Menu 3", ""))
	submenu:AddItem(NativeUI.CreateItem("Menu 4", ""))
	submenu:AddItem(NativeUI.CreateItem("Menu 5", ""))
end

-- Creer un menu nommé SauvegardepositionMenu --
function SauvegardepositionMenu(menu)
    local submenu = _menuPool:AddSubMenu(menu, "Sauvegarder votre position")
end

-- Raccourcis pour les menus au lieu de les appeler a chaque fois --
InventaireMenu(mainMenu)
PortefeuilleMenu(mainMenu)
VetementMenu(mainMenu)
AnimationMenu(mainMenu)
GestionvehiculeMenu(mainMenu)
DemarcheMenu(mainMenu)
VoixMenu(mainMenu)
ParametreMenu(mainMenu)
SauvegardepositionMenu(mainMenu)
_menuPool:RefreshIndex()

-- Ouvrir le menu via F5 --
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        _menuPool:ProcessMenus()
        if IsControlJustPressed(1, 167) then
            mainMenu:Visible(not mainMenu:Visible())
        end
    end
end)

-- Fonction utiles --
function DrawPlayerInfo(target)
	drawTarget = target
	drawInfo = true
end

function StopDrawPlayerInfo()
	drawInfo = false
	drawTarget = 0
end

function ShowNotification(text)
    SetNotificationTextEntry("STRING")
    AddTextComponentString(text)
    DrawNotification(false, false)
end
1 Like

Anyone know where to change the title rectangle colour? I’m assuming it’s in NativeUI.lua.

Also where can I move the coordinates of the menu, rather than me going through all the code.

At this line : NativeUI.CreateMenu(Title, Subtitle, X, Y, TxtDictionary, TxtName) create a UIMenu

When you see 1320 if you decrease it will go to the left.
I think 0.10 is a good position !

Thanks mate! Just running into a few issues, the coordinates are showing below in the description when I select it.

@BabbaTundaee You can edit your posts… You don’t have to remove them and create new ones…

Yeah I know, but couldn’t be assed :joy:

need more example…

how to set right label at sub menu???
like “>>” to mark this is a sub menu…

and how to create a dynamic menu…
like “online player”…

thanks…

Hello I was wondering how I could make this work with markers on the ground. So when I go into a marker the button will show and when you aren’t in the marker it isn’t on the menu. I am using

if CurrentActionJobs == ‘clockin’ then
end

anyone have any solutions to my problem?

Honestly I don’t understand what your problem is?

1 Like

I want it so the menu will work with markers, when I enter a button will show and when I leave the marker the button will remove.

heres a link of what my other menu does https://vimeo.com/272037742