• 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++ move the monster back to own spawn position

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
Hello, I'm trying make the monsters walk back to the spawn positiion when the target list is empty
I'm using the function from @Marcelo Druida
Code:
https://otland.net/threads/creature-moveto-position.237960/
AS BASE to try move the monsters
then in monster.cpp
void onThink()
Code:
           } else if (targetList.empty() && randomSteping) {
                std::cout << "TEST" << std::endl;
                FindPathParams fpp;
                fpp.minTargetDist = masterPos.x;
                fpp.maxTargetDist = masterPos.y;
                fpp.fullPathSearch = true;
                fpp.clearSight = true;
                fpp.maxSearchDist = 150;

                std::forward_list<Direction> dirList;
                if (getPathTo(masterPos, dirList, fpp)) {
                    hasFollowPath = true;
                    startAutoWalk(dirList);
                    std::cout << "TEST 2" << std::endl;
                }
            }
the try print TEST works but the TEST 2 don't
 
Last edited:
Truly this

  1. fpp.minTargetDist = 0;
  2. fpp.maxTargetDist = masterPos.y;
nothing I guess...
Code:
} else if (targetList.empty() && randomSteping) {
                std::cout << "TEST" << std::endl;
                FindPathParams fpp;
                fpp.minTargetDist = 0;
                fpp.maxTargetDist = masterPos.y;
                fpp.fullPathSearch = true;
                fpp.allowDiagonal = true;
                fpp.maxSearchDist = 150;

                std::forward_list<Direction> dirList;
                if (this->getPathTo(masterPos, dirList, fpp)) {
                    hasFollowPath = true;
                    startAutoWalk(dirList);
                    std::cout << "TEST 2" << std::endl;
                }
            }
it print
TEST
TESTE 2
 
nothing I guess...
Code:
} else if (targetList.empty() && randomSteping) {
                std::cout << "TEST" << std::endl;
                FindPathParams fpp;
                fpp.minTargetDist = 0;
                fpp.maxTargetDist = masterPos.y;
                fpp.fullPathSearch = true;
                fpp.allowDiagonal = true;
                fpp.maxSearchDist = 150;

                std::forward_list<Direction> dirList;
                if (this->getPathTo(masterPos, dirList, fpp)) {
                    hasFollowPath = true;
                    startAutoWalk(dirList);
                    std::cout << "TEST 2" << std::endl;
                }
            }
it print
TEST
TESTE 2
If it printed both those text (TEST/TEST 2) that means both blocks executed.
 
By default this will only move 10~ squares max. If you want to move farther increase

static constexpr int32_t MAX_NODES = 512;

10000 will go 120 squares at most (straight there). Don't use moveTo for anything 50 steps or father otherwise your server will likely stutter.
cus of that
 
@StreamSide not yet, tested now with:
Code:
} else if (targetList.empty() && randomSteping) {
                FindPathParams fpp;
                fpp.minTargetDist = 0;
                fpp.maxTargetDist = masterPos.y;
                fpp.fullPathSearch = true;
                fpp.allowDiagonal = true;
                fpp.maxSearchDist = 50;
                randomSteping = false;

                std::forward_list<Direction> dirList;
                if (this->getPathTo(masterPos, dirList, fpp)) {
                    hasFollowPath = true;
                    startAutoWalk(dirList);
                    std::cout << "TEST 2" << std::endl;
                }
            }
it print the TEST 2...
but the monster still random steping
 
somewhere I read that when monster is randomsteping onthink is not executed so why dont you test with onattackedcreaturedissapear?
 
somewhere I read that when monster is randomsteping onthink is not executed so why dont you test with onattackedcreaturedissapear?
I test it in this function
Code:
void Monster::onCreatureLeave(Creature* creature)
{
    // std::cout << "onCreatureLeave - " << creature->getName() << std::endl;

    if (getMaster() == creature) {
        //Turn the monster off until its master comes back
        isMasterInRange = false;
    }

    //update friendList
    if (isFriend(creature)) {
        removeFriend(creature);
    }

    //update targetList
    if (isOpponent(creature)) {
        removeTarget(creature);
        if (targetList.empty()) {
            FindPathParams fpp;
            fpp.minTargetDist = 0;
            fpp.maxTargetDist = masterPos.y;
            fpp.fullPathSearch = true;
            fpp.allowDiagonal = true;
            fpp.maxSearchDist = 50;
            randomSteping = false;

            std::forward_list<Direction> dirList;
            if (this->getPathTo(masterPos, dirList, fpp)) {
                hasFollowPath = true;
                startAutoWalk(dirList);
                std::cout << "TEST 2" << std::endl;
            }
            updateIdleStatus();
        }
    }
}
it print TEST 2, but the monster still random steping if the player is in a different floor, but with the monster on the screen...
and the monster stay idle when the player leave your "vision" area
 
Back
Top