I tried to make my own NUI (wiew code .lua). But something wasn’t right.
Explain: I made 4 items in the mainMenu (FirstItem, SecondItem, ThirdItem, FourthItem). FirstItem is to clear all Weapons, SeconItem is to give full health, ThirdItem is a list of weapon that one want to get and FourthItem is a subMenu that is to spawn vehicle and decide seat. well all of the functions worked well but, the problem is here: FirstItem didn’t work if I put it in the first order of the menu list. So I tried to switch order, I put SecondItem in the first order of the mainMenu and FirstItem in the second order of the mainMenu. Then, the SecondItem that in the first order didn’t work but, the FirstItem that in the second order worked. Afterthat, I tried to make a BaitItem and put it in the top of the mainMenu. Then, only the FirstItem (in the third order) together with ThirdItem and FourthItem worked. The BaitItem (in the first order) and SecondItem (in the second order) didn’t work. Now I come to the conclusion that only 1 item in the order above ThirdItem and FourthItem worked. And I couldn’t find the mistake.
_menuPool = NativeUI.CreatePool()
mainMenu = NativeUI.CreateMenu("Main Menu", "~b~Assist")
_menuPool:Add(mainMenu)
_menuPool:MouseControlsEnabled(false)
_menuPool:MouseEdgeEnabled(false)
_menuPool:ControlDisablingEnabled(false);
-- BaitItem
function BaitItem(menu)
local click = NativeUI.CreateItem("Bait", "~r~Try this")
menu:AddItem(click)
menu.OnItemSelect = function(sender, item, index)
if item == click then
notify("~r~Damn")
end
end
end
-- firstItem
function FirstItem(menu)
local click = NativeUI.CreateItem("Clear Weapons", "~r~Clear all Weapons")
menu:AddItem(click)
menu.OnItemSelect = function(sender, item, index)
if item == click then
RemoveAllPedWeapons(GetPlayerPed(-1), true)
notify("~r~Cleared.")
end
end
end
-- secondItem
function SecondItem(menu)
local click = NativeUI.CreateItem("Heal me", "~g~Heal yourself")
menu:AddItem(click)
menu.OnItemSelect = function(sender, item, index)
if item == click then
SetEntityHealth(PlayerPedId(), 200)
notify("~g~Healed.")
end
end
end
-- Used in "ThirdItem"
sniper = "weapon_sniperrifle"
weapons = {
sniper,
"weapon_pistol",
"weapon_microsmg",
"weapon_flashlight"
}
function ThirdItem(menu)
local gunsList = NativeUI.CreateListItem("Get Guns", weapons, 1)
menu:AddItem(gunsList)
menu.OnListSelect = function(sender, item, index)
if item == gunsList then
local selectedGun = item:IndexToItem(index)
giveWeapon(selectedGun)
notify("spawned in a "..selectedGun)
end
end
end
-- used in "FourthItem"
cars = {
"TriBike",
"Sanchez",
"F620"
}
seats = {-1,0,1,2}
function FourthItem(menu)
local submenu = _menuPool:AddSubMenu(menu, "~b~Sub Menu")
local carList = NativeUI.CreateListItem("Spawn Vehicle", cars, 1)
submenu:AddItem(carList)
_menuPool:MouseControlsEnabled(false)
_menuPool:MouseEdgeEnabled(false)
_menuPool:ControlDisablingEnabled(false);
submenu.OnListSelect = function(sender, item, index)
if item == carList then
local selectedCar = item:IndexToItem(index)
spawnCar(selectedCar)
notify("spawned in "..selectedCar)
end
end
local seat = NativeUI.CreateSliderItem("Change seat", seats, 1)
submenu.OnSliderChange = function(sender, item, index)
if item == seat then
vehSeat = item:IndexToItem(index)
local pedsCar = GetVehiclePedIsIn(GetPlayerPed(-1),false)
SetPedIntoVehicle(PlayerPedId(), pedsCar, vehSeat)
end
end
submenu:AddItem(seat)
end
-- Menu List display order **
--BaitItem(mainMenu)
FirstItem(mainMenu)
SecondItem(mainMenu)
BaitItem(mainMenu)
ThirdItem(mainMenu)
FourthItem(mainMenu)
_menuPool:RefreshIndex()
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
_menuPool:ProcessMenus()
--[[ The "F1" button will activate the menu ]]
if IsControlJustPressed(1, 288) then
mainMenu:Visible(not mainMenu:Visible())
end
end
end)
--[[ Function ]]
function notify(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(true, true)
end
function giveWeapon(hash)
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey(hash), 999, false, false)
end
function spawnCar(car)
local car = GetHashKey(car)
RequestModel(car)
while not HasModelLoaded(car) do
RequestModel(car)
Citizen.Wait(50)
end
local x, y, z = table.unpack(GetEntityCoords(PlayerPedId(), false))
local vehicle = CreateVehicle(car, x + 2, y + 2, z + 1, GetEntityHeading(PlayerPedId()), true, false)
SetPedIntoVehicle(PlayerPedId(), vehicle, -1)
SetEntityAsNoLongerNeeded(vehicle)
SetModelAsNoLongerNeeded(vehicleName)
--[[ SetEntityAsMissionEntity(vehicle, true, true) ]]
end