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

C++ [TFS 0x] Life Leech ?

Mokk

New Member
Joined
Jun 2, 2023
Messages
12
Reaction score
4
Hello everyone,

I would like to know if someone could help me add new attributes in TFS 0.4 like Life Leech/Absorb for example.

I appreciate everyone's attention, thank you very much!
 
Solution
in combat.cpp in bool Combat::CombatHealthFunc add

Code:
if(caster->getPlayer()&& params.combatType != COMBAT_HEALING )
        {
            int32_t Lifeleech = caster->getPlayer()->getLifeLeechAmount(); // you can set it empty storage
            int32_t Lifeleechchance = caster->getPlayer()->getLifeLeechChance(); // you can set it empty storage
            if(Lifeleech > 0)
            {
                int32_t amount = std::abs((int32_t)std::floor((change * (Lifeleech / 100.))));
                if(amount > 0 && random_range(1, 100) <= Lifeleechchance)
                {
                        g_game.combatChangeHealth(COMBAT_HEALING, caster->getPlayer(), caster->getPlayer(), amount)...
in combat.cpp in bool Combat::CombatHealthFunc add

Code:
if(caster->getPlayer()&& params.combatType != COMBAT_HEALING )
        {
            int32_t Lifeleech = caster->getPlayer()->getLifeLeechAmount(); // you can set it empty storage
            int32_t Lifeleechchance = caster->getPlayer()->getLifeLeechChance(); // you can set it empty storage
            if(Lifeleech > 0)
            {
                int32_t amount = std::abs((int32_t)std::floor((change * (Lifeleech / 100.))));
                if(amount > 0 && random_range(1, 100) <= Lifeleechchance)
                {
                        g_game.combatChangeHealth(COMBAT_HEALING, caster->getPlayer(), caster->getPlayer(), amount);
                        g_game.addMagicEffect(pCaster->getPosition(), MAGIC_EFFECT_WRAPS_RED); // add effect you want here
                }
            }
        }
that how life leech work u can make same for mana leech
will work for spells and weapons
 
Solution
Why not using tfs 1.x ?
Because my server on TFS 0.4 is almost ready, I tried to use 1x versions but I couldn't add some modifications in the font that for my server is essential, in addition to some scripts that I couldn't adapt to 1x, so I decided to stay on 0.4, what I lack is just that of adding new attributes like Life Leech for example
Post automatically merged:

Issue resolved with @Elgenady support
 
Last edited:
in combat.cpp in bool Combat::CombatHealthFunc add

Code:
if(caster->getPlayer()&& params.combatType != COMBAT_HEALING )
        {
            int32_t Lifeleech = caster->getPlayer()->getLifeLeechAmount(); // you can set it empty storage
            int32_t Lifeleechchance = caster->getPlayer()->getLifeLeechChance(); // you can set it empty storage
            if(Lifeleech > 0)
            {
                int32_t amount = std::abs((int32_t)std::floor((change * (Lifeleech / 100.))));
                if(amount > 0 && random_range(1, 100) <= Lifeleechchance)
                {
                        g_game.combatChangeHealth(COMBAT_HEALING, caster->getPlayer(), caster->getPlayer(), amount);
                        g_game.addMagicEffect(pCaster->getPosition(), MAGIC_EFFECT_WRAPS_RED); // add effect you want here
                }
            }
        }
that how life leech work u can make same for mana leech
will work for spells and weapons
@Elgenady how to add this by storage? Example, i have storage 8312 with value 10, so it means 10% life leech. I want the same thing for mana leech, can u show me the code merging with my critical system?

C++:
bool Combat::CombatHealthFunc(Creature* caster, Creature* target, const CombatParams& params, void* data)
{
    int32_t change = 0;
    if(Combat2Var* var = (Combat2Var*)data)
    {
        change = var->change;
        if(!change)
            change = random_range(var->minChange, var->maxChange, DISTRO_NORMAL);
    }

    Monster* mCaster = NULL;
    Player* pCaster = NULL;

    if(caster)
        {
            pCaster = caster->getPlayer();
            mCaster = caster->getMonster();
        }

    if(pCaster && params.combatType != COMBAT_HEALING)
        {
            std::string value;
             pCaster->getStorage("794750", value);
             int32_t intValue = (int32_t)(atoi(value.c_str()));
              int32_t chnace = static_cast<int32_t>(intValue *0.2);
            if(random_range(1, 100) <= chnace)
            {
              int32_t critdamage = pCaster->getCriticalDamage();
            if(critdamage > 0)
                 change  = static_cast<int32_t>(change +((change*critdamage)/100));
                g_game.addMagicEffect(target->getPosition(), MAGIC_EFFECT_STUN); //change here ***
                g_game.addAnimatedText(target->getPosition(), 144, "CRITICAL!");
            }
        }

    if(g_game.combatBlockHit(params.combatType, caster, target, change, params.blockedByShield, params.blockedByArmor, params.itemId != 0))
        return false;

    CombatParams _params = params;
    if(_params.element.damage && _params.element.type != COMBAT_NONE)
        g_game.combatBlockHit(_params.element.type, caster, target, _params.element.damage, params.blockedByShield, params.blockedByArmor, params.itemId != 0, true);

    if(caster && caster->getPlayer() && target->getPlayer())
    {
        _params.element.damage /= 2;
        if(change < 0)
            change /= 2;
    }

    if(!g_game.combatChangeHealth(_params, caster, target, change, false))
        return false;

    CombatConditionFunc(caster, target, params, NULL);
    CombatDispelFunc(caster, target, params, NULL);
    return true;
}
Post automatically merged:

This is mana function:

C++:
bool Combat::CombatManaFunc(Creature* caster, Creature* target, const CombatParams& params, void* data)
{
    int32_t change = 0;
    if(Combat2Var* var = (Combat2Var*)data)
    {
        change = var->change;
        if(!change)
            change = random_range(var->minChange, var->maxChange, DISTRO_NORMAL);
    }

    if(g_game.combatBlockHit(COMBAT_MANADRAIN, caster, target, change, false, false, params.itemId != 0))
        return false;

    if(change < 0 && caster && caster->getPlayer() && target->getPlayer())
        change /= 2;

    if(!g_game.combatChangeMana(caster, target, change))
        return false;

    CombatConditionFunc(caster, target, params, NULL);
    CombatDispelFunc(caster, target, params, NULL);
    return true;
}

And i have already created those functions:

C++:
int32_t Player::getLifeLeechChance() const
{
    int32_t Lifeleechchancestorage = 0;
    std::string value;
    if (getStorage("48700", value)) {
        Lifeleechchancestorage = (int32_t)(atoi(value.c_str()));
    }

    return Lifeleechchancestorage;
}
int32_t Player::getLifeLeechAmount() const
{
    int32_t Lifeleechamountstorage = 0;
    std::string value;
    if (getStorage("48701", value)) {
        Lifeleechamountstorage = (int32_t)(atoi(value.c_str()));
    }

    return Lifeleechamountstorage;
}
int32_t Player::getManaLeechChance() const
{
    int32_t Manaleechchancestorage = 0;
    std::string value;
    if (getStorage("48600", value)) {
        Manaleechchancestorage = (int32_t)(atoi(value.c_str()));
    }

    return Manaleechchancestorage;
}
int32_t Player::getManaLeechAmount() const
{
    int32_t Manaleechamountstorage = 0;
    std::string value;
    if (getStorage("48601", value)) {
        Manaleechamountstorage = (int32_t)(atoi(value.c_str()));
    }

    return Manaleechamountstorage;
}
 
Last edited:
LUA:
if(pCaster&& params.combatType != COMBAT_HEALING)
        {
            int32_t Lifeleech = caster->getPlayer()->getLifeLeechAmount();
            int32_t Lifeleechchance = caster->getPlayer()->getLifeLeechChance();
            if(Lifeleech > 0)
            {
                int32_t amount = std::abs((int32_t)std::floor((change * (Lifeleech / 100.))));
                if(amount > 0 && random_range(1, 100) <= Lifeleechchance)
                {
                        g_game.combatChangeHealth(COMBAT_HEALING, caster->getPlayer(), caster->getPlayer(), amount);
                        g_game.addMagicEffect(caster->getPlayer()->getPosition(), MAGIC_EFFECT_WRAPS_RED);
                }
            }
        }

        if(pCaster&& params.combatType != COMBAT_HEALING)
        {
            int32_t Manaleech = caster->getPlayer()->getManaLeechAmount();
            int32_t Manaleechchance = caster->getPlayer()->getManaLeechChance();
            if(Manaleech > 0 )
            {
                int32_t amount = std::abs((int32_t)std::floor((change * (Manaleech / 100.))));
                if(amount > 0 && random_range(1, 100) <= Manaleechchance)
                {
                    g_game.combatChangeMana(caster->getPlayer(), caster->getPlayer(), amount);
                    g_game.addMagicEffect(caster->getPlayer()->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
                }
            }
        }
2 code in bool Combat::CombatHealthFunc
 

Similar threads

Back
Top