0

我正在创建一个独立的车辆附加菜单。我遇到的问题是,如果我生成汽车 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()
4

1 回答 1

0

解决它

        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```
于 2020-02-29T04:16:45.850 回答