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

Compiling [TFS 1.2] condition to abosrb damage

Cornwallis

Member
Joined
Jan 3, 2010
Messages
480
Reaction score
16
Hello, I want to make a condition to absorb damage -- and absorb less damage, but I don't know where all I should be looking.

I'm thinking I should edit this to check if the condition is true, and if so then add it to the absorbPercent, which would be simple, and I know I have to add it in condition.cpp,
player.cpp:
HTML:
BlockType_t Player::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage,
                            bool checkDefense /* = false*/, bool checkArmor /* = false*/, bool field /* = false*/)
{
    BlockType_t blockType = Creature::blockHit(attacker, combatType, damage, checkDefense, checkArmor, field);

    if (attacker) {
        sendCreatureSquare(attacker, SQ_COLOR_BLACK);
    }

    if (blockType != BLOCK_NONE) {
        return blockType;
    }

    if (damage > 0) {
        for (int32_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; ++slot) {
            if (!isItemAbilityEnabled(static_cast<slots_t>(slot))) {
                continue;
            }

            Item* item = inventory[slot];
            if (!item) {
                continue;
            }

            const ItemType& it = Item::items[item->getID()];
            if (it.abilities) {
                const int16_t& absorbPercent = it.abilities->absorbPercent[combatTypeToIndex(combatType)];
                if (absorbPercent != 0) {
                    damage -= std::ceil(damage * (absorbPercent / 100.));

                    uint16_t charges = item->getCharges();
                    if (charges != 0) {
                        g_game.transformItem(item, item->getID(), charges - 1);
                    }
                }

                if (field) {
                    const int16_t& fieldAbsorbPercent = it.abilities->fieldAbsorbPercent[combatTypeToIndex(combatType)];
                    if (fieldAbsorbPercent != 0) {
                        damage -= std::ceil(damage * (fieldAbsorbPercent / 100.));

                        uint16_t charges = item->getCharges();
                        if (charges != 0) {
                            g_game.transformItem(item, item->getID(), charges - 1);
                        }
                    }
                }
            }
        }

        if (damage <= 0) {
            damage = 0;
            blockType = BLOCK_ARMOR;
        }
    }
    return blockType;
}

So far I've come up with this but I don't know how to get the param for the percent:
HTML:
            Condition* condition = getCondition(CONDITION_ABSORBPERCENT, CONDITIONID_DEFAULT);
            if (condition) {
                absorbPercent +=
 
Last edited:
Hello, I want to make a condition to absorb damage -- and absorb less damage,

Can you explain, what exactly you want to do? A condition that makes player wearing an item with absorb percent weaker? (The absorb thing from item works worse, so players receives more dmg yes?)

there's if stament for every item containg any 'absorb dmg' value
Code:
                if (absorbPercent != 0) {
                    damage -= std::round(damage * (absorbPercent / 100.)); // dmg reduced by % from item

                    uint16_t charges = item->getCharges(); // charges of item decreased by 1 (if exist)
                    if (charges != 0) {
                        g_game.transformItem(item, item->getID(), charges - 1);
                    }
                }
 
Close, but no, basically it'll just stack, so if they have 30% protection from armor then get the condition for an additional 20% then they'll get 50% protection, or if they get -20% then they'll have 10% protection. So, my idea was to add something like:
HTML:
           Condition* condition = getCondition(CONDITION_ABSORBPERCENT, CONDITIONID_DEFAULT);
            if (condition) {
                absorbPercent +=
after:
HTML:
    if (damage > 0) {
But I don't know how to reference the amount, like if I use the condition in a spell, how do I make it return the amount to absorb that I put in the Lua spell file.
 
Back
Top