1
function CountCops()

    local xPlayers = ESX.GetPlayers()

        CopsConnected = 0

        for i=1, #xPlayers, 1 do
            local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
            if xPlayer.job.name == 'police' then
              CopsConnected = CopsConnected + 1
            end
        end

    SetTimeout(120 * 1000, CountCops)
end

有谁知道如果 xPlayer.job.name == 'police' 或 xPlayer.job.name == 'sheriff' 为每个人读取 = 1 名警察,我将如何拥有两者。

因此,如果一名警察在场,则 = 1,如果一名警长在场,则 = 2。

4

1 回答 1

1
local countingJobs = {
    ['police'] = true,
    ['sheriff'] = true
};

function CountCops()
    local xPlayers = ESX.GetPlayers()
    CopsConnected = 0

    for i=1, #xPlayers, 1 do
        local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
        if countingJobs[xPlayer.job.name] then
            CopsConnected = CopsConnected + 1
        end
    end

    SetTimeout(120 * 1000, CountCops)
end
于 2020-08-31T22:38:02.650 回答