• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X Order MC command

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
How to order /mc command? (the default that comes on tfs)

This command that show players with MCs, but it is a mess

It shows something like:
Code:
20:50 Currently online players with same IP address(es):
20:50 Jizz Draco (XXX.XXX.XXX.XXX)
20:50 Ygorxx (YYYY.YYYY.YYYY.YYYY)
20:50 Diegothais (XXX.XXX.XXX.XXX)
20:50 Casual Nisse (WWWW.WWWW.WWWW.WWWW)
20:50 Kiss of dragon (ZZZZ.ZZZZ.ZZZZ.ZZZZ)
20:50 Chimone (WWWW.WWWW.WWWW.WWWW)
20:50 Mutant Pizza (XXX.XXX.XXX.XXX)
20:50 Raylover (ZZZZ.ZZZZ.ZZZZ.ZZZZ)
20:50 Albus Elvan (ZZZZ.ZZZZ.ZZZZ.ZZZZ)
20:50 Dalith Knight (XXX.XXX.XXX.XXX)
20:50 Happy Stepping (XXX.XXX.XXX.XXX)
20:50 Phaina Panda (ZZZZ.ZZZZ.ZZZZ.ZZZZ)
20:50 Rio Knigth (ZZZZ.ZZZZ.ZZZZ.ZZZZ)
20:50 Professor Demzy (XXX.XXX.XXX.XXX)
20:50 Psydabb (ZZZZ.ZZZZ.ZZZZ.ZZZZ)
20:50 Droxen (YYYY.YYYY.YYYY.YYYY)
20:50 Maicon Tchuf Tchaf (ZZZZ.ZZZZ.ZZZZ.ZZZZ)

I would like to order with something like:
Code:
20:50 Currently online players with same IP address(es):

XXX.XXX.XXX.XXX - 6
20:50 (1) Jizz Draco
20:50 (2) Diegothais
20:50 (3) Mutant Pizza
20:50 (4) Dalith Knight
20:50 (5) Happy Stepping
20:50 (6) Professor Demzy

WWWW.WWWW.WWWW.WWWW - 2
20:50 (1) Casual Nisse
20:50 (2) Chimone 

YYYY.YYYY.YYYY.YYYY - 2
20:50 (1) Ygorxx
20:50 (2) Droxen

ZZZZ.ZZZZ.ZZZZ.ZZZZ - 7
20:50 (1) Kiss of dragon
20:50 (2) Raylover
20:50 (3) Albus Elvan
20:50 (4) Phaina Panda
20:50 (5) Rio Knigth
20:50 (6) Psydabb
20:50 (7) Maicon Tchuf Tchaf
 
Solution
We just need to order table in the opposite way, so to speak
Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

function onSay(cid, words, param, channel)
    local _ip = nil
    if(param ~= '') then
        _ip = tonumber(param)
        if(not _ip or _ip == 0) then
            local revertIp = doRevertIp(param)
            if(not revertIp) then
                local tid =...
Server version?
Edit: Nvm, just saw it's tagged with 0.x - give me a little bit and I'll post a script here

Not my code, but this should work roughly how you want it
Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

local function getTarget(cid)
    local target = getCreatureTarget(cid)
    if target ~= 0 then
        target = ' | Target: ' .. getCreatureName(target)
        else
        target = ''
    end
    return target
end

function onSay(cid, words, param, channel)
    if not getPlayerByNameWildcard(param) then
        return doPlayerSendCancel(cid, "You have to enter a valid param.")
    end

    local _ip = nil
    if param ~= nil then
        _ip = tonumber(param)
        if not _ip or _ip == 0 then
            local revertIp = doRevertIp(param)
            if not revertIp then
                local tid = getPlayerByNameWildcard(param)
                if not tid then
                    _ip = nil
                else
                    _ip = getPlayerIp(tid)
                end
            else
                _ip = doConvertIpToInteger(revertIp)
            end
        end
    end

    local list, ips, forb = {}, {}, {}
    local players = getPlayersOnline()
    local userAccess = getPlayerAccess(cid)
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        if getPlayerAccess(pid) >= userAccess then
            table.insert(forb, ip)
        end
        
        if table.contains(ips, ip) and (not _ip or _ip == ip) then
            if table.count(list, ip) == 0 then
                list[players[ip]] = ip
            end
            list[pid] = ip
        end

        table.insert(ips, ip)
    end
    
    local keys = {}
    for k in pairs(list) do
        keys[#keys+1] = k
    end

    local mcs = {}
    for k, v in pairs(list) do
        if not table.contains(mcs, v) then
            mcs[#mcs+1] = v
        end
    end

    local text = ""
    local countOfMsgs = 0
    local delayOfMsgs = 25
    
    if table.maxn(list) > 0 then
        if _ip == nil or (_ip ~= nil and not table.contains(forb, _ip)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Currently there are [" .. #keys .. "] characters with same IP address(es):")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")            
        end

        for pid, ip in spairs(list, function(t,a,b) return t[b] < t[a] end) do
            if not table.contains(forb, ip) then
                text = text .. "\n" ..  "[" .. doConvertIntegerToIp(ip) .. "] " .. getCreatureName(pid) .. getTarget(pid)

                if text:len() > 350 then
                    addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
                    countOfMsgs = countOfMsgs + 1
                    text = ""
                end
            end
        end
        
        if text:len() > 0 then
            addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
            countOfMsgs = countOfMsgs + 1
            text = ""
        end    

        if _ip == nil then
            addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'There are ' .. #getPlayersOnline() - #keys + #mcs .. ' unique IP addresses.')
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end

    return true
end
 
Last edited:
Server version?
Edit: Nvm, just saw it's tagged with 0.x - give me a little bit and I'll post a script here

Not my code, but this should work roughly how you want it
Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

local function getTarget(cid)
    local target = getCreatureTarget(cid)
    if target ~= 0 then
        target = ' | Target: ' .. getCreatureName(target)
        else
        target = ''
    end
    return target
end

function onSay(cid, words, param, channel)
    if not getPlayerByNameWildcard(param) then
        return doPlayerSendCancel(cid, "You have to enter a valid param.")
    end

    local _ip = nil
    if param ~= nil then
        _ip = tonumber(param)
        if not _ip or _ip == 0 then
            local revertIp = doRevertIp(param)
            if not revertIp then
                local tid = getPlayerByNameWildcard(param)
                if not tid then
                    _ip = nil
                else
                    _ip = getPlayerIp(tid)
                end
            else
                _ip = doConvertIpToInteger(revertIp)
            end
        end
    end

    local list, ips, forb = {}, {}, {}
    local players = getPlayersOnline()
    local userAccess = getPlayerAccess(cid)
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        if getPlayerAccess(pid) >= userAccess then
            table.insert(forb, ip)
        end
       
        if table.contains(ips, ip) and (not _ip or _ip == ip) then
            if table.count(list, ip) == 0 then
                list[players[ip]] = ip
            end
            list[pid] = ip
        end

        table.insert(ips, ip)
    end
   
    local keys = {}
    for k in pairs(list) do
        keys[#keys+1] = k
    end

    local mcs = {}
    for k, v in pairs(list) do
        if not table.contains(mcs, v) then
            mcs[#mcs+1] = v
        end
    end

    local text = ""
    local countOfMsgs = 0
    local delayOfMsgs = 25
   
    if table.maxn(list) > 0 then
        if _ip == nil or (_ip ~= nil and not table.contains(forb, _ip)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Currently there are [" .. #keys .. "] characters with same IP address(es):")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")           
        end

        for pid, ip in spairs(list, function(t,a,b) return t[b] < t[a] end) do
            if not table.contains(forb, ip) then
                text = text .. "\n" ..  "[" .. doConvertIntegerToIp(ip) .. "] " .. getCreatureName(pid) .. getTarget(pid)

                if text:len() > 350 then
                    addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
                    countOfMsgs = countOfMsgs + 1
                    text = ""
                end
            end
        end
       
        if text:len() > 0 then
            addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
            countOfMsgs = countOfMsgs + 1
            text = ""
        end   

        if _ip == nil then
            addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'There are ' .. #getPlayersOnline() - #keys + #mcs .. ' unique IP addresses.')
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end

    return true
end

This is a ordened mc list? The default is sucks :(
I couldnt use that, should i use /mc with something else?
 
This is a ordened mc list? The default is sucks :(
I couldnt use that, should i use /mc with something else?
Yes, it's an ordered list, players with the most mc's should be at the top
Try this, if this doesn't work, then you need to tell me what exactly doesn't work.

Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

local function getTarget(cid)
    local target = getCreatureTarget(cid)
    if target ~= 0 then
        target = ' | Target: ' .. getCreatureName(target)
        else
        target = ''
    end
    return target
end

function onSay(cid, words, param, channel)
    local userAccess = getPlayerAccess(cid)
    if userAccess < 3 and not getPlayerByNameWildcard(param) then
        return doPlayerSendCancel(cid, "You have to enter a valid param.")
    end

    local _ip = nil
    if param ~= nil then
        _ip = tonumber(param)
        if not _ip or _ip == 0 then
            local revertIp = doRevertIp(param)
            if not revertIp then
                local tid = getPlayerByNameWildcard(param)
                if not tid then
                    _ip = nil
                else
                    _ip = getPlayerIp(tid)
                end
            else
                _ip = doConvertIpToInteger(revertIp)
            end
        end
    end

    local list, ips, forb = {}, {}, {}
    local players = getPlayersOnline()
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        if getPlayerAccess(pid) >= userAccess then
            table.insert(forb, ip)
        end
        
        if table.contains(ips, ip) and (not _ip or _ip == ip) then
            if table.count(list, ip) == 0 then
                list[players[ip]] = ip
            end
            list[pid] = ip
        end

        table.insert(ips, ip)
    end
    
    local keys = {}
    for k in pairs(list) do
        keys[#keys+1] = k
    end

    local mcs = {}
    for k, v in pairs(list) do
        if not table.contains(mcs, v) then
            mcs[#mcs+1] = v
        end
    end

    local text = ""
    local countOfMsgs = 0
    local delayOfMsgs = 25
    
    if table.maxn(list) > 0 then
        if _ip == nil or (_ip ~= nil and not table.contains(forb, _ip)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Currently there are [" .. #keys .. "] characters with same IP address(es):")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")            
        end

        for pid, ip in spairs(list, function(t,a,b) return t[b] < t[a] end) do
            if not table.contains(forb, ip) then
                text = text .. "\n" ..  "[" .. doConvertIntegerToIp(ip) .. "] " .. getCreatureName(pid) .. getTarget(pid)

                if text:len() > 350 then
                    addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
                    countOfMsgs = countOfMsgs + 1
                    text = ""
                end
            end
        end
        
        if text:len() > 0 then
            addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
            countOfMsgs = countOfMsgs + 1
            text = ""
        end    

        if _ip == nil then
            addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'There are ' .. #getPlayersOnline() - #keys + #mcs .. ' unique IP addresses.')
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end

    return true
end
 
Yes, it's an ordered list, players with the most mc's should be at the top
Try this, if this doesn't work, then you need to tell me what exactly doesn't work.

Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

local function getTarget(cid)
    local target = getCreatureTarget(cid)
    if target ~= 0 then
        target = ' | Target: ' .. getCreatureName(target)
        else
        target = ''
    end
    return target
end

function onSay(cid, words, param, channel)
    local userAccess = getPlayerAccess(cid)
    if userAccess < 3 and not getPlayerByNameWildcard(param) then
        return doPlayerSendCancel(cid, "You have to enter a valid param.")
    end

    local _ip = nil
    if param ~= nil then
        _ip = tonumber(param)
        if not _ip or _ip == 0 then
            local revertIp = doRevertIp(param)
            if not revertIp then
                local tid = getPlayerByNameWildcard(param)
                if not tid then
                    _ip = nil
                else
                    _ip = getPlayerIp(tid)
                end
            else
                _ip = doConvertIpToInteger(revertIp)
            end
        end
    end

    local list, ips, forb = {}, {}, {}
    local players = getPlayersOnline()
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        if getPlayerAccess(pid) >= userAccess then
            table.insert(forb, ip)
        end
      
        if table.contains(ips, ip) and (not _ip or _ip == ip) then
            if table.count(list, ip) == 0 then
                list[players[ip]] = ip
            end
            list[pid] = ip
        end

        table.insert(ips, ip)
    end
  
    local keys = {}
    for k in pairs(list) do
        keys[#keys+1] = k
    end

    local mcs = {}
    for k, v in pairs(list) do
        if not table.contains(mcs, v) then
            mcs[#mcs+1] = v
        end
    end

    local text = ""
    local countOfMsgs = 0
    local delayOfMsgs = 25
  
    if table.maxn(list) > 0 then
        if _ip == nil or (_ip ~= nil and not table.contains(forb, _ip)) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Currently there are [" .. #keys .. "] characters with same IP address(es):")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")          
        end

        for pid, ip in spairs(list, function(t,a,b) return t[b] < t[a] end) do
            if not table.contains(forb, ip) then
                text = text .. "\n" ..  "[" .. doConvertIntegerToIp(ip) .. "] " .. getCreatureName(pid) .. getTarget(pid)

                if text:len() > 350 then
                    addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
                    countOfMsgs = countOfMsgs + 1
                    text = ""
                end
            end
        end
      
        if text:len() > 0 then
            addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
            countOfMsgs = countOfMsgs + 1
            text = ""
        end  

        if _ip == nil then
            addEvent(doPlayerSendTextMessage, countOfMsgs * delayOfMsgs, cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'There are ' .. #getPlayersOnline() - #keys + #mcs .. ' unique IP addresses.')
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end

    return true
end

Code:
[20:31:27.199] [Error - TalkAction Interface]
[20:31:27.199] data/talkactions/scripts/multicheck.lua:onSay
[20:31:27.199] Description:
[20:31:27.199] data/lib/012-table.lua:17: bad argument #1 to 'pairs' (table expected, got number)
[20:31:27.199] stack traceback:
[20:31:27.199]     [C]: in function 'pairs'
[20:31:27.200]     data/lib/012-table.lua:17: in function 'contains'
[20:31:27.200]     data/talkactions/scripts/multicheck.lua:63: in function <data/talkactions/scripts/multicheck.lua:31>

what is it?
 
Code:
[20:31:27.199] [Error - TalkAction Interface]
[20:31:27.199] data/talkactions/scripts/multicheck.lua:onSay
[20:31:27.199] Description:
[20:31:27.199] data/lib/012-table.lua:17: bad argument #1 to 'pairs' (table expected, got number)
[20:31:27.199] stack traceback:
[20:31:27.199]     [C]: in function 'pairs'
[20:31:27.200]     data/lib/012-table.lua:17: in function 'contains'
[20:31:27.200]     data/talkactions/scripts/multicheck.lua:63: in function <data/talkactions/scripts/multicheck.lua:31>

what is it?
Try replacing table.contains with table.find in the script and try again
 
Try replacing table.contains with table.find in the script and try again

Code:
[21:34:32.326] [Error - TalkAction Interface] 
[21:34:32.326] data/talkactions/scripts/multicheck.lua:onSay
[21:34:32.326] Description: 
[21:34:32.326] data/talkactions/scripts/multicheck.lua:65: table index is nil
[21:34:32.326] stack traceback:
[21:34:32.326]     data/talkactions/scripts/multicheck.lua:65: in function <data/talkactions/scripts/multicheck.lua:31>
 
Code:
[21:34:32.326] [Error - TalkAction Interface]
[21:34:32.326] data/talkactions/scripts/multicheck.lua:onSay
[21:34:32.326] Description:
[21:34:32.326] data/talkactions/scripts/multicheck.lua:65: table index is nil
[21:34:32.326] stack traceback:
[21:34:32.326]     data/talkactions/scripts/multicheck.lua:65: in function <data/talkactions/scripts/multicheck.lua:31>
can you post your original script, to see players IP address?
 
So I read a complaint from one OT admin about players intentionally logging in 4+ mcs and then reporting the server for spoofing to otservlist and getting it banned. With this script, you could essentially do an onThink script and run it periodically every minute or so, if IP has >4 mcs then give them a warning

“You are violating the limit of multi-client.
Players are only allowed to have 3 clients max.
Please disconnect excess clients within 5 minutes or you will be banned for 1 hour.
Repeated offenses will result in prolonged ban-time or IP ban permanently.”

You could also add a white list (exceptions) for players who truly have multiple pcs on the same net such as family members.
There could also be a rule for clients with 0.0.0.0 ip (exit-logged client at trainers). Could kick after X minutes disregarding pz etc. After a player receives X kicks (warnings), they could be banned.

What do you guys think? It sounds to me like this would solve a major problem.
 
can you post your original script, to see players IP address?

So I read a complaint from one OT admin about players intentionally logging in 4+ mcs and then reporting the server for spoofing to otservlist and getting it banned. With this script, you could essentially do an onThink script and run it periodically every minute or so, if IP has >4 mcs then give them a warning

“You are violating the limit of multi-client.
Players are only allowed to have 3 clients max.
Please disconnect excess clients within 5 minutes or you will be banned for 1 hour.
Repeated offenses will result in prolonged ban-time or IP ban permanently.”

You could also add a white list (exceptions) for players who truly have multiple pcs on the same net such as family members.
There could also be a rule for clients with 0.0.0.0 ip (exit-logged client at trainers). Could kick after X minutes disregarding pz etc. After a player receives X kicks (warnings), they could be banned.

What do you guys think? It sounds to me like this would solve a major problem.

no, i just want to see who is using MCs, witch chars in a organized way
there are a few sources changes here on forum to fix the problem u mention

bump

bump

bump
 
We just need to order table in the opposite way, so to speak
Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

function onSay(cid, words, param, channel)
    local _ip = nil
    if(param ~= '') then
        _ip = tonumber(param)
        if(not _ip or _ip == 0) then
            local revertIp = doRevertIp(param)
            if(not revertIp) then
                local tid = getPlayerByNameWildcard(param)
                if(not tid) then
                    _ip = nil
                else
                    _ip = getPlayerIp(tid)
                end
            else
                _ip = doConvertIpToInteger(revertIp)
            end
        end
    end

    local list, ips = {}, {}
    local players = getPlayersOnline()
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        local tmp = table.find(ips, ip)
        if(tmp ~= nil and (not _ip or _ip == ip)) then
            if not list[ip] then
                list[ip] = {}
            end
            if(table.countElements(list, ip) == 0) then
                table.insert(list[ip], players[tmp])
            end
            table.insert(list[ip], pid)
        end
        table.insert(ips, ip)
    end

    local count = 0
    for _ in pairs(list) do count = count + 1 end

    if(count > 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently online players with same IP address(es):")
        for ip,cids in spairs(list, function(t,a,b) return #t[b] < #t[a] end) do
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "IP: "..doConvertIntegerToIp(ip).." - "..#cids)
            for i = 1, #cids do
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "("..i..") - "..getCreatureName(cids[i]))
            end
        end
        --[[ count -> unique addresses ]]
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Total: "..count.." clients with more than one connection.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end

    return true
end

EDIT: added spairs() from Alpha's script to sort table (descending)
 
Last edited:
Solution
We just need to order table in the opposite way, so to speak
Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

function onSay(cid, words, param, channel)
    local _ip = nil
    if(param ~= '') then
        _ip = tonumber(param)
        if(not _ip or _ip == 0) then
            local revertIp = doRevertIp(param)
            if(not revertIp) then
                local tid = getPlayerByNameWildcard(param)
                if(not tid) then
                    _ip = nil
                else
                    _ip = getPlayerIp(tid)
                end
            else
                _ip = doConvertIpToInteger(revertIp)
            end
        end
    end

    local list, ips = {}, {}
    local players = getPlayersOnline()
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        local tmp = table.find(ips, ip)
        if(tmp ~= nil and (not _ip or _ip == ip)) then
            if not list[ip] then
                list[ip] = {}
            end
            if(table.countElements(list, ip) == 0) then
                table.insert(list[ip], players[tmp])
            end
            table.insert(list[ip], pid)
        end
        table.insert(ips, ip)
    end

    local count = 0
    for _ in pairs(list) do count = count + 1 end

    if(count > 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently online players with same IP address(es):")
        for ip,cids in spairs(list, function(t,a,b) return #t[b] < #t[a] end) do
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "IP: "..doConvertIntegerToIp(ip).." - "..#cids)
            for i = 1, #cids do
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "("..i..") - "..getCreatureName(cids[i]))
            end
        end
        --[[ count -> unique addresses ]]
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Total: "..count.." clients with more than one connection.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end

    return true
end

EDIT: added spairs() from Alpha's script to sort table (descending)
worked here

1643205711587.png
 
Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

function onSay(cid, words, param, channel)
    local _ip = nil
    if(param ~= '') then
        _ip = tonumber(param)
        if(not _ip or _ip == 0) then
            local revertIp = doRevertIp(param)
            if(not revertIp) then
                local tid = getPlayerByNameWildcard(param)
                if(not tid) then
                    _ip = nil
                else
                    _ip = getPlayerIp(tid)
                end
            else
                _ip = doConvertIpToInteger(revertIp)
            end
        end
    end

    local list, ips = {}, {}
    local players = getPlayersOnline()
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        local tmp = table.find(ips, ip)
        if(tmp ~= nil and (not _ip or _ip == ip)) then
            if not list[ip] then
                list[ip] = {}
            end
            if(table.countElements(list, ip) == 0) then
                table.insert(list[ip], players[tmp])
            end
            table.insert(list[ip], pid)
        end
        table.insert(ips, ip)
    end

    local count = 0
    for _ in pairs(list) do count = count + 1 end

    if(count > 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently online players with same IP address(es):")
        for ip,cids in spairs(list, function(t,a,b) return #t[b] < #t[a] end) do
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "IP: "..doConvertIntegerToIp(ip).." - "..#cids)
            for i = 1, #cids do
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "("..i..") - "..getCreatureName(cids[i]))
            end
        end
        --[[ count -> unique addresses ]]
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Total: "..count.." clients with more than one connection.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end

    return true
end

EDIT: added spairs() from Alpha's script to sort table (descending)
Something its duplicating some characters, dont know why.

1643804543169.png
 
Something its duplicating some characters, dont know why.

View attachment 65261

Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

function onSay(cid, words, param, channel)

    local list = {}
    local players = getPlayersOnline()
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        if not list[ip] then
            list[ip] = {}
        end
        list[ip][#list[ip] + 1] = pid
    end

    local uniqueClients = 0
    if next(list) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently online players with same IP address(es):")
        for ip,cids in spairs(list, function(t,a,b) return #t[b] < #t[a] end) do
            if #cids > 1 then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "IP: "..doConvertIntegerToIp(ip).." - "..#cids)
                for i = 1, #cids do
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "("..i..") - "..getCreatureName(cids[i]))
                end
                uniqueClients = uniqueClients + 1
            end
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Total: "..uniqueClients.." clients with more than one connection.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end
    return true
end
 
Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

function onSay(cid, words, param, channel)

    local list = {}
    local players = getPlayersOnline()
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        if not list[ip] then
            list[ip] = {}
        end
        list[ip][#list[ip] + 1] = pid
    end

    local uniqueClients = 0
    if next(list) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently online players with same IP address(es):")
        for ip,cids in spairs(list, function(t,a,b) return #t[b] < #t[a] end) do
            if #cids > 1 then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "IP: "..doConvertIntegerToIp(ip).." - "..#cids)
                for i = 1, #cids do
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "("..i..") - "..getCreatureName(cids[i]))
                end
                uniqueClients = uniqueClients + 1
            end
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Total: "..uniqueClients.." clients with more than one connection.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end
    return true
end
works
 
Lua:
local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

function onSay(cid, words, param, channel)

    local list = {}
    local players = getPlayersOnline()
    for i, pid in ipairs(players) do
        local ip = getPlayerIp(pid)
        if not list[ip] then
            list[ip] = {}
        end
        list[ip][#list[ip] + 1] = pid
    end

    local uniqueClients = 0
    if next(list) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently online players with same IP address(es):")
        for ip,cids in spairs(list, function(t,a,b) return #t[b] < #t[a] end) do
            if #cids > 1 then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "IP: "..doConvertIntegerToIp(ip).." - "..#cids)
                for i = 1, #cids do
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "("..i..") - "..getCreatureName(cids[i]))
                end
                uniqueClients = uniqueClients + 1
            end
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Total: "..uniqueClients.." clients with more than one connection.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
    end
    return true
end
What causes this invalid IP (0.0.0.0)?

1656961377353.png
 
Back
Top