• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

C++ Only get infight if take damage from monsters. Help.

Bera

New Member
Joined
Jan 15, 2013
Messages
8
Reaction score
0
Guys I need help with monster adding infight just for targetting players. I'm making a server with a wide range of view and players get infight all the time because of that.

I don't want to reduce monster cansee so that they just don't stand there frozem. So I think one solution is to remove infight just to get targeted by a monster and then get infight if got hit/damaged. I'm looking in the sources but can't figure out how to do that (TFS 1.3).

Maybe reduce the range that monsters target too, but I don't know if that would froze them in the distance too.

Here is where I think needs change in players.cpp:


C++:
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();
    }
}

Any suggestion?
 
In map.h you have something like:
C++:
static const int32_t maxViewportX = 11; //min value: maxClientViewportX + 1
static const int32_t maxViewportY = 11; //min value: maxClientViewportY + 1
Which are used to determine if creatures try to "see" enemies and move among other things.

In creature.cpp you have things like:
C++:
bool Creature::canSee(const Position& pos) const
{
    return canSee(getPosition(), pos, Map::maxViewportX, Map::maxViewportY);
}
By changing those values you can solve your problem with view-range of monsters. This should give you what you want.

But... If someone could share this feature, like: Player get PZ only when getting damage from monsters/other players that would be great because I'm looking for that feature too.
So, BUMP!
 
Back
Top