• 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 1.X+ Error in "ProtocolGame::AddPlayerStats"

Derlexy

Intermediate OT User
Joined
Jun 29, 2011
Messages
219
Reaction score
101
Hello guys, i need your help once again...

I've added a new type of mana in my server (i call it spirit). Now, i have to send it to my client, to be able to read and show it. I found this function that seems to do it (send player stats to the client), and tried to add some more bytes like this:

Original:
C++:
void ProtocolGame::AddPlayerStats(NetworkMessage& msg)
{
    msg.addByte(0xA0);

    msg.add<uint16_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max()));
    msg.add<uint16_t>(std::min<int32_t>(player->getMaxHealth(), std::numeric_limits<uint16_t>::max()));
    msg.add<uint16_t>(static_cast<uint16_t>(player->getFreeCapacity() / 100.));
    if (player->getExperience() >= std::numeric_limits<uint32_t>::max()) {
        msg.add<uint32_t>(0);
    } else {
        msg.add<uint32_t>(static_cast<uint32_t>(player->getExperience()));
    }
    msg.add<uint16_t>(static_cast<uint16_t>(player->getLevel()));
    msg.addByte(player->getLevelPercent());
    msg.add<uint16_t>(std::min<int32_t>(player->getMana(), std::numeric_limits<uint16_t>::max()));
    msg.add<uint16_t>(std::min<int32_t>(player->getMaxMana(), std::numeric_limits<uint16_t>::max()));

    msg.addByte(std::min<uint32_t>(player->getMagicLevel(), std::numeric_limits<uint8_t>::max()));
    msg.addByte(player->getMagicLevelPercent());

    msg.addByte(player->getSoul());
}

With my changes:
C++:
void ProtocolGame::AddPlayerStats(NetworkMessage& msg)
{
    msg.addByte(0xA0);

    msg.add<uint16_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max()));
    msg.add<uint16_t>(std::min<int32_t>(player->getMaxHealth(), std::numeric_limits<uint16_t>::max()));
    msg.add<uint16_t>(static_cast<uint16_t>(player->getFreeCapacity() / 100.));
    if (player->getExperience() >= std::numeric_limits<uint32_t>::max()) {
        msg.add<uint32_t>(0);
    } else {
        msg.add<uint32_t>(static_cast<uint32_t>(player->getExperience()));
    }
    msg.add<uint16_t>(static_cast<uint16_t>(player->getLevel()));
    msg.addByte(player->getLevelPercent());
    msg.add<uint16_t>(std::min<int32_t>(player->getMana(), std::numeric_limits<uint16_t>::max()));
    msg.add<uint16_t>(std::min<int32_t>(player->getMaxMana(), std::numeric_limits<uint16_t>::max()));

    msg.addByte(std::min<uint32_t>(player->getMagicLevel(), std::numeric_limits<uint8_t>::max()));
    msg.addByte(player->getMagicLevelPercent());

    msg.addByte(player->getSoul());

    msg.add<uint16_t>(std::min<int32_t>(player->getSpirit(), std::numeric_limits<uint16_t>::max()));
    msg.add<uint16_t>(std::min<int32_t>(player->getMaxSpirit(), std::numeric_limits<uint16_t>::max()));
}

As you can see, i just added this at the end:
C++:
msg.add<uint16_t>(std::min<int32_t>(player->getSpirit(), std::numeric_limits<uint16_t>::max()));
msg.add<uint16_t>(std::min<int32_t>(player->getMaxSpirit(), std::numeric_limits<uint16_t>::max()));

I compiled the server and i got no errors. But when i try to run the server, i get the following:
bU9NGhe.png


What am I missing? I forget to do something in another place?

Im currently using Nostalrius distro, that is TFS 1.2 based. Repository here: GitHub - Ezzz-dev/Nostalrius: Nostalrius is a 7.7 Tibia Clone Project based on The Forgotten Server 1.2 and CipSoft files. (https://github.com/Ezzz-dev/Nostalrius)
 
You have to be a lil more specific.
To send the values, you have to create the functions to the "spirit", register also in the protocolgame.h.
If you dont, the server doesnt recognize the information it has to send.
If you're using otclient, there more easy ways to send data.
 
You have to be a lil more specific.
To send the values, you have to create the functions to the "spirit", register also in the protocolgame.h.
If you dont, the server doesnt recognize the information it has to send.
If you're using otclient, there more easy ways to send data.

You have to be a lil more specific.
To send the values, you have to create the functions to the "spirit", register also in the protocolgame.h.

I have the spirit functions working on my server. In the protocolgame.h, there is nothing about getMana() aswell... And it is sent to the cliente through this function anyway...

Im using OTCv8.
How can i do it more easily?
 
Trough opcodes.
If you're using 1.2 and otcv8.

Go to creaturescripts/scripts/extendedopcode.lua
and somewhere above


function onExtendedOpcode(player, opcode, buffer)
You can inset your code.



Lua:
  local SpiritCode = 99
  if (or elseif) opcode == SpiritCode then
      if string.find(buffer, "spirit") then
        player:getSpirit()
        player:getMaxSpirit()
        end
  end


then in the module you want to receive the information:


Inside init function

Code:
  ProtocolGame.registerExtendedOpcode(99, getSpirit)


and above with other functions

create a new function:


Code:
function getSpirit(protocol, opcode, buffer)
    --inset the code here
end



I'm out of home now, so, I can help only with tips. I hope it helps you to figure out how to.
 
Problem solved. Dont even know why, but i removed the build folder of the TFS, recreate and recompiled it, then it get back to work again.
 
Back
Top