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

command "!online" is not working

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,337
Solutions
71
Reaction score
697
Location
ლ(ಠ益ಠლ)
Does anyone know why the command "!online" is not working? I've tried several scripts without success, help me solve this problem?

use tfs engine 1.2 8.0 by celehore
 
Solution
XML:
<talkaction words="!online" script="online.lua" />

Lua:
local maxPlayersPerMessage = 10

function onSay(player, words, param)
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local onlineList = {}

    for _, targetPlayer in ipairs(players) do
        if hasAccess or not targetPlayer:isInGhostMode() then
            table.insert(onlineList, ("%s [%d]"):format(targetPlayer:getName(), targetPlayer:getLevel()))
        end
    end

    local playersOnline = #onlineList
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("%d players online."):format(playersOnline))

    for i = 1, playersOnline, maxPlayersPerMessage do
        local j = math.min(i + maxPlayersPerMessage - 1...
XML:
<talkaction words="!online" script="online.lua" />

Lua:
local maxPlayersPerMessage = 10

function onSay(player, words, param)
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local onlineList = {}

    for _, targetPlayer in ipairs(players) do
        if hasAccess or not targetPlayer:isInGhostMode() then
            table.insert(onlineList, ("%s [%d]"):format(targetPlayer:getName(), targetPlayer:getLevel()))
        end
    end

    local playersOnline = #onlineList
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("%d players online."):format(playersOnline))

    for i = 1, playersOnline, maxPlayersPerMessage do
        local j = math.min(i + maxPlayersPerMessage - 1, playersOnline)
        local msg = table.concat(onlineList, ", ", i, j) .. "."
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg)
    end
    return false
end
 
Solution
XML:
<talkaction words="!online" script="online.lua" />

Lua:
local maxPlayersPerMessage = 10

function onSay(player, words, param)
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local onlineList = {}

    for _, targetPlayer in ipairs(players) do
        if hasAccess or not targetPlayer:isInGhostMode() then
            table.insert(onlineList, ("%s [%d]"):format(targetPlayer:getName(), targetPlayer:getLevel()))
        end
    end

    local playersOnline = #onlineList
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("%d players online."):format(playersOnline))

    for i = 1, playersOnline, maxPlayersPerMessage do
        local j = math.min(i + maxPlayersPerMessage - 1, playersOnline)
        local msg = table.concat(onlineList, ", ", i, j) .. "."
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg)
    end
    return false
end
working perfectly, thank you!
 
Back
Top