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

New change target behavior

Peonso

Godly Member
Joined
Jan 14, 2008
Messages
1,787
Solutions
30
Reaction score
1,592
I need help with C++, I want to create a new change target behavior. It should always pick the nearby target, if there are more then one at the same range, it picks randomly. I want it to be able to pick the creature that is already target.
Something like this:
Code:
case TARGETSEARCH_RANGEDMONSTER: {
  std::list<Creature*> resultMinList;
  int32_t minRange = std::numeric_limits<int32_t>::max();
//picks the minimum range
  for (Creature* creature : targetList) { 
    const Position& pos = creature->getPosition();
    int32_t distance = Position::getDistanceX(myPos, pos) + Position::getDistanceY(myPos, pos);
    if (distance < minRange) {
      minRange = distance
  }
//add all creatures in the minimum range to the list
  for (Creature* creature : targetList) { 
    const Position& pos = creature->getPosition();
    int32_t distance = Position::getDistanceX(myPos, pos) + Position::getDistanceY(myPos, pos);
    if (distance = minRange) {
      resultMinList.push_back(creature);
  }
//sets a random creature from the list as target
  if (!resultList.empty()) {
    auto it = resultMinList.begin();
    std::advance(it, uniform_random(0, resultMinList.size() - 1));
    return selectTarget(*it);
  }
}
 
If i understand correctly, you should change this https://github.com/otland/forgotten...2984d4b997f82d10769f205c/src/monster.cpp#L901

to:
Code:
if (mType->changeTargetChance >= uniform_random(1, 100)) {
    searchTarget(TARGETSEARCH_NEAREST);
}

Basicaly now when changing target(based on target chance on monster.xml flags) it will always look for the nearest target.

TARGETSEARCH_NEAREST don't pick the same target if it's the closer one, that what I want to change. So it actually don't change target when the event is triggered, only if the nearest one is actually different.
 
Back
Top