script_name('TOC')
script_authors('checkdasound', 'imring','Lapenko')
script_version('1.0')
local cc = {
    {
        4279826207, -- Grove
        4291237375, -- Ballas
        4294967040, -- Vagos
        4279228922, -- El Corona
        4292396898, -- LCN
        4286070681, -- Yakuza
        4286023833, -- RM
        4294910464, -- Triads
        4287102976, -- Outlaws
        4278550420, -- Coyotes
        4278220612, -- Hells Angels
        4279900698  -- Sons of Anarchy
    },
    {
        4279826207, -- Grove
        4291237375, -- Ballas
        4294967040, -- Vagos
        4279228922, -- El Corona
        4292396898, -- LCN
        4286070681, -- Yakuza
        4286023833, -- RM
        4294910464, -- Triads
        4287102976, -- Outlaws
        4278550420, -- Coyotes
        4278220612, -- Hells Angels
        4282006074  -- Sons of Anarchy
    }
}
local tt = {
    '{778899}---------------------------- {B0C4DE}ONLINE CHECKER{778899} ----------------------------\nBands: {$Col}Grove: $ONL {FFFFFF}| {$Col}Ballas: $ONL {FFFFFF}| {$Col}Vagos: $ONL {FFFFFF}| {$Col}El Corona: $ONL{FFFFFF}\nMafia: {$Col}LCN: $ONL {FFFFFF}| {$Col}Yakuza: $ONL {FFFFFF}| {$Col}Russian Mafia: $ONL {FFFFFF}| {$Col}Triads: $ONL {FFFFFF}\nBikers Club: {$Col}Outlaws: $ONL {FFFFFF}| {$Col}Coyotes: $ONL {FFFFFF}| {$Col}Hells Angels: $ONL {FFFFFF}| {$Col}{696969}SOA: $ONL',
    '{778899}---------------------------- {B0C4DE}ONLINE CHECKER{778899} ----------------------------\nBands: {$Col}Grove: $ONL {FFFFFF}| {$Col}Ballas: $ONL {FFFFFF}| {$Col}Vagos: $ONL {FFFFFF}| {$Col}El Corona: $ONL{FFFFFF}\nMafia: {$Col}LCN: $ONL {FFFFFF}| {$Col}Yakuza: $ONL {FFFFFF}| {$Col}Russian Mafia: $ONL {FFFFFF}| {$Col}Triads: $ONL {FFFFFF}\nBikers Club: {$Col}Outlaws: $ONL {FFFFFF}| {$Col}Coyotes: $ONL {FFFFFF}| {$Col}Hells Angels: $ONL {FFFFFF}| {$Col}{696969}SOA: $ONL'
}
function main()
    while not isSampAvailable() do wait(0) end
    while sampGetGamestate() ~= 3 do wait(0) end
    current_server = getCurrentServer(sampGetCurrentServerName())
    assert(current_server, 'Server not found.')
    sampRegisterChatCommand('gon', function()
        local t = tt[current_server]
        for i = 1, #cc[current_server] do
            local onl = 0
            local _, myid = sampGetPlayerIdByCharHandle(playerPed)
            if sampGetPlayerColor(myid) == cc[current_server][i] then onl = onl + 1 end
            for l = 0, sampGetMaxPlayerId(false) do
                if sampIsPlayerConnected(l) then
                    if sampGetPlayerColor(l) == cc[current_server][i] then onl = onl + 1 end
                end
            end
            t = t:gsub('$Col', ('%06X'):format(bit.band(cc[current_server][i], 0xFFFFFF)), 1)
            t = t:gsub('$ONL', onl, 1)
        end
        for vr in t:gmatch('[^\r\n]+') do sampAddChatMessage(vr, -1)end
    end)
    wait(-1)
end
function getCurrentServer(name)
    if name:find('Trinity Roleplay  №2') or name:find('Trinity Roleplay  №1') then return 1
    elseif name:find('Trinity RPG') then return 2
    end
end