• 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 [C++] TFS - 0.3.6 - 8.60 - Help Channel Bot - I can't compile it. Please help me. Support for the onTalk function.

samuel157

/root
Joined
Mar 19, 2010
Messages
518
Solutions
3
Reaction score
71
Location
São Paulo, Brazil
GitHub
Samuel10M
Code:
Here is the English translation of your full guide for adding a Help Channel auto-reply bot ("Tutor Bot") to TFS 0.3.6 (Tibia 8.60) by modifying the source code to support a new onTalk creature event:

✅ Step-by-step: Creating an Auto-Reply Tutor Bot for the Help Channel
🧠 Context:
TFS 0.3.6 does not support the onTalk event for channels by default in creaturescripts.
To make this work, we must add native support for onTalk, then register a Lua script that listens to the Help Channel (ID 9) and replies automatically if the admin (ADM) is offline.

✅ 1. Enable the onTalk creature event in the source code
📄 File: luascript.cpp
🔍 Find the function:

cpp
Copiar
Editar
void LuaScriptInterface::registerFunctions()
➡️ Add this line inside the function (if not already present):

cpp
Copiar
Editar
lua_register(m_luaState, "registerCreatureEvent", LuaInterface::luaRegisterCreatureEvent);
📄 File: creatureevent.h
Find the enum CreatureEventType and add this new type:

cpp
Copiar
Editar
enum CreatureEventType
{
    ...
    CREATURE_EVENT_CHANNEL,
    ...
    CREATURE_EVENT_TALK, // ✅ Add this
};
📄 File: creatureevent.cpp
In the function:

cpp
Copiar
Editar
CreatureEventType CreatureEvents::getType(const std::string& str)
➡️ Add:

cpp
Copiar
Editar
else if(str == "talk")
    return CREATURE_EVENT_TALK; // ✅ new
Also in:

cpp
Copiar
Editar
bool CreatureEvent::configureEvent(xmlNodePtr p)
➡️ Add support:

cpp
Copiar
Editar
if(m_type == CREATURE_EVENT_TALK)
    m_interface->reserveScriptEnv(); // reserve environment
✅ 2. Call the event onTalk when a player speaks in a channel
📄 File: chat.cpp
Find the function:

cpp
Copiar
Editar
bool Chat::talkToChannel(Player* player, MessageClasses type, const std::string& text, uint16_t channelId)
➡️ At the start of the function, add:

cpp
Copiar
Editar
if (player) {
    CreatureEventList talkEvents = player->getCreatureEvents(CREATURE_EVENT_TALK);
    for(CreatureEventList::iterator it = talkEvents.begin(); it != talkEvents.end(); ++it)
        (*it)->executeTalk(player, type, text, channelId);
}
✅ 3. Add the function executeTalk in CreatureEvent
📄 File: creatureevent.cpp
Add this function:

cpp
Copiar
Editar
bool CreatureEvent::executeTalk(Creature* creature, MessageClasses type, const std::string& text, uint16_t channel)
{
    if(m_type != CREATURE_EVENT_TALK)
        return false;

    if (!m_interface->reserveScriptEnv()) {
        std::cout << "[Error - CreatureEvent::executeTalk] Call stack overflow." << std::endl;
        return false;
    }

    ScriptEnviroment* env = m_interface->getScriptEnv();
    env->setScriptId(m_scriptId, m_interface);
    env->setRealPos(creature->getPosition());

    lua_State* L = m_interface->getLuaState();
    m_interface->pushFunction(m_scriptId);

    LuaScriptInterface::pushThing(L, creature, false);
    lua_pushnumber(L, type);
    lua_pushstring(L, text.c_str());
    lua_pushnumber(L, channel);

    return m_interface->callFunction(4);
}
📄 File: creatureevent.h
Add this at the end of the CreatureEvent class:

cpp
Copiar
Editar
bool executeTalk(Creature* creature, MessageClasses type, const std::string& text, uint16_t channel);
✅ 4. Create the Lua script: help_bot.lua
📄 File: data/creaturescripts/scripts/help_bot.lua
Create this file and add:

lua
Copiar
Editar
local ADM_NAME = "ADM" -- Name of your admin character
local HELP_CHANNEL_ID = 9

function onTalk(cid, type, channel, msg)
    if channel == HELP_CHANNEL_ID then
        local admPlayer = getPlayerByNameWildcard(ADM_NAME)
        if not isPlayer(admPlayer) then
            doPlayerSendChannelMessage(0, "Tutor Bot",
                "For support, please email the admin at: [email protected] or WhatsApp: +55 11 91230-8360.",
                TALKTYPE_CHANNEL_O, HELP_CHANNEL_ID)
        end
    end
    return true
end
✅ 5. Register the event in creaturescripts.xml
📄 File: data/creaturescripts/creaturescripts.xml
Add:

xml
Copiar
Editar
<event type="talk" name="HelpBot" script="help_bot.lua"/>
✅ 6. Register the event on player login
📄 File: data/creaturescripts/scripts/login.lua
Inside the onLogin(cid) function, add:

lua
Copiar
Editar
registerCreatureEvent(cid, "HelpBot")
 
Back
Top