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
I added this inside the canWalkTo function
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
To
but the problem (crash server) still persists, can someone help me how can i solve this?
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?