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

Lua !online talkaction

Blasphemy

Well-Known Member
Joined
Jan 5, 2012
Messages
387
Reaction score
67
Hi! im trying to show vocation on "online list" talkaction... what im doing wrong :C?
someone can help me please

Lua:
local maxPlayersPerMessage = 10

function onSay(player, words, param)
    local playerCount = Game.getPlayerCount()
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local onlineList = {}
    local msg = ""
    
    for _, targetPlayer in ipairs(players) do
        if hasAccess or not targetPlayer:isInGhostMode() then
            local playerVocation = targetPlayer:getVocation()
            local playerName = targetPlayer:getName()
            local playerLevel = targetPlayer:getLevel()
            table.insert(onlineList, playerLevel .. " - " .. playerName .. " - " .. playerVocation .. ".")
        end
    end

    local playersOnline = #onlineList
        
    for i = 1, playersOnline, maxPlayersPerMessage do
        local j = math.min(i + maxPlayersPerMessage - 1, playersOnline)
        local msg = table.concat(onlineList, ",\n", i, j) .. ".\n\n"
        msg =  msg .. playerCount ..  " player(s) online.\n\n"
        player:showTextDialog(4871, msg)
    end
    return false
end
 
Untested
Lua:
local maxPlayersPerMessage = 10

function onSay(player, words, param)
    local playerCount = Game.getPlayerCount()
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local onlineList = {}
    local msg = ""
    local playerNumber = 1
    
    for _, targetPlayer in ipairs(players) do
        if hasAccess or not targetPlayer:isInGhostMode() then
            local playerVocation = targetPlayer:getVocation():getName()
            local playerName = targetPlayer:getName()
            local playerLevel = targetPlayer:getLevel()
            table.insert(onlineList, "["..playerNumber.."] - Level: " .. playerLevel .. " - Name: " .. playerName .. " - Vocation: " .. playerVocation .. ".")
            playerNumber = playerNumber + 1
        end
    end

    local playersOnline = #onlineList
        
    for i = 1, playersOnline, maxPlayersPerMessage do
        local j = math.min(i + maxPlayersPerMessage - 1, playersOnline)
        local msg = table.concat(onlineList, ",\n", i, j) .. ".\n\n"
        msg =  msg .. playerCount ..  " player(s) online.\n\n"
        player:showTextDialog(4871, msg)
    end
    return false
end
 
Last edited:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/online.lua:onSay
data/talkactions/scripts/online.lua:33: attempt to concatenate local 'playerVocation' (a userdata value)
stack traceback:
        [C]: in function '__concat'
        data/talkactions/scripts/online.lua:33: in function <data/talkactions/scripts/online.lua:21>
Post automatically merged:

Untested
Lua:
local maxPlayersPerMessage = 10

function onSay(player, words, param)
    local playerCount = Game.getPlayerCount()
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local onlineList = {}
    local msg = ""
    local playerNumber = 1
   
    for _, targetPlayer in ipairs(players) do
        if hasAccess or not targetPlayer:isInGhostMode() then
            local playerVocation = targetPlayer:getVocation():getName()
            local playerName = targetPlayer:getName()
            local playerLevel = targetPlayer:getLevel()
            table.insert(onlineList, "["..playerNumber.."] - Level: " .. playerLevel .. " - Name: " .. playerName .. " - Vocation: " .. playerVocation .. ".")
            playerNumber = playerNumber + 1
        end
    end

    local playersOnline = #onlineList
       
    for i = 1, playersOnline, maxPlayersPerMessage do
        local j = math.min(i + maxPlayersPerMessage - 1, playersOnline)
        local msg = table.concat(onlineList, ",\n", i, j) .. ".\n\n"
        msg =  msg .. playerCount ..  " player(s) online.\n\n"
        player:showTextDialog(4871, msg)
    end
    return false
end
this is the solution ":getName()" hehe thank you very much
 
Back
Top