• 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!

Talkaction !online

Status
Not open for further replies.

115820

Member
Joined
Feb 27, 2011
Messages
193
Solutions
1
Reaction score
5
Location
London, England
Hi everyone.

I use this script to command !online
Code:
local ranks = {
[1] = {"Tutor"},
[2] = {"S-Tutor"},
[3] = {"GM"},
[4] = {"CM"},
[5] = {"GOD"},
[9] = {"Admin"},
[10] = {"Owner"}
}

local config = {
showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}

function onSay(cid, words, param, channel)
local players = getPlayersOnline()
local strings = {""}
local i, position = 1, 1
local added = false

for _, pid in ipairs(players) do
if(added) then
if(i > (position * 7)) then
strings[position] = strings[position] .. ","
position = position + 1
strings[position] = ""
else
strings[position] = i == 1 and "" or strings[position] .. ", "
end
end

if getPlayerAccess(pid) < 2 then
strings[position] = strings[position] .. getCreatureName(pid) .." ("..getPlayerLevel(pid)..")"
i = i + 1
added = true
else
added = false
end
end

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (i - 1) .. " player(s) online:")
for i, str in ipairs(strings) do
if(str:sub(str:len()) ~= ",") then
str = str .. "."
end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
end

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "-----------")

local players2 = getPlayersOnline()
local helpon = 0
local rank = ""
local str2 = ""

for _, pid2 in ipairs(players2) do
if getPlayerAccess(pid2) > 0 then
if((config.showGamemasters or getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES) or not getPlayerCustomFlagValue(pid2, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) and (not isPlayerGhost(pid2) or getPlayerGhostAccess(cid) >= getPlayerGhostAccess(pid2))) then
rank = ranks[getPlayerAccess(pid2)]
str2 = str2 .. getCreatureName(pid2) .." ["..rank[1].."] "
helpon = helpon + 1
end
end
end
if helpon > 0 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (helpon) .. " support player(s) online:")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str2)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "There are no support players currently online.")
end
return true
end

When i use command him show :
11:34 1 player(s) online:
11:34 Theuzao (4999772).
11:34 -----------
11:34 1 support player(s) online:
11:34 [BOSS] [Owner]

I want to show level with dot's :

11:34 1 player(s) online:
11:34 Theuzao (4.999.772).
11:34 -----------
11:34 1 support player(s) online:
11:34 [BOSS] [Owner]
 
Solution
Correction:
Lua:
-------------------------------------------------
-- new in this script
-- this will convert the number to a format using a seperator of your choosing, where n is the number and f is the format seperator
function formatNumber(n, f)
    while true do
        n, k = string.gsub(n, "^(-?%d+)(%d%d%d)", '%1'..f..'%2')
        if (k==0) then
            break
        end
    end
    return n
end

-- this is the character you will use to seperator the formated number; Example 123456789 becomes 123.456.789
local numberFormatCharacter = '.'

-----------------------------------------------

local ranks = {
    [1] = {"Tutor"},
    [2] = {"S-Tutor"},
    [3] = {"GM"},
    [4] = {"CM"},
    [5] = {"GOD"},
    [9] = {"Admin"}...
Lua:
-------------------------------------------------
-- new in this script
-- this will convert the number to a format using a seperator of your choosing, where n is the number and f is the format seperator
function formatNumber(n, f)
    while true do 
        n, k = string.gsub(f, "^(-?%d+)(%d%d%d)", '%1'..f..'%2')
        if (k==0) then
            break
        end
    end
    return n
end

-- this is the character you will use to seperator the formated number; Example 123456789 becomes 123.456.789
local numberFormatCharacter = '.'

-----------------------------------------------

local ranks = {
    [1] = {"Tutor"},
    [2] = {"S-Tutor"},
    [3] = {"GM"},
    [4] = {"CM"},
    [5] = {"GOD"},
    [9] = {"Admin"},
    [10] = {"Owner"}
}
local config = {
    showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}
function onSay(cid, words, param, channel)
    local players = getPlayersOnline()
    local strings = {""}
    local i, position = 1, 1
    local added = false
    
    for _, pid in ipairs(players) do
        if(added) then
            if(i > (position * 7)) then
                strings[position] = strings[position] .. ","
                position = position + 1
                strings[position] = ""
            else
                strings[position] = i == 1 and "" or strings[position] .. ", "
            end
        end
    
        if getPlayerAccess(pid) < 2 then
            -- this was the only line changed from the original script
            strings[position] = strings[position] .. getCreatureName(pid) .." ("..formatNumber(getPlayerLevel(pid), numberFormatCharacter)..")"
            i = i + 1
            added = true
        else
            added = false
        end
    end
    
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (i - 1) .. " player(s) online:")
    for i, str in ipairs(strings) do
        if(str:sub(str:len()) ~= ",") then
            str = str .. "."
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
    end
    
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "-----------")
    
    local players2 = getPlayersOnline()
    local helpon = 0
    local rank = ""
    local str2 = ""
    
    for _, pid2 in ipairs(players2) do
        if getPlayerAccess(pid2) > 0 then
            if((config.showGamemasters or getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES) or not getPlayerCustomFlagValue(pid2, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) and (not isPlayerGhost(pid2) or getPlayerGhostAccess(cid) >= getPlayerGhostAccess(pid2))) then
                rank = ranks[getPlayerAccess(pid2)]
                str2 = str2 .. getCreatureName(pid2) .." ["..rank[1].."] "
                helpon = helpon + 1
            end
        end
    end
    if helpon > 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (helpon) .. " support player(s) online:")
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str2)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "There are no support players currently online.")
    end
    return true
end
 
Correction:
Lua:
-------------------------------------------------
-- new in this script
-- this will convert the number to a format using a seperator of your choosing, where n is the number and f is the format seperator
function formatNumber(n, f)
    while true do
        n, k = string.gsub(n, "^(-?%d+)(%d%d%d)", '%1'..f..'%2')
        if (k==0) then
            break
        end
    end
    return n
end

-- this is the character you will use to seperator the formated number; Example 123456789 becomes 123.456.789
local numberFormatCharacter = '.'

-----------------------------------------------

local ranks = {
    [1] = {"Tutor"},
    [2] = {"S-Tutor"},
    [3] = {"GM"},
    [4] = {"CM"},
    [5] = {"GOD"},
    [9] = {"Admin"},
    [10] = {"Owner"}
}
local config = {
    showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}
function onSay(cid, words, param, channel)
    local players = getPlayersOnline()
    local strings = {""}
    local i, position = 1, 1
    local added = false
 
    for _, pid in ipairs(players) do
        if(added) then
            if(i > (position * 7)) then
                strings[position] = strings[position] .. ","
                position = position + 1
                strings[position] = ""
            else
                strings[position] = i == 1 and "" or strings[position] .. ", "
            end
        end
 
        if getPlayerAccess(pid) < 2 then
            -- this was the only line changed from the original script
            strings[position] = strings[position] .. getCreatureName(pid) .." ("..formatNumber(getPlayerLevel(pid), numberFormatCharacter)..")"
            i = i + 1
            added = true
        else
            added = false
        end
    end
 
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (i - 1) .. " player(s) online:")
    for i, str in ipairs(strings) do
        if(str:sub(str:len()) ~= ",") then
            str = str .. "."
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
    end
 
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "-----------")
 
    local players2 = getPlayersOnline()
    local helpon = 0
    local rank = ""
    local str2 = ""
 
    for _, pid2 in ipairs(players2) do
        if getPlayerAccess(pid2) > 0 then
            if((config.showGamemasters or getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES) or not getPlayerCustomFlagValue(pid2, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) and (not isPlayerGhost(pid2) or getPlayerGhostAccess(cid) >= getPlayerGhostAccess(pid2))) then
                rank = ranks[getPlayerAccess(pid2)]
                str2 = str2 .. getCreatureName(pid2) .." ["..rank[1].."] "
                helpon = helpon + 1
            end
        end
    end
    if helpon > 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (helpon) .. " support player(s) online:")
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str2)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "There are no support players currently online.")
    end
    return true
end
 
Solution
Status
Not open for further replies.
Back
Top