• 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++ Help me with crash server tfs 1.2

jackl90

Member
Joined
Jul 25, 2017
Messages
249
Reaction score
12
I'm trying to set a 10 sqm limit of player (target) for the monster not to walk outside this limit when using the getRandomStep function

one way i managed to make it work is this way

C++:
bool Monster::canWalkTo(Position pos, Direction direction) const
{
    const Position targetPos = followCreature->getPosition();

    pos = getNextPosition(direction, pos);
    if (Position::getDistanceX(pos, targetPos) > 10 || Position::getDistanceY(pos, targetPos) > 10) {
        return false;
    }

    if (isInSpawnRange(pos)) {
        if (getWalkCache(pos) == 0) {
            return false;
        }
        Tile* tile = g_game.map.getTile(pos);
        if (tile && tile->getTopVisibleCreature(this) == nullptr && tile->queryAdd(0, *this, 1, FLAG_PATHFINDING) == RETURNVALUE_NOERROR) {
            return true;
        }
    }
    return false;
}

I added this inside the canWalkTo function

C++:
  const Position targetPos = followCreature->getPosition();
    if (Position::getDistanceX(pos, targetPos) > 10 || Position::getDistanceY(pos, targetPos) > 10) {
        return false;
    }

well everything works as I exactly wanted, but I found a problem, the server is crashing when a monster is attacking the player and he enters the protection zone...

i tried change the
C++:
 const Position targetPos = followCreature->getPosition();

To

C++:
 const Position targetPos = attackedCreature->getPosition();

but the problem (crash server) still persists, can someone help me how can i solve this?
 
Solution
I'm trying to set a 10 sqm limit of player (target) for the monster not to walk outside this limit when using the getRandomStep function

one way i managed to make it work is this way

C++:
bool Monster::canWalkTo(Position pos, Direction direction) const
{
    const Position targetPos = followCreature->getPosition();

    pos = getNextPosition(direction, pos);
    if (Position::getDistanceX(pos, targetPos) > 10 || Position::getDistanceY(pos, targetPos) > 10) {
        return false;
    }

    if (isInSpawnRange(pos)) {
        if (getWalkCache(pos) == 0) {
            return false;
        }
        Tile* tile = g_game.map.getTile(pos);
        if (tile && tile->getTopVisibleCreature(this) == nullptr && tile->queryAdd(0, *this, 1...
I'm trying to set a 10 sqm limit of player (target) for the monster not to walk outside this limit when using the getRandomStep function

one way i managed to make it work is this way

C++:
bool Monster::canWalkTo(Position pos, Direction direction) const
{
    const Position targetPos = followCreature->getPosition();

    pos = getNextPosition(direction, pos);
    if (Position::getDistanceX(pos, targetPos) > 10 || Position::getDistanceY(pos, targetPos) > 10) {
        return false;
    }

    if (isInSpawnRange(pos)) {
        if (getWalkCache(pos) == 0) {
            return false;
        }
        Tile* tile = g_game.map.getTile(pos);
        if (tile && tile->getTopVisibleCreature(this) == nullptr && tile->queryAdd(0, *this, 1, FLAG_PATHFINDING) == RETURNVALUE_NOERROR) {
            return true;
        }
    }
    return false;
}

I added this inside the canWalkTo function

C++:
  const Position targetPos = followCreature->getPosition();
    if (Position::getDistanceX(pos, targetPos) > 10 || Position::getDistanceY(pos, targetPos) > 10) {
        return false;
    }

well everything works as I exactly wanted, but I found a problem, the server is crashing when a monster is attacking the player and he enters the protection zone...

i tried change the
C++:
 const Position targetPos = followCreature->getPosition();

To

C++:
 const Position targetPos = attackedCreature->getPosition();

but the problem (crash server) still persists, can someone help me how can i solve this?

C++:
bool Monster::canWalkTo(Position pos, Direction direction) const
{
    pos = getNextPosition(direction, pos);

    if (attackedCreature) {
        const Position targetPos = attackedCreature->getPosition();
        if (Position::getDistanceX(pos, targetPos) > 10 || Position::getDistanceY(pos, targetPos) > 10) {
            return false;
        }
    }

    if (isInSpawnRange(pos)) {
        if (getWalkCache(pos) == 0) {
            return false;
        }

        Tile* tile = g_game.map.getTile(pos);
        if (tile && tile->getTopVisibleCreature(this) == nullptr && tile->queryAdd(0, *this, 1, FLAG_PATHFINDING) == RETURNVALUE_NOERROR) {
            return true;
        }
    }
    return false;
}
 
Solution
Back
Top