1
Citizen.CreateThread(function()
    while true do 
        Citizen.Wait(0)
        local playerPed = GetPlayerPed()
        local rank = exports.XpM:XPM_GetRank() --Gets the rank of the player from XP system XpM
print('Rank:' .. rank)
        if rank>50 then
          EighthItem(mainMenu) --All the different menu available for the player to choose vehicles from
          FifthItem(mainMenu)
          SixthItem(mainMenu)
          ThirdItem(mainMenu)
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        elseif rank>40 then
          FifthItem(mainMenu)
          SixthItem(mainMenu)
          ThirdItem(mainMenu)
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        elseif rank>30 then
          SixthItem(mainMenu)
          ThirdItem(mainMenu)
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        elseif rank>20 then
          ThirdItem(mainMenu)
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        else
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        end
       _menuPool:RefreshIndex()
    end
end)
Citizen.CreateThread(function()
    while true do   --
        Citizen.Wait(0)
        _menuPool:ProcessMenus()
        if not IsPedInAnyVehicle(PlayerPedId()) and IsControlJustPressed(1, 243) then  --Console
            mainMenu:Visible(not mainMenu:Visible())
        elseif IsPedInAnyVehicle(PlayerPedId()) and IsControlJustPressed(1, 243) then  --Console
            exports['mythic_notify']:SendAlert('error', 'Player is in Vehicle')
        end
    end
end)

此代码用于通过菜单生成车辆,但在运行代码时菜单会无限循环。rank参数用于为具有一定级别的人打开特定的车辆类别。玩家的排名与 XP 系统脚本链接,并在打开菜单之前检索以检查排名并相应地提供可用类别

4

1 回答 1

0

只需创建一个布尔变量来定义循环是否已经运行。

例子:

local LoopRan = false
Citizen.CreateThread(function()
 while true do
  while LoopRan == false do
   -- Do things
   LoopRan = true
   Citizen.Wait(1337)
  end
 end
end)
于 2021-11-15T09:09:30.963 回答