• 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 !online command - need some

PuszekLDZ

https://tibia74.eu
Premium User
Joined
Jan 2, 2020
Messages
329
Solutions
1
Reaction score
85
Location
Lodz
hello again :)

I got a !online command to show how many players are online
it look like that:
Lua:
function onSay(cid, words, param, channel)
    if(not checkExhausted(cid, 666, 10)) then
        return false
    end

    local strings, i, position, added, showGamemasters = {""}, 1, 1, false, getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
    for _, pid in ipairs(getPlayersOnline()) 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

        added = false
        if((showGamemasters or getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES) or not getPlayerCustomFlagValue(pid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) and (not isPlayerGhost(pid) or getPlayerGhostAccess(cid) >= getPlayerGhostAccess(pid))) then
            strings[position] = strings[position] .. getCreatureName(pid) .. " [" .. getPlayerLevel(pid) .. "]"
            i = i + 1
            added = true
        end
    end

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

    return true
end

online.png

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

is any easy way to "show more" - i mean players names?
like after type !online

it will show

01:43 1 players online: Player Name
or

01:43 3 players online: Player Name1, Player Name2, Player Name3

?
 
Lua:
function onSay(player, words, param)
    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 = ""
    for k, tmpPlayer in ipairs(players) do
        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

Change line 16 from:
Lua:
msg = msg .. tmpPlayer:getName() .. " [" .. tmpPlayer:getLevel() .. "]"
to:
Code:
msg = msg .. tmpPlayer:getName()

If you don't want the level information to show.

EDIT: I've just realised you are using TFS 0.X
Sorry this code won't work, please tag your support threads correctly.
 
Not working here...

<talkaction words="!online" event="script" value="online.lua"/>


function onSay(player, words, param)
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 = ""
for k, tmpPlayer in ipairs(players) do
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
 
What errors? I just tested it on main TFS and it worked without any errors.
 
What errors? I just tested it on main TFS and it worked without any errors.

It doesn't show any error, it just doesn't show anything...

I've changed the .xml now, but still nothing happening
<talkaction words="!online" event="script" script="online.lua"/>
 
That's not how you add it in 1.3
XML:
<talkaction words="!online" script="online.lua" />
 
That's not how you add it in 1.3
XML:
<talkaction words="!online" script="online.lua" />

Well, I have those two, and both working:

<talkaction words="!bless" event="script" script="bless.lua"/>
<talkaction words="!serverinfo" event="script" value="serverinfo.lua"/>

How is yours?
 
That's how you add scripts to XML file in 0.4 not in 1.3 and it should print errors.
Are you sure you are using 1.3?
I have simple 1.3 talkactions.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<talkactions>
    <!-- commands -->
    <talkaction words="/ban" separator=" " script="ban.lua" />
    <talkaction words="/ipban" separator=" " script="ipban.lua" />
    <talkaction words="/unban" separator=" " script="unban.lua" />
    <talkaction words="/up" script="up.lua" />
    <talkaction words="/down" script="down.lua" />
    <talkaction words="/c" separator=" " script="teleport_creature_here.lua" />
    <talkaction words="/goto" separator=" " script="teleport_to_creature.lua" />
    <talkaction words="/owner" separator=" " script="owner.lua" />
    <talkaction words="/t" script="teleport_home.lua" />
    <talkaction words="/town" separator=" " script="teleport_to_town.lua" />
    <talkaction words="/a" separator=" " script="teleport_ntiles.lua" />
    <talkaction words="/info" separator=" " script="info.lua" />
    <talkaction words="/r" separator=" " script="removething.lua" />
    <talkaction words="/kick" separator=" " script="kick.lua" />
    <talkaction words="/openserver" script="openserver.lua" />
    <talkaction words="/closeserver" separator=" " script="closeserver.lua" />
    <talkaction words="/B" separator=" " script="broadcast.lua" />
    <talkaction words="/m" separator=" " script="place_monster.lua" />
    <talkaction words="/i" separator=" " script="create_item.lua" />
    <talkaction words="/s" separator=" " script="place_npc.lua" />
    <talkaction words="/addtutor" separator=" " script="add_tutor.lua" />
    <talkaction words="/removetutor" separator=" " script="remove_tutor.lua" />
    <talkaction words="/looktype" separator=" " script="looktype.lua" />
    <talkaction words="/summon" separator=" " script="place_summon.lua" />
    <talkaction words="/chameleon" separator=" " script="chameleon.lua" />
    <talkaction words="/addskill" separator=" " script="add_skill.lua" />
    <talkaction words="/mccheck" script="mccheck.lua" />
    <talkaction words="/ghost" script="ghost.lua" />
    <talkaction words="/clean" script="clean.lua" />
    <talkaction words="/hide" script="hide.lua" />
    <talkaction words="/reload" separator=" " script="reload.lua" />
    <talkaction words="/raid" separator=" " script="force_raid.lua" />

    <!-- player talkactions -->
    <talkaction words="!buypremium" script="buyprem.lua" />
    <talkaction words="!buyhouse" script="buyhouse.lua" />
    <talkaction words="!sellhouse" separator=" " script="sellhouse.lua" />
    <talkaction words="!leavehouse" script="leavehouse.lua" />
    <talkaction words="!changesex" script="changesex.lua" />
    <talkaction words="!uptime" script="uptime.lua" />
    <talkaction words="!deathlist" script="deathlist.lua" />
    <talkaction words="!kills" script="kills.lua" />
    <talkaction words="!online" script="online.lua" />
    <talkaction words="!serverinfo" script="serverinfo.lua" />

    <!-- test talkactions -->
    <talkaction words="!z" separator=" " script="magiceffect.lua" />
    <talkaction words="!x" separator=" " script="animationeffect.lua" />
</talkactions>
 
I had this issue using otservbr-global. I'm no expert, but it appears they somehow messed up their message types. Very few seem to work from the list in .\server\src\const.h (enum MessageClasses)

Try using the following script, placing it in .\server\data\scripts\talkactions\player\online.lua

Notice a few differences-
  1. we declare a local TalkAction object at the top
  2. we call that TalkAction object's onSay function "online.onSay" ... because it is done this way, it doesn't need to be set up in a talkactions.xml file. I'm not sure if both ways are possible in otservbr, I haven't explored that avenue, just copied their methods.
  3. in the function, I have changed "MESSAGE_STATUS_CONSOLE_BLUE" to "MESSAGE_INFO_DESCR"
  4. at the bottom after the end of the function definition, notice that we call the TalkAction object's "register" function

Lua:
local online = TalkAction("!online")

function online.onSay(player, words, param)
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local playerCount = Game.getPlayerCount()

    local i = 0
    local msg = playerCount .. " player(s) online. "
    for k, tmpPlayer in ipairs(players) do
        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_INFO_DESCR, msg)
            msg = ""
            i = 0
        end
    end

    if i > 0 then
        msg = msg .. "."
        player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
    end
    return false
end

online:separator(" ")
online:register()

I also merged the two messages the player receives into a single message just out of personal preference.
I wish MESSAGE_STATUS_CONSOLE_BLUE worked like it's supposed to. I like how that looks better, but I'll take what I can get for now.

EDIT: I forgot to mention, if you're wondering why "/reload talkactions" isn't reloading it, try "/reload scripts" .. i know.. strangeness lol
EDIT: credit to Leo32 for the original script which I just tweaked a bit
 
Last edited:
I had this issue using otservbr-global. I'm no expert, but it appears they somehow messed up their message types. Very few seem to work from the list in .\server\src\const.h (enum MessageClasses)

Try using the following script, placing it in .\server\data\scripts\talkactions\player\online.lua

Notice a few differences-
  1. we declare a local TalkAction object at the top
  2. we call that TalkAction object's onSay function "online.onSay" ... because it is done this way, it doesn't need to be set up in a talkactions.xml file. I'm not sure if both ways are possible in otservbr, I haven't explored that avenue, just copied their methods.
  3. in the function, I have changed "MESSAGE_STATUS_CONSOLE_BLUE" to "MESSAGE_INFO_DESCR"
  4. at the bottom after the end of the function definition, notice that we call the TalkAction object's "register" function

Lua:
local online = TalkAction("!online")

function online.onSay(player, words, param)
    local hasAccess = player:getGroup():getAccess()
    local players = Game.getPlayers()
    local playerCount = Game.getPlayerCount()

    local i = 0
    local msg = playerCount .. " player(s) online. "
    for k, tmpPlayer in ipairs(players) do
        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_INFO_DESCR, msg)
            msg = ""
            i = 0
        end
    end

    if i > 0 then
        msg = msg .. "."
        player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
    end
    return false
end

online:separator(" ")
online:register()

I also merged the two messages the player receives into a single message just out of personal preference.
I wish MESSAGE_STATUS_CONSOLE_BLUE worked like it's supposed to. I like how that looks better, but I'll take what I can get for now.

EDIT: I forgot to mention, if you're wondering why "/reload talkactions" isn't reloading it, try "/reload scripts" .. i know.. strangeness lol

Thank you Orkanite. This script is working, but I had to add at the normal folder (\data\talkactions\scripts), It didin't work at \data\scripts\talkactions\player.

Cheers mate, thank you for your help.
 
Back
Top