• 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++ Take Condition Infight only when you take damage.

donabimbo

Member
Joined
May 1, 2023
Messages
27
Reaction score
9
GitHub
donabimbo
TFS: 1.X

Greetings otland, I was looking for how to modify the Infight condition, only receive the condition if a monster attacks you (1SQM).

As you know, when a monster just sees you from afar, the player receives the Infight condition.

I started looking in the sources about that and found this:

Player:ccp

Lua:
void Player::onAttackedCreature(Creature* target, bool addFightTicks /* = true */)
{
    Creature::onAttackedCreature(target);

    if (target->getZone() == ZONE_PVP) {
        return;
    }

    if (target == this) {
        if (addFightTicks) {
            addInFightTicks();
        }
        return;
    }

    if (hasFlag(PlayerFlag_NotGainInFight)) {
        return;
    }

    Player* targetPlayer = target->getPlayer();
    if (targetPlayer && !isPartner(targetPlayer) && !isGuildMate(targetPlayer)) {
        if (!pzLocked && g_game.getWorldType() == WORLD_TYPE_PVP_ENFORCED) {
            pzLocked = true;
            sendIcons();
        }

        targetPlayer->addInFightTicks();

        if (getSkull() == SKULL_NONE && getSkullClient(targetPlayer) == SKULL_YELLOW) {
            addAttacked(targetPlayer);
            targetPlayer->sendCreatureSkull(this);
        }
        else if (!targetPlayer->hasAttacked(this)) {
            if (!pzLocked) {
                pzLocked = true;
                sendIcons();
            }

            if (!Combat::isInPvpZone(this, targetPlayer) && !isInWar(targetPlayer)) {
                addAttacked(targetPlayer);

                if (targetPlayer->getSkull() == SKULL_NONE && getSkull() == SKULL_NONE) {
                    setSkull(SKULL_WHITE);
                }

                if (getSkull() == SKULL_NONE) {
                    targetPlayer->sendCreatureSkull(this);
                }
            }
        }
    }

    if (addFightTicks) {
        addInFightTicks();
    }
}

I do not know what I have to modify, I would be grateful for any help.
 
TFS: 1.X

Greetings otland, I was looking for how to modify the Infight condition, only receive the condition if a monster attacks you (1SQM).

As you know, when a monster just sees you from afar, the player receives the Infight condition.

I started looking in the sources about that and found this:

Player:ccp

Lua:
void Player::onAttackedCreature(Creature* target, bool addFightTicks /* = true */)
{
    Creature::onAttackedCreature(target);

    if (target->getZone() == ZONE_PVP) {
        return;
    }

    if (target == this) {
        if (addFightTicks) {
            addInFightTicks();
        }
        return;
    }

    if (hasFlag(PlayerFlag_NotGainInFight)) {
        return;
    }

    Player* targetPlayer = target->getPlayer();
    if (targetPlayer && !isPartner(targetPlayer) && !isGuildMate(targetPlayer)) {
        if (!pzLocked && g_game.getWorldType() == WORLD_TYPE_PVP_ENFORCED) {
            pzLocked = true;
            sendIcons();
        }

        targetPlayer->addInFightTicks();

        if (getSkull() == SKULL_NONE && getSkullClient(targetPlayer) == SKULL_YELLOW) {
            addAttacked(targetPlayer);
            targetPlayer->sendCreatureSkull(this);
        }
        else if (!targetPlayer->hasAttacked(this)) {
            if (!pzLocked) {
                pzLocked = true;
                sendIcons();
            }

            if (!Combat::isInPvpZone(this, targetPlayer) && !isInWar(targetPlayer)) {
                addAttacked(targetPlayer);

                if (targetPlayer->getSkull() == SKULL_NONE && getSkull() == SKULL_NONE) {
                    setSkull(SKULL_WHITE);
                }

                if (getSkull() == SKULL_NONE) {
                    targetPlayer->sendCreatureSkull(this);
                }
            }
        }
    }

    if (addFightTicks) {
        addInFightTicks();
    }
}

I do not know what I have to modify, I would be grateful for any help.



on Player.cpp search for:


C++:
void Player::onAttacked()
{
    Creature::onAttacked();
    addInFightTicks();
}

then comment:


C++:
void Player::onAttacked()
{
    Creature::onAttacked();
    //addInFightTicks();
}


and add the condition InFight only when receive damage...


search for:

C++:
void Player::drainHealth(Creature* attacker, int32_t damage)
{
    Creature::drainHealth(attacker, damage);
    sendStats();
}


then add:

C++:
void Player::drainHealth(Creature* attacker, int32_t damage)
{
    Creature::drainHealth(attacker, damage);
    
    // Add Condition InFight only when receive damage
    if (damage > 0) {
        addInFightTicks();
    }
    
    sendStats();
}



I think that in the same way a condition should be added for when you are being attacked but you do not receive damage. But for now that's what you're looking for. Tested on TFS 1.3
 
@NvSo
Thank you very much, in that case when I am attacked by a monster it works perfectly but when it is a player, the condition is placed on it.

If a condition should be placed on him, because if the condition is placed on him when he is attacked by a player, but when he has not received damage for a while, the condition disappears.

I'll take a look at the sources.
Recording 2023-05-09 at 17.32.31.gif
Post automatically merged:

About 5 minutes later I saw this:
in the function: void Player::eek:nAttackedCreature(Creature* target, bool addFightTicks /* = true */)
In this line:

Lua:
Player* targetPlayer = target->getPlayer();
    if (targetPlayer && !isPartner(targetPlayer) && !isGuildMate(targetPlayer)) {
        if (!pzLocked && g_game.getWorldType() == WORLD_TYPE_PVP_ENFORCED) {
            pzLocked = true;
            sendIcons();
        }

        // Not receiving Condition when attacked by player.
        //targetPlayer->addInFightTicks();

        if (getSkull() == SKULL_NONE && getSkullClient(targetPlayer) == SKULL_YELLOW) {
            addAttacked(targetPlayer);
            targetPlayer->sendCreatureSkull(this);
        } else {
I saw the line that say: targetPlayer->addInFightTicks();
By removing that line, now that does not happen.
Recording 2023-05-09 at 17.53.53.gif
I honestly don't know if it's the right thing to do or if there would be another way around it, but for now I'm taking it for granted.
Thanks for the help. @NvSo
 
Last edited:
Back
Top