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

Does anyone know how would I have both if xPlayer.job.name == 'police' or xPlayer.job.name == 'sheriff' read for = 1 cop for each person.

So if one police was on then it = 1 and if one sheriff was on it would = 2.

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64

1 Answers1

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
szkiddaj
  • 17
  • 4