使用 NUI 的 FiveM 车辆额外列表
FiveM Vehicle Extra List using NUI
我正在创建一个独立的车辆附加菜单。我遇到的问题是,如果我生成汽车 A 并且它有 4 个额外选项,它们可以正常工作。但是如果我生成汽车 B 并且它有 8 个,菜单仍然只会显示前一个汽车 A 的 4 个。无论我离开汽车 A 还是删除它都是如此。有什么想法可以重置它以读取正确的车辆吗?
local AvailableExtras = {['VehicleExtras'] = {}}
local Items = {['Vehicle'] = {}}
local MenuExists, Vehicle
_menuPool = NativeUI.CreatePool()
mainMenu = NativeUI.CreateMenu("Vehicle Extras", "~b~Select Extras")
_menuPool:Add(mainMenu)
_menuPool:MouseControlsEnabled (false);
_menuPool:MouseEdgeEnabled (false);
_menuPool:ControlDisablingEnabled(false);
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
_menuPool:MouseControlsEnabled (false);
_menuPool:MouseEdgeEnabled (false);
_menuPool:ControlDisablingEnabled(false)
_menuPool:ProcessMenus()
if IsControlJustPressed(1, 56) then
mainMenu:Visible(not mainMenu:Visible())
end
end
end)
function Extras(menu)
local AvailableExtras = {['VehicleExtras'] = {}}
local Items = {['Vehicle'] = {}}
local MenuExists
local Vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local GotVehicleExtras = false
for ExtraID = 0, 20 do
if DoesExtraExist(Vehicle, ExtraID) then
AvailableExtras.VehicleExtras[ExtraID] = (IsVehicleExtraTurnedOn(Vehicle, ExtraID) == 1)
GotVehicleExtras = true
end
end
-- Vehicle Extras
if GotVehicleExtras then
for Key, Value in pairs(AvailableExtras.VehicleExtras) do
local ExtraItem = NativeUI.CreateCheckboxItem('Extra ' .. Key, AvailableExtras.VehicleExtras[Key],Vehicle)
mainMenu:AddItem(ExtraItem)
Items.Vehicle[Key] = ExtraItem
end
menu.OnCheckboxChange = function(Sender, Item, Checked)
for Key, Value in pairs(Items.Vehicle) do
if Item == Value then
AvailableExtras.VehicleExtras[Key] = Checked
if AvailableExtras.VehicleExtras[Key] then
SetVehicleExtra(Vehicle, Key, 0)
else
SetVehicleExtra(Vehicle, Key, 1)
end
end
end
end
end
end
Extras(mainMenu)
_menuPool:RefreshIndex()
已修复
while true do
Citizen.Wait(0)
_menuPool:MouseControlsEnabled (false);
_menuPool:MouseEdgeEnabled (false);
_menuPool:ControlDisablingEnabled(false)
_menuPool:ProcessMenus()
if IsControlJustPressed(1, 56) then
Extras(mainMenu)
mainMenu:Visible(not mainMenu:Visible())
end
end
end)
function Extras(menu)
mainMenu:Clear()
local AvailableExtras = {['VehicleExtras'] = {}}
local Items = {['Vehicle'] = {}}
local MenuExists
local Vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local GotVehicleExtras = false
for ExtraID = 0, 20 do
if DoesExtraExist(Vehicle, ExtraID) then
AvailableExtras.VehicleExtras[ExtraID] = (IsVehicleExtraTurnedOn(Vehicle, ExtraID) == 1)
GotVehicleExtras = true
end
end
-- Vehicle Extras
if GotVehicleExtras then
for Key, Value in pairs(AvailableExtras.VehicleExtras) do
local ExtraItem = NativeUI.CreateCheckboxItem('Extra ' .. Key, AvailableExtras.VehicleExtras[Key],"Enable or Disable Extras")
mainMenu:AddItem(ExtraItem)
Items.Vehicle[Key] = ExtraItem
end
menu.OnCheckboxChange = function(Sender, Item, Checked)
for Key, Value in pairs(Items.Vehicle) do
if Item == Value then
AvailableExtras.VehicleExtras[Key] = Checked
if AvailableExtras.VehicleExtras[Key] then
SetVehicleExtra(Vehicle, Key, 0)
else
SetVehicleExtra(Vehicle, Key, 1)
end
end
end
end
end
end```
我正在创建一个独立的车辆附加菜单。我遇到的问题是,如果我生成汽车 A 并且它有 4 个额外选项,它们可以正常工作。但是如果我生成汽车 B 并且它有 8 个,菜单仍然只会显示前一个汽车 A 的 4 个。无论我离开汽车 A 还是删除它都是如此。有什么想法可以重置它以读取正确的车辆吗?
local AvailableExtras = {['VehicleExtras'] = {}}
local Items = {['Vehicle'] = {}}
local MenuExists, Vehicle
_menuPool = NativeUI.CreatePool()
mainMenu = NativeUI.CreateMenu("Vehicle Extras", "~b~Select Extras")
_menuPool:Add(mainMenu)
_menuPool:MouseControlsEnabled (false);
_menuPool:MouseEdgeEnabled (false);
_menuPool:ControlDisablingEnabled(false);
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
_menuPool:MouseControlsEnabled (false);
_menuPool:MouseEdgeEnabled (false);
_menuPool:ControlDisablingEnabled(false)
_menuPool:ProcessMenus()
if IsControlJustPressed(1, 56) then
mainMenu:Visible(not mainMenu:Visible())
end
end
end)
function Extras(menu)
local AvailableExtras = {['VehicleExtras'] = {}}
local Items = {['Vehicle'] = {}}
local MenuExists
local Vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local GotVehicleExtras = false
for ExtraID = 0, 20 do
if DoesExtraExist(Vehicle, ExtraID) then
AvailableExtras.VehicleExtras[ExtraID] = (IsVehicleExtraTurnedOn(Vehicle, ExtraID) == 1)
GotVehicleExtras = true
end
end
-- Vehicle Extras
if GotVehicleExtras then
for Key, Value in pairs(AvailableExtras.VehicleExtras) do
local ExtraItem = NativeUI.CreateCheckboxItem('Extra ' .. Key, AvailableExtras.VehicleExtras[Key],Vehicle)
mainMenu:AddItem(ExtraItem)
Items.Vehicle[Key] = ExtraItem
end
menu.OnCheckboxChange = function(Sender, Item, Checked)
for Key, Value in pairs(Items.Vehicle) do
if Item == Value then
AvailableExtras.VehicleExtras[Key] = Checked
if AvailableExtras.VehicleExtras[Key] then
SetVehicleExtra(Vehicle, Key, 0)
else
SetVehicleExtra(Vehicle, Key, 1)
end
end
end
end
end
end
Extras(mainMenu)
_menuPool:RefreshIndex()
已修复
while true do
Citizen.Wait(0)
_menuPool:MouseControlsEnabled (false);
_menuPool:MouseEdgeEnabled (false);
_menuPool:ControlDisablingEnabled(false)
_menuPool:ProcessMenus()
if IsControlJustPressed(1, 56) then
Extras(mainMenu)
mainMenu:Visible(not mainMenu:Visible())
end
end
end)
function Extras(menu)
mainMenu:Clear()
local AvailableExtras = {['VehicleExtras'] = {}}
local Items = {['Vehicle'] = {}}
local MenuExists
local Vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local GotVehicleExtras = false
for ExtraID = 0, 20 do
if DoesExtraExist(Vehicle, ExtraID) then
AvailableExtras.VehicleExtras[ExtraID] = (IsVehicleExtraTurnedOn(Vehicle, ExtraID) == 1)
GotVehicleExtras = true
end
end
-- Vehicle Extras
if GotVehicleExtras then
for Key, Value in pairs(AvailableExtras.VehicleExtras) do
local ExtraItem = NativeUI.CreateCheckboxItem('Extra ' .. Key, AvailableExtras.VehicleExtras[Key],"Enable or Disable Extras")
mainMenu:AddItem(ExtraItem)
Items.Vehicle[Key] = ExtraItem
end
menu.OnCheckboxChange = function(Sender, Item, Checked)
for Key, Value in pairs(Items.Vehicle) do
if Item == Value then
AvailableExtras.VehicleExtras[Key] = Checked
if AvailableExtras.VehicleExtras[Key] then
SetVehicleExtra(Vehicle, Key, 0)
else
SetVehicleExtra(Vehicle, Key, 1)
end
end
end
end
end
end```