使用NUI的五辆汽车额外清单

问题描述 投票:0回答:1

我正在创建一个独立的车辆附加菜单。我遇到的问题是,如果我生成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()
lua grand-theft-auto
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```
© www.soinside.com 2019 - 2024. All rights reserved.