[How-to] Make Multiple Item Types & MORE in NativeUI

To make Multiple Item Types in NativeUI you must have each Item Type in the same Function and not separated. A example of which is as follows.

function Weapons(menu)
local submenu = _menuPool:AddSubMenu(menu, "Weapons Menu", "Sub Menu for Weapons") 
local gunsList = NativeUI.CreateListItem("Get Weapons", weapons, 1)
  submenu.OnListSelect = function(sender, item, index)  
      if item == gunsList then
          local selectedGun = item:IndexToItem(index)
          giveWeapon(selectedGun)
          notify("Gave Weapon: "..selectedGun)
    end
  end
    local click = NativeUI.CreateItem("~r~Clear Weapon(s)", "Clears Peds Weapons")
    local weapon = NativeUI.CreateItem("~b~Give all Weapons")
    submenu.OnItemSelect = function (sender, item, index)
      if item == click then
        RemoveAllPedWeapons(GetPlayerPed(-1), true)
        notify("~r~Removed All Weapon(s)")
      else if item == weapon then
        giveWeapon("weapon_knife")
      end
  end
end
submenu:AddItem(gunsList)
submenu:AddItem(weapon)
submenu:AddItem(click)
end

If you were to then go on and make a new submenu you can go on and do that in a seperate Function, but to have multiple of the same types in one submenu you must keep that in one single function with if and elseif statements.

NOTE: If you have any questions feel free to comment them, I am open for discussion. This is not the most in-depth because it’s not to to hard… but if you are confused (New to Programming) that is understandable and I am there to help.

If you wish to make SubMenu’s in SubMenu’s then do the following.

  • Change submenu to othermenu (ex local othermenu = _menuPool:AddSubMenu(submenu, "Test Menu", "" was originally local submenu = _menuPool:AddSubMenu(menu, "Weapons Menu", "Sub Menu for Weapons")
  • For submenu:AddItem() change submenu to othermenu

Example

local othermenu = _menuPool:AddSubMenu(submenu, "~b~Emergency Loadouts")
    local stateloadout = NativeUI.CreateItem("State Loadout", "Gives State Loadout")
    local hwayloadout = NativeUI.CreateItem("Highway Patrol Loadout", "Gives Highway Patrol Loadout")
    local coploadout = NativeUI.CreateItem("Police Loadout", "Gives Police Loadout")
    local sherloadout = NativeUI.CreateItem("Sheriff Loadout", "Gives Sheriff Loadout")
    local medloadout = NativeUI.CreateItem("EMT Loadout", "Gives EMT Loadout")
    local fireloadout = NativeUI.CreateItem("Fire Loadout", "Gives Fire Loadout")
    othermenu:AddItem(stateloadout)
    othermenu:AddItem(hwayloadout)
    othermenu:AddItem(coploadout)
    othermenu:AddItem(sherloadout)
    othermenu:AddItem(medloadout)
    othermenu:AddItem(fireloadout)
    othermenu.OnItemSelect = function(sender, item, index)
      if item == coploadout then
        if police then
          loaded = not loaded
          if loaded then
        loadModel("s_m_y_cop_01")
        giveWeapon("weapon_teargas")
        giveWeapon("weapon_combatpistol")
        giveWeapon("weapon_stungun")
        giveWeapon("weapon_pumpshotgun")
        giveWeapon("weapon_carbinerifle")
        giveWeapon("weapon_nightstick")
        giveWeapon("weapon_flashlight")
        notify("~b~Police Loadout Given")
      else
        RemoveAllPedWeapons(GetPlayerPed(-1), true)
        notify("~r~Loadout is now Removed")
      end
      else
        notify("~r~Permission not granted!")
      end
      else if item == stateloadout then
        if state then
          loaded2 = not loaded2
          if loaded2 then
          loadModel("s_m_y_sheriff_01")
          giveWeapon("weapon_teargas")
          giveWeapon("weapon_combatpistol")
          giveWeapon("weapon_stungun")
          giveWeapon("weapon_pumpshotgun")
          giveWeapon("weapon_carbinerifle")
          giveWeapon("weapon_nightstick")
          giveWeapon("weapon_flashlight")
          notify("~b~Sheriff Loadout Given: ")
        else
          RemoveAllPedWeapons(GetPlayerPed(-1), true)
          notify("~r~Loadout is now Removed")
        end
        else
          notify("~r~Permission not granted!")
        end
      else if item == sherloadout then
        if sheriff then
        loaded3 = not loaded3
        if loaded3 then
        loadModel("s_m_y_sheriff_01")
        giveWeapon("weapon_teargas")
        giveWeapon("weapon_combatpistol")
        giveWeapon("weapon_stungun")
        giveWeapon("weapon_pumpshotgun")
        giveWeapon("weapon_carbinerifle")
        giveWeapon("weapon_nightstick")
        giveWeapon("weapon_flashlight")
        notify("~b~Sheriff Loadout Given: ")
      else
        RemoveAllPedWeapons(GetPlayerPed(-1), true)
        notify("~r~Loadout is now Removed")
      end
      else
        notify("~r~Permission not granted!")
      end
      else if item == medloadout then
        if emt then
        loaded4 = not loaded4
        if loaded4 then
        loadModel("S_M_M_Paramedic_01")
      else
        RemoveAllPedWeapons(GetPlayerPed(-1), true)
        notify("~r~Loadout is now Removed")
      end
      else
        notify("~r~Permission not granted!")
      end
      else if item == fireloadout then
        if fire then
        loaded5 = not loaded5
        if loaded5 then
        loadModel("S_M_Y_Fireman_01")
        giveWeapon("weapon_flaregun")
        giveWeapon("weapon_fireextinguisher")
        giveWeapon("weapon_crowbar")
        notify("~b~Fire Loadout Given")
      else
        RemoveAllPedWeapons(GetPlayerPed(-1), true)
        notify("~r~Loadout is now Removed")
      end
      else
        notify("~r~Permission not granted!")
      end
    else if item == hwayloadout then
      if sheriff then
      loaded3 = not loaded3
      if loaded3 then
      giveWeapon("weapon_teargas")
      giveWeapon("weapon_combatpistol")
      giveWeapon("weapon_stungun")
      giveWeapon("weapon_pumpshotgun")
      giveWeapon("weapon_carbinerifle")
      giveWeapon("weapon_nightstick")
      giveWeapon("weapon_flashlight")
      notify("~b~Sheriff Loadout Given: ")
    else
      RemoveAllPedWeapons(GetPlayerPed(-1), true)
      notify("~r~Loadout is now Removed")
    end
    else
      notify("~r~Permission not granted!")
    end
              end
            end
          end
        end
      end
    end
  end
end

Could i just copy and paste this in and it would work?

So I’m looking to trigger an event when a specific item from an array is chosen. For example - I would have an array called doors. My code would look something like this. Can you tell me why this wouldn’t work? I feel like an idiot

local doorList = NativeUICreateListItem("Toggle Doors", doors, 1)
submenu.OnListSelect = function(sender, item, index)
        if item == doorList then
                 local selectedDoor = item:IndexToItem(index)
                          if selectedDoor = "Front Right" then
                                 TriggerEvent("frdoor")
                          end
      end

I just don’t understand why this wouldn’t work, and was wondering if someone could give me some advice here.