• 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!

Feature [CreatureEvent] onSoulChange(cid, value) - Trigger functions when soul points change!

Exedion

Active Member
Joined
Jun 11, 2007
Messages
628
Reaction score
30
Hello to all! :D well some time ago i want to make a system to get magic level and some other functions with the ever forgotten soul points in tibia, but i ever find a limit: no function to trigger the system :/... so i decide to read the sourcers and do the function by myself :D and here is the result:

[size=+3]onSoulChange(cid, value)[/size]​

  • cid = player
  • value = return the value of soul points used(gain/loss) when the function is triggered.


Now the code!

In creatureevent.cpp:

  • After of...
    [cpp]
    else if(type == "advance")
    _type = CREATURE_EVENT_ADVANCE;
    [/cpp]
  • Add
    [cpp]
    else if(type == "soulchange")
    _type = CREATURE_EVENT_SOULCHANGE;
    [/cpp]
  • After of...
    [cpp]
    case CREATURE_EVENT_ADVANCE:
    return "onAdvance";
    [/cpp]
  • Add
    [cpp]
    case CREATURE_EVENT_SOULCHANGE:
    return "onSoulChange";
    [/cpp]
  • After of...
    [cpp]
    case CREATURE_EVENT_ADVANCE:
    return "cid, skill, oldLevel, newLevel";
    [/cpp]
  • Add
    [cpp]
    case CREATURE_EVENT_SOULCHANGE:
    return "cid, value";
    [/cpp]
  • After the whole function...
    [cpp]
    uint32_t CreatureEvent::executeAdvance(Player* player, skills_t skill, uint32_t oldLevel, uint32_t newLevel)
    {
    //onAdvance(cid, skill, oldLevel, newLevel)
    if(m_interface->reserveEnv())
    {
    ScriptEnviroment* env = m_interface->getEnv();
    if(m_scripted == EVENT_SCRIPT_BUFFER)
    {
    env->setRealPos(player->getPosition());
    std::stringstream scriptstream;
    scriptstream << "local cid = " << env->addThing(player) << std::endl;

    scriptstream << "local skill = " << skill << std::endl;
    scriptstream << "local oldLevel = " << oldLevel << std::endl;
    scriptstream << "local newLevel = " << newLevel << std::endl;

    if(m_scriptData)
    scriptstream << *m_scriptData;

    bool result = true;
    if(m_interface->loadBuffer(scriptstream.str()))
    {
    lua_State* L = m_interface->getState();
    result = m_interface->getGlobalBool(L, "_result", true);
    }

    m_interface->releaseEnv();
    return result;
    }
    else
    {
    #ifdef __DEBUG_LUASCRIPTS__
    char desc[35];
    sprintf(desc, "%s", player->getName().c_str());
    env->setEvent(desc);
    #endif

    env->setScriptId(m_scriptId, m_interface);
    env->setRealPos(player->getPosition());

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

    lua_pushnumber(L, env->addThing(player));
    lua_pushnumber(L, (uint32_t)skill);

    lua_pushnumber(L, oldLevel);
    lua_pushnumber(L, newLevel);

    bool result = m_interface->callFunction(4);
    m_interface->releaseEnv();
    return result;
    }
    }
    else
    {
    std::clog << "[Error - CreatureEvent::executeAdvance] Call stack overflow." << std::endl;
    return 0;
    }
    }
    [/cpp]
  • Add this whole function
    [cpp]
    uint32_t CreatureEvent::executeSoulChange(Player* player, int32_t value)
    {
    //onSoulChange(cid, value)
    if(m_interface->reserveEnv())
    {
    ScriptEnviroment* env = m_interface->getEnv();
    if(m_scripted == EVENT_SCRIPT_BUFFER)
    {
    env->setRealPos(player->getPosition());
    std::stringstream scriptstream;

    scriptstream << "local cid = " << env->addThing(player) << std::endl;
    scriptstream << "local value = " << value << std::endl;

    scriptstream << m_scriptData;
    bool result = true;
    if(m_interface->loadBuffer(scriptstream.str()))
    {
    lua_State* L = m_interface->getState();
    result = m_interface->getGlobalBool(L, "_result", true);
    }

    m_interface->releaseEnv();
    return result;
    }
    else
    {
    #ifdef __DEBUG_LUASCRIPTS__
    char desc[35];
    sprintf(desc, "%s", player->getName().c_str());
    env->setEvent(desc);
    #endif

    env->setScriptId(m_scriptId, m_interface);
    env->setRealPos(player->getPosition());

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

    lua_pushnumber(L, env->addThing(player));
    lua_pushnumber(L, value);

    bool result = m_interface->callFunction(2);
    m_interface->releaseEnv();
    return result;
    }
    }
    else
    {
    std::clog << "[Error - CreatureEvent::executeGainExp] Call stack overflow." << std::endl;
    return 0;
    }
    }
    [/cpp]

In creatureevent.h:
  • After of...
    [cpp]
    CREATURE_EVENT_ADVANCE,
    [/cpp]
  • Add
    [cpp]
    CREATURE_EVENT_SOULCHANGE,
    [/cpp]
  • After of...
    [cpp]
    uint32_t executeAdvance(Player* player, skills_t skill, uint32_t oldLevel, uint32_t newLevel);
    [/cpp]
  • Add
    [cpp]
    uint32_t executeSoulChange(Player* player, int32_t value);
    [/cpp]

In player.cpp:
  • Find this whole function...
    [cpp]
    void Player::changeSoul(int32_t soulChange)
    {
    if(!hasFlag(PlayerFlag_HasInfiniteSoul))
    soul = std::min((int32_t)soulMax, (int32_t)soul + soulChange);

    sendStats();
    }
    [/cpp]
  • Replace with this code...
    [cpp]
    void Player::changeSoul(int32_t soulChange)
    {

    CreatureEventList soulChangeEvents = getCreatureEvents(CREATURE_EVENT_SOULCHANGE);
    for(CreatureEventList::iterator it = soulChangeEvents.begin(); it != soulChangeEvents.end(); ++it)
    (*it)->executeSoulChange(this, soulChange);

    if(!hasFlag(PlayerFlag_HasInfiniteSoul))
    soul = std::min((int32_t)soulMax, (int32_t)soul + soulChange);

    sendStats();
    }
    [/cpp]

    [size=+2]Compile and it's done![/size]

    Example:
    • With a lua code like this...
      Lua:
      function onSoulChange(cid, value)
      		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You soul change ".. value .." values.")
      	return true
      end
    • You will get this message when you use a spell with 2 soulpoints in cost or use a function to remove 2 soulpoints:
      Code:
      You soul change [color=red]-2[/color] values.
    • Or you will get this message when you recover 2 soulpoints hunting (configured) or use a function to add 2 soulpoints:
      Code:
      You soul change [color=red]2[/color] values.


    Compatible with tfs dev 0.4 and pre-release 0.3.7, please coment and enjoy :)
 
Last edited:
Lua:
 case CREATURE_EVENT_SOULCHANGE:
			return "cid value";
To
Lua:
 case CREATURE_EVENT_SOULCHANGE:
			return "cid, value";
 
Back
Top