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!