• 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 Level next to the player's name.

Otlandserv

Member
Joined
May 22, 2023
Messages
58
Reaction score
5
Hello!
Does anyone have a code for TFS 0.3.7 to display the level next to the player's name?

ETC.
Owned [101]
OtlandServ [89]
Smoke [11]
 
Yes, you can add it, but I don't know if your TFS has the data/event/player.lua file. In that line function Player:eek:nLook(thing, position, distance), if there is something similar to that, you can add yes. I already added 'reset', 'dodge', 'critical' and others to my server

example the code:
Lua:
if thing:isPlayer() then
                local dodgeValue = thing:getStorageValue(154510)
                description = string.format("%s\nDodge: %d", description, dodgeValue)
When I click on the player, the name appears next to [Dodge: 100/100]
 
Last edited:
Yes, you can add it, but I don't know if your TFS has the data/event/player.lua file. In that line function Player:eek:nLook(thing, position, distance), if there is something similar to that, you can add yes. I already added 'reset', 'dodge', 'critical' and others to my server

example the code:
Lua:
if thing:isPlayer() then
                local dodgeValue = thing:getStorageValue(154510)
                description = string.format("%s\nDodge: %d", description, dodgeValue)
When I click on the player, the name appears next to [Dodge: 100/100]
No i don't have this. Onle sources edit.
 

Replace with
C++:
if (!creature->getHideName())
{
    if (const Player* player = creature->getPlayer())
        msg->addString(creature->getName() + " [" + std::to_string(player->getLevel()) + "]");
    else
        msg->addString(creature->getName());
}
else
    msg->addString("");
 

Replace with
C++:
if (!creature->getHideName())
{
    if (const Player* player = creature->getPlayer())
        msg->addString(creature->getName() + " [" + std::to_string(player->getLevel()) + "]");
    else
        msg->addString(creature->getName());
}
else
    msg->addString("");
Works perfect! Thank you !!! <3

*One problem - if click right mouse on player, can't add to vip, send message :(
 
Last edited:
I have tried this in the past, but the functions "Copy name", "Add vip" and "Send private message" when you do a right click in other players are broken, I managed to solve this changing the client source code.
You right.
Not working only when click right mouse on player, but if you click on TEXT all working good.
Maybe it can be omitted so that it is not in the name and the client does not take it into account?
 
You right.
Not working only when click right mouse on player, but if you click on TEXT all working good.
Maybe it can be omitted so that it is not in the name and the client does not take it into account?

One possible solution would change those functions in the client side to remove the extra text ' [.*]' before execute the action, or a better approach would be write the level on screen, in the position that you want in the function (client source code):
src/client/creature.cpp

C++:
void Creature:drawInformation

I did something similar in my client (OTCv8), but my goal was show the reset level from my players, the problem is that you must change your TFS too, in order to send the new information to the client:
1686824038001.png
I will post my code here, if you want to change it to level, idk if it is the best way to do it, but here it is:
src/client/creature.h
C++:
    void setReset(uint32 value);
    void resetInformationColor() { m_useCustomInformationColor = false; setHealthPercent(getHealthPercent());  }
    uint32 m_reset;
    CachedText m_resetCache;

src/client/protocolgameparse.cpp
C++:
CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
{
...

            if (g_game.getFeature(Otc::GameTibia12Protocol) && creatureType == Proto::CreatureTypeSummonOwn)
                msg->getU32(); // master

            std::string name = g_game.formatCreatureName(msg->getString());

            uint resets = msg->getU32();
...
 if (creature) {
                    creature->setId(id);
                    creature->setName(name);
                    if (resets && resets > 0) {
                        creature->setReset(resets);
                    }

                    g_map.addCreature(creature);
                }
...
Just add the level/reset code uint resets = msg->getU32(); after the std::string name = g_game.formatCreatureName(msg->getString()); and the code: if (resets && resets > 0) { creature->setReset(resets); } after creature->setName(name);.

And finally change the:
src/client/creature.cpp
Search for this:
C++:
    m_nameCache.setFont(g_fonts.getFont("verdana-11px-rounded"));
    m_nameCache.setAlign(Fw::AlignTopCenter);
And add this code after:
C++:
    m_resetCache.setFont(g_fonts.getFont("verdana-11px-rounded"));
    m_resetCache.setAlign(Fw::AlignTopCenter);
Then search for this:
C++:
           textRect.moveBottomCenter(textCenter);
            m_titleCache.draw(textRect, m_titleColor);
        }
And add this code after:
[CODE=cpp]
        if (m_resetCache.hasText()) {
            Size titleSize = m_resetCache.getTextSize();
            textRect.setSize(titleSize);
            Rect extraTextRect = Rect(textRect.topLeft().x - (textRect.width() + 2), textRect.topLeft().y, titleSize);
            m_resetCache.draw(extraTextRect, fillColor);
        }
And finally search for this:
C++:
void Creature::setName(const std::string& name)
{
    m_nameCache.setText(name);
    m_name = name;
}
And add this code after:
[CODE=cpp]
void Creature::setReset(uint32 reset)
{
    m_resetCache.setText(stdext::format("[%i]", reset));
    m_reset = reset;
}

You must change your TFS in order to send the new information too, there is my example:
src/protocolgame.cpp

Code:
////////////// Add common messages
void ProtocolGame::AddCreature(NetworkMessage& msg, const Creature* creature, bool known, uint32_t remove)
{
    CreatureType_t creatureType = creature->getType();

    const Player* otherPlayer = creature->getPlayer();

    if (known) {
        msg.add<uint16_t>(0x62);
        msg.add<uint32_t>(creature->getID());
    } else {
        msg.add<uint16_t>(0x61);
        msg.add<uint32_t>(remove);
        msg.add<uint32_t>(creature->getID());
        msg.addByte(creatureType);

        uint32_t resets = 0;

        if (otherPlayer && otherPlayer->getReset() > 0) {
            msg.addString(creature->getName());
            resets = otherPlayer->getReset();
        }
        else {
            msg.addString(creature->getName());
        }
        msg.add<uint32_t>(resets);
    }
Notice that I added this code:
C++:
        uint32_t resets = 0;

        if (otherPlayer && otherPlayer->getReset() > 0) {
            msg.addString(creature->getName());
            resets = otherPlayer->getReset();
        }
        else {
            msg.addString(creature->getName());
        }
        msg.add<uint32_t>(resets);
 
Last edited:
One possible solution would change those functions in the client side to remove the extra text ' [.*]' before execute the action, or a better approach would be write the level on screen, in the position that you want in the function (client source code):
src/client/creature.cpp

C++:
void Creature:drawInformation

I did something similar in my client (OTCv8), but my goal was show the reset level from my players, the problem is that you must change your TFS too, in order to send the new information to the client:
View attachment 76172
I will post my code here, if you want to change it to level, idk if it is the best way to do it, but here it is:
src/client/creature.h
C++:
    void setReset(uint32 value);
    void resetInformationColor() { m_useCustomInformationColor = false; setHealthPercent(getHealthPercent());  }
    uint32 m_reset;
    CachedText m_resetCache;

src/client/protocolgameparse.cpp
C++:
CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
{
...

            if (g_game.getFeature(Otc::GameTibia12Protocol) && creatureType == Proto::CreatureTypeSummonOwn)
                msg->getU32(); // master

            std::string name = g_game.formatCreatureName(msg->getString());

            uint resets = msg->getU32();
...
 if (creature) {
                    creature->setId(id);
                    creature->setName(name);
                    if (resets && resets > 0) {
                        creature->setReset(resets);
                    }

                    g_map.addCreature(creature);
                }
...
Just add the level/reset code uint resets = msg->getU32(); after the std::string name = g_game.formatCreatureName(msg->getString()); and the code: if (resets && resets > 0) { creature->setReset(resets); } after creature->setName(name);.

And finally change the:
src/client/creature.cpp
Search for this:
C++:
    m_nameCache.setFont(g_fonts.getFont("verdana-11px-rounded"));
    m_nameCache.setAlign(Fw::AlignTopCenter);
And add this code after:
C++:
    m_resetCache.setFont(g_fonts.getFont("verdana-11px-rounded"));
    m_resetCache.setAlign(Fw::AlignTopCenter);
Then search for this:
C++:
           textRect.moveBottomCenter(textCenter);
            m_titleCache.draw(textRect, m_titleColor);
        }
And add this code after:
[CODE=cpp]
        if (m_resetCache.hasText()) {
            Size titleSize = m_resetCache.getTextSize();
            textRect.setSize(titleSize);
            Rect extraTextRect = Rect(textRect.topLeft().x - (textRect.width() + 2), textRect.topLeft().y, titleSize);
            m_resetCache.draw(extraTextRect, fillColor);
        }
And finally search for this:
C++:
void Creature::setName(const std::string& name)
{
    m_nameCache.setText(name);
    m_name = name;
}
And add this code after:
[CODE=cpp]
void Creature::setReset(uint32 reset)
{
    m_resetCache.setText(stdext::format("[%i]", reset));
    m_reset = reset;
}

Você deve alterar seu TFS para enviar as novas informações também, aí está o meu exemplo:
SRC/ProtocolGame.cpp

[CÓDIGO]///// Adicionar mensagens comuns
void ProtocolGame::AddCreature(NetworkMessage& msg, const Creature* criatura, bool conhecido, uint32_t remover)
{
CreatureType_t creatureType = criatura->getType();

const Player* otherPlayer = criatura->getPlayer();

se (conhecido) {
msg.add<uint16_t>(0x62);
msg.add<uint32_t>(criatura->getID());
} else {
msg.add<uint16_t>(0x61);
msg.add<uint32_t>(remover);
msg.add<uint32_t>(criatura->getID());
msg.addByte(creatureType);

uint32_t resets = 0;

if (otherPlayer && otherPlayer->getReset() > 0) {
msg.addString(creature->getName());
resets = otherPlayer->getReset();
}
senão {
msg.addString(creature->getName());
}
msg.add<uint32_t>(redefinições);
}[/CÓDIGO]
Observe que adicionei este código:
C++:
        uint32_t resets = 0;

        if (otherPlayer && otherPlayer->getReset() > 0) {
            msg.addString(creature->getName());
            resets = otherPlayer->getReset();
        }
senão {
            msg.addString(creature->getName());
        }
msg.add<uint32_t>(redefinições); [/CÓDIGO]
[/QUOTE]
amigo, meu sistema de reset é por armazenamento > 378378!! como seria? Estou tentando, mas não consigo :(
Post automatically merged:

friend, my system reset is by storage > 378378!! how would it be? I'm trying but I can't :(
 
Back
Top