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

Solved [TFS 1.2] !online counting ghost

Shadow Dan

Sh4dowDan
Joined
Jun 5, 2010
Messages
344
Reaction score
88
Location
Poland
#edit
I fixed it this way, now everything is fine :p
Code:
function onSay(player, words, param)
local cid = player
if(not checkExhausted(cid, 555, 5)) then
    return false
end
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local playerCount = Game.getPlayerCount()

    local e = 0
    local i = 0
    local msg = ""
    local tmpPlayer
    for k = 1, #players do
        tmpPlayer = players[k]
        if hasAccess or not tmpPlayer:isInGhostMode() then
            if i > 0 then
                msg = msg .. ", "
            end
            msg = msg .. tmpPlayer:getName() .. " [" .. tmpPlayer:getLevel() .. "]"
            i = i + 1
        end
       
        if tmpPlayer:isInGhostMode() then
        e = e + 1
        end

        if i == 10 then
            if k == playerCount then
                msg = msg .. "."
            else
                msg = msg .. ","
            end
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg)
            msg = ""
            i = 0
        end
    end

    if i > 0 then
        msg = msg .. "."
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg)
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, playerCount - e .. " players online.")
    return false
end

#old ------------------------------------------------------------------------------
This script works perfect but has one bug. It counts players in ghost mode.
Need to add something like Game.getPlayerCount() - PlayersInGhostMode but i have no idea how to do it without errors.

testmaste_wqpsasq.png


btw. i didn't give up on trying but maybe someone knows easy solution for this so i posted it.
..and this may help other players in future.

Code:
function onSay(player, words, param)
local cid = player
if(not checkExhausted(cid, 555, 2)) then
    return false
end
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local playerCount = Game.getPlayerCount()

    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, playerCount .. " players online.")

    local i = 0
    local msg = ""
    local tmpPlayer
    for k = 1, #players do
        tmpPlayer = players[k]
        if hasAccess or not tmpPlayer:isInGhostMode() then
            if i > 0 then
                msg = msg .. ", "
            end
            msg = msg .. tmpPlayer:getName() .. " [" .. tmpPlayer:getLevel() .. "]"
            i = i + 1
        end

        if i == 10 then
            if k == playerCount then
                msg = msg .. "."
            else
                msg = msg .. ","
            end
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg)
            msg = ""
            i = 0
        end
    end

    if i > 0 then
        msg = msg .. "."
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg)
    end
    return false
end
 
Last edited:
Back
Top Bottom