Animated Text Support for OT Client 10.98/99 - TFS 1.3

Void_

Banned User
Joined
Jan 7, 2018
Messages
9
Reaction score
7
I discovered that OT Client can support animated text in higher client versions of tibia. To do this its very simple.

Open up compat.lua and find
Lua:
function doSendAnimatedText() debugPrint("Deprecated function.") return true end
and replace it with this
Lua:
function doSendAnimatedText(message, position, color) return Game.sendAnimatedText(message, position, color) end
Open up game.cpp and find this
C++:
void Game::addCreatureHealth(const SpectatorHashSet& spectators, const Creature* target)
{
    for (Creature* spectator : spectators) {
        if (Player* tmpPlayer = spectator->getPlayer()) {
            tmpPlayer->sendCreatureHealth(target);
        }
    }
}
and place this right underneath
C++:
void Game::addAnimatedText(const std::string& message, const Position& pos, TextColor_t color)
{
    SpectatorHashSet spectators;
    map.getSpectators(spectators, pos, true, true);
    addAnimatedText(spectators, message, pos, color);
}


void Game::addAnimatedText(const SpectatorHashSet& spectators, const std::string& message, const Position& pos, TextColor_t color)
{
    for (Creature* spectator : spectators) {
        if (Player* tmpPlayer = spectator->getPlayer()) {
            tmpPlayer->sendAnimatedText(message, pos, color);
        }
    }
}
Open up game.h and find this
C++:
        void addCreatureHealth(const Creature* target);
        static void addCreatureHealth(const SpectatorHashSet& spectators, const Creature* target);
and place this right underneath
C++:
        void addAnimatedText(const std::string& message, const Position& pos, TextColor_t color);
        static void addAnimatedText(const SpectatorHashSet& spectators, const std::string& message, const Position& pos, TextColor_t color);

Open up luascript.cpp and find this
C++:
registerMethod("Game", "reload", LuaScriptInterface::luaGameReload);
and place this right underneath
C++:
registerMethod("Game", "sendAnimatedText", LuaScriptInterface::luaGameSendAnimatedText);
Then find this
C++:
int LuaScriptInterface::luaGameReload(lua_State* L)
{
    // Game.reload(reloadType)
    ReloadTypes_t reloadType = getNumber<ReloadTypes_t>(L, 1);
    if (reloadType == RELOAD_TYPE_GLOBAL) {
        pushBoolean(L, g_luaEnvironment.loadFile("data/global.lua") == 0);
    } else {
        pushBoolean(L, g_game.reload(reloadType));
    }
    lua_gc(g_luaEnvironment.getLuaState(), LUA_GCCOLLECT, 0);
    return 1;
}
and place this right underneath
C++:
int LuaScriptInterface::luaGameSendAnimatedText(lua_State* L)
{
    // Game.sendAnimatedText(message, position, color)
    int parameters = lua_gettop(L);
    if (parameters < 3) {
        pushBoolean(L, false);
        return 1;
    }

    TextColor_t color = getNumber<TextColor_t>(L, 3);
    const Position& position = getPosition(L, 2);
    const std::string& message = getString(L, 1);

    if (!position.x || !position.y) {
        pushBoolean(L, false);
        return 1;
    }

    g_game.addAnimatedText(message, position, color);
    pushBoolean(L, true);
    return 1;
}

Open up luascript.h and find this
C++:
static int luaGameReload(lua_State* L);
and place this right underneath
C++:
static int luaGameSendAnimatedText(lua_State* L);
Next open up player.h and find this
C++:
       void sendCreatureShield(const Creature* creature) {
           if (client) {
               client->sendCreatureShield(creature);
           }
       }
and place this right underneath
C++:
        void sendAnimatedText(const std::string& message, const Position& pos, TextColor_t color) {
            if (client) {
                client->sendAnimatedText(message, pos, color);
            }
        }

Now open up protocolgame.cpp and find this
C++:
void ProtocolGame::sendVIPEntries()
{
    const std::forward_list<VIPEntry>& vipEntries = IOLoginData::getVIPEntries(player->getAccount());

    for (const VIPEntry& entry : vipEntries) {
        VipStatus_t vipStatus = VIPSTATUS_ONLINE;

        Player* vipPlayer = g_game.getPlayerByGUID(entry.guid);

        if (!vipPlayer || vipPlayer->isInGhostMode() || player->isAccessPlayer()) {
            vipStatus = VIPSTATUS_OFFLINE;
        }

        sendVIP(entry.guid, entry.name, entry.description, entry.icon, entry.notify, vipStatus);
    }
}
place this right underneath
C++:
void ProtocolGame::sendAnimatedText(const std::string& message, const Position& pos, TextColor_t color)
{
    if (!canSee(pos)) {
        return;
    }

    NetworkMessage msg;
    msg.addByte(0x84);
    msg.addPosition(pos);
    msg.addByte(color);
    msg.addString(message);
    writeToOutputBuffer(msg);
}
Finally open protocolgame.h and find this
C++:
void sendVIPEntries();
and place this right underneath
C++:
void sendAnimatedText(const std::string& message, const Position& pos, TextColor_t color);
Here is a demonstration of this in action

The code used in the video demonstration, this goes in login.lua
Lua:
    local pos = player:getPosition()
    local colors = {5,30,35,95,108,129,143,155,180,198,210,215}
    for i = 1, #colors do
        addEvent(function(x, c)
            Game.sendAnimatedText('this is where i spawned', x, c)
        end, i * 1000, pos, colors[i])
    end
 
OP
V

Void_

Banned User
Joined
Jan 7, 2018
Messages
9
Reaction score
7
This should work in any version or distribution which supports at the very least TFS 1.x code structure but given enough knowledge in C++ anyone can adapt this to their distribution (within reason of course)
 

Awesomedudei

Revolutionot.com
Joined
Jan 20, 2010
Messages
266
Reaction score
36
Location
Sweden
TFS 1.3 10.98

Followed everything to 100% and client crashes 1 second after joining the world.
 

Ahilphino

Veteran OT User
Joined
Jun 5, 2013
Messages
1,383
Reaction score
404
you need otclient to use this
it will crash in normal client because cipsoft removed ability to use animated text with letters in some client after 9.x
 

gicu0770

Intermediate OT User
Joined
Feb 26, 2011
Messages
101
Reaction score
13
Working good on TFS 1.2 too but i change one function:
this
SpectatorHashSet
to
SpectatorVec

on all scripts and working :)
You are best!
 

gicu0770

Intermediate OT User
Joined
Feb 26, 2011
Messages
101
Reaction score
13
I discovered that OT Client can support animated text in higher client versions of tibia. To do this its very simple.

Open up compat.lua and find
Lua:
function doSendAnimatedText() debugPrint("Deprecated function.") return true end
and replace it with this
Lua:
function doSendAnimatedText(message, position, color) return Game.sendAnimatedText(message, position, color) end
Open up game.cpp and find this
C++:
void Game::addCreatureHealth(const SpectatorHashSet& spectators, const Creature* target)
{
    for (Creature* spectator : spectators) {
        if (Player* tmpPlayer = spectator->getPlayer()) {
            tmpPlayer->sendCreatureHealth(target);
        }
    }
}
and place this right underneath
C++:
void Game::addAnimatedText(const std::string& message, const Position& pos, TextColor_t color)
{
    SpectatorHashSet spectators;
    map.getSpectators(spectators, pos, true, true);
    addAnimatedText(spectators, message, pos, color);
}


void Game::addAnimatedText(const SpectatorHashSet& spectators, const std::string& message, const Position& pos, TextColor_t color)
{
    for (Creature* spectator : spectators) {
        if (Player* tmpPlayer = spectator->getPlayer()) {
            tmpPlayer->sendAnimatedText(message, pos, color);
        }
    }
}
Open up game.h and find this
C++:
        void addCreatureHealth(const Creature* target);
        static void addCreatureHealth(const SpectatorHashSet& spectators, const Creature* target);
and place this right underneath
C++:
        void addAnimatedText(const std::string& message, const Position& pos, TextColor_t color);
        static void addAnimatedText(const SpectatorHashSet& spectators, const std::string& message, const Position& pos, TextColor_t color);

Open up luascript.cpp and find this
C++:
registerMethod("Game", "reload", LuaScriptInterface::luaGameReload);
and place this right underneath
C++:
registerMethod("Game", "sendAnimatedText", LuaScriptInterface::luaGameSendAnimatedText);
Then find this
C++:
int LuaScriptInterface::luaGameReload(lua_State* L)
{
    // Game.reload(reloadType)
    ReloadTypes_t reloadType = getNumber<ReloadTypes_t>(L, 1);
    if (reloadType == RELOAD_TYPE_GLOBAL) {
        pushBoolean(L, g_luaEnvironment.loadFile("data/global.lua") == 0);
    } else {
        pushBoolean(L, g_game.reload(reloadType));
    }
    lua_gc(g_luaEnvironment.getLuaState(), LUA_GCCOLLECT, 0);
    return 1;
}
and place this right underneath
C++:
int LuaScriptInterface::luaGameSendAnimatedText(lua_State* L)
{
    // Game.sendAnimatedText(message, position, color)
    int parameters = lua_gettop(L);
    if (parameters < 3) {
        pushBoolean(L, false);
        return 1;
    }

    TextColor_t color = getNumber<TextColor_t>(L, 3);
    const Position& position = getPosition(L, 2);
    const std::string& message = getString(L, 1);

    if (!position.x || !position.y) {
        pushBoolean(L, false);
        return 1;
    }

    g_game.addAnimatedText(message, position, color);
    pushBoolean(L, true);
    return 1;
}

Open up luascript.h and find this
C++:
static int luaGameReload(lua_State* L);
and place this right underneath
C++:
static int luaGameSendAnimatedText(lua_State* L);
Next open up player.h and find this
C++:
       void sendCreatureShield(const Creature* creature) {
           if (client) {
               client->sendCreatureShield(creature);
           }
       }
and place this right underneath
C++:
        void sendAnimatedText(const std::string& message, const Position& pos, TextColor_t color) {
            if (client) {
                client->sendAnimatedText(message, pos, color);
            }
        }

Now open up protocolgame.cpp and find this
C++:
void ProtocolGame::sendVIPEntries()
{
    const std::forward_list<VIPEntry>& vipEntries = IOLoginData::getVIPEntries(player->getAccount());

    for (const VIPEntry& entry : vipEntries) {
        VipStatus_t vipStatus = VIPSTATUS_ONLINE;

        Player* vipPlayer = g_game.getPlayerByGUID(entry.guid);

        if (!vipPlayer || vipPlayer->isInGhostMode() || player->isAccessPlayer()) {
            vipStatus = VIPSTATUS_OFFLINE;
        }

        sendVIP(entry.guid, entry.name, entry.description, entry.icon, entry.notify, vipStatus);
    }
}
place this right underneath
C++:
void ProtocolGame::sendAnimatedText(const std::string& message, const Position& pos, TextColor_t color)
{
    if (!canSee(pos)) {
        return;
    }

    NetworkMessage msg;
    msg.addByte(0x84);
    msg.addPosition(pos);
    msg.addByte(color);
    msg.addString(message);
    writeToOutputBuffer(msg);
}
Finally open protocolgame.h and find this
C++:
void sendVIPEntries();
and place this right underneath
C++:
void sendAnimatedText(const std::string& message, const Position& pos, TextColor_t color);
Here is a demonstration of this in action

The code used in the video demonstration, this goes in login.lua
Lua:
    local pos = player:getPosition()
    local colors = {5,30,35,95,108,129,143,155,180,198,210,215}
    for i = 1, #colors do
        addEvent(function(x, c)
            Game.sendAnimatedText('this is where i spawned', x, c)
        end, i * 1000, pos, colors[i])
    end
Can no stack text?
 

darkmubr

Member
Joined
Mar 8, 2019
Messages
40
Reaction score
10
Video offline.


How i add animated text in login.lua? Vídeo offline

i got error with:

local pos = player:getPosition()
local colors = {5,30,35,95,108,129,143,155,180,198,210,215}
for i = 1, #colors do
addEvent(function(x, c)
Game.sendAnimatedText('this is where i spawned', x, c)
end, i * 1000, pos, colors)
end
 
Top