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

Follow.

Il Knight

Veteran OT User
Joined
Dec 1, 2014
Messages
676
Solutions
7
Reaction score
350
Location
Spain
Hi, today im triying to do this =

Monster Follow Master if target = NULL <

I remove this from Monster.cpp

if target ==(nullptr) then

monster:setFollowCreature(master)

Now if you summon something, never follow you.

because have 2 seconds of exhausted, so if the "master" stop, and walk, the Monster get idle 2 seconds

so i made this =

Code:
function onThink(cid, interval)
local monster = Monster(cid)
local master = monster:getMaster()
local target = master:getTarget()

function pokemon ()
monster:setFollowCreature(master)
end

if last_interval == nil then
      last_interval = os.clock()
    end
    if (os.clock() - last_interval) > 0 then


if target ==(nullptr) then

monster:setFollowCreature(master)
addEvent(pokemon,250)
addEvent(pokemon,500)
addEvent(pokemon,750)
return true
end

last_interval= os.clock()

end
    return true
end

each 250 Ms the script check if the Master have a target and follow the Master if not, but now still the problem if the master STOP, the Monster get idle for 2 seconds again :S

i already try to use this =
addEvent(pokemon,100)
addEvent(pokemon,100)
addEvent(pokemon,100)
addEvent(pokemon,100)
addEvent(pokemon,100)
addEvent(pokemon,100)
addEvent(pokemon,100)
addEvent(pokemon,100)
addEvent(pokemon,100)
addEvent(pokemon,100)

to make it FASTER 10x seconds, but still the problem, if you stop, your summon stop for 2 seconds S:

i need to ALWAYS FOLLOW the master if target = Null.
Like when a player follow other player.

some help?
 
I'm not sure, but maybe the problem is in this line:
Code:
if target ==(nullptr) then
I guess it should be nil instead of (nullptr)
 
Nullptr Its Nil when you no have Target selected.

All work good, but the Monster(summon) get idle for 1-2 seconds when the Master/Owner stop and walk.
i need to do =monster follow master/owner like when a player follow other player.

Tfs 1.2 Monster .cpp, onThink ( when the Summon follow you/target.

Code:
void Monster::onThink(uint32_t interval)
{
    Creature::onThink(interval);

    if (mType->thinkEvent != -1) {
        // onThink(self, interval)
        LuaScriptInterface* scriptInterface = mType->scriptInterface;
        if (!scriptInterface->reserveScriptEnv()) {
            std::cout << "[Error - Monster::onThink] Call stack overflow" << std::endl;
            return;
        }

        ScriptEnvironment* env = scriptInterface->getScriptEnv();
        env->setScriptId(mType->thinkEvent, scriptInterface);

        lua_State* L = scriptInterface->getLuaState();
        scriptInterface->pushFunction(mType->thinkEvent);

        LuaScriptInterface::pushUserdata<Monster>(L, this);
        LuaScriptInterface::setMetatable(L, -1, "Monster");

        lua_pushnumber(L, interval);

        if (scriptInterface->callFunction(2)) {
            return;
        }
    }

    if (!isInSpawnRange(position)) {
        g_game.internalTeleport(this, masterPos);
        setIdle(true);
    } else {
        updateIdleStatus();

        if (!isIdle) {
            addEventWalk();

            if (isSummon()) {
                if (!attackedCreature) {
                    if (getMaster() && getMaster()->getAttackedCreature()) {
                        //This happens if the monster is summoned during combat
                        selectTarget(getMaster()->getAttackedCreature());
                    } else if (getMaster() != followCreature) {
                        //Our master has not ordered us to attack anything, lets follow him around instead.
                        setFollowCreature(nullptr);
                    }
                } else if (attackedCreature == this) {
                    setFollowCreature(nullptr);
                } else if (followCreature != attackedCreature) {
                    //This happens just after a master orders an attack, so lets follow it aswell.
                    setFollowCreature(attackedCreature);
                }
            } else if (!targetList.empty()) {
                if (!followCreature || !hasFollowPath) {
                    searchTarget();
                } else if (isFleeing()) {
                    if (attackedCreature && !canUseAttack(getPosition(), attackedCreature)) {
                        searchTarget(TARGETSEARCH_ATTACKRANGE);
                    }
                }
            }

            onThinkTarget(interval);
            onThinkYell(interval);
            onThinkDefense(interval);
        }
    }
}

on this part i change the follow master/ per Nullptr.

Now when you summon something, no follow you never.

Code:
//Our master has not ordered us to attack anything, lets follow him around instead.
                        setFollowCreature(nullptr);

then, i make this script,
each 250 MS, check if have target or not, and follow the Master.

Code:
function onThink(cid, interval)
local monster = Monster(cid)
local master = monster:getMaster()
local target = master:getTarget()

function pokemon ()
monster:setFollowCreature(master)
end

if last_interval == nil then
      last_interval = os.clock()
    end
    if (os.clock() - last_interval) > 0 then


if target ==(nullptr) then

monster:setFollowCreature(master)
addEvent(pokemon,250)
addEvent(pokemon,500)
addEvent(pokemon,750)
return true
end

last_interval= os.clock()

end
    return true
end

But still giving me 2 seconds of exhausted (Idle)
then you can use utani gran hur, and run like a crazy and let your summon very fast for that "2" seconds of idle.

and its not the speed, because the summon have the same speed of the Master/owner,
when you summon something =

monster:changeSpeed(p:getBaseSpeed())

and mi utani gran hur.

monster:changeSpeed(p:getBaseSpeed())
 
Last edited by a moderator:
I don't think this is the problem, but maybe there's some interval of time between each onThink :eek:
 
each interval on the script its 250 ms.

addEvent(pokemon,250)
addEvent(pokemon,500)
addEvent(pokemon,750)

i already test its with
send text to player,
and yes, each 250 MS i get the "text" only when the master/owner no get "target" selected
 
do this:
when a creature moves, check if it have a summon, if it does, make the summon walk

creature.cpp
Code:
void Creature::goToFollowCreature()
{
    if (followCreature) {
        FindPathParams fpp;
        getPathSearchParams(followCreature, fpp);

        Monster* monster = getMonster();
        if (monster && !monster->getMaster() && (monster->isFleeing() || fpp.maxTargetDist > 1)) {
            Direction dir = DIRECTION_NONE;

            if (monster->isFleeing()) {
                monster->getDistanceStep(followCreature->getPosition(), dir, true);
            } else { //maxTargetDist > 1
                if (!monster->getDistanceStep(followCreature->getPosition(), dir)) {
                    // if we can't get anything then let the A* calculate
                    listWalkDir.clear();
                    if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) {
                        hasFollowPath = true;
                        startAutoWalk(listWalkDir);
                    } else {
                        hasFollowPath = false;
                    }
                    return;
                }
            }

            if (dir != DIRECTION_NONE) {
                listWalkDir.clear();
                listWalkDir.push_front(dir);

                hasFollowPath = true;
                startAutoWalk(listWalkDir);
            }
        } else {
            listWalkDir.clear();
            if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) {
                hasFollowPath = true;
                startAutoWalk(listWalkDir);
            } else {
                hasFollowPath = false;
            }
        }
    }

    onFollowCreatureComplete(followCreature);
}

bool Creature::setFollowCreature(Creature* creature)
{
    if (creature) {
        if (followCreature == creature) {
            return true;
        }

        const Position& creaturePos = creature->getPosition();
        if (creaturePos.z != getPosition().z || !canSee(creaturePos)) {
            followCreature = nullptr;
            return false;
        }

        if (!listWalkDir.empty()) {
            listWalkDir.clear();
            onWalkAborted();
        }

        hasFollowPath = false;
        forceUpdateFollowPath = false;
        followCreature = creature;
        isUpdatingPath = true;
    } else {
        isUpdatingPath = false;
        followCreature = nullptr;
    }

    onFollowCreature(creature);
    return true;
}

AND PLAYER.CPP
Code:
bool Player::setFollowCreature(Creature* creature)
{
    if (!Creature::setFollowCreature(creature)) {
        setFollowCreature(nullptr);
        setAttackedCreature(nullptr);

        sendCancelMessage(RETURNVALUE_THEREISNOWAY);
        sendCancelTarget();
        stopWalk();
        return false;
    }
    return true;
}

Code:
void Player::goToFollowCreature()
{
    if (!walkTask) {
        if ((OTSYS_TIME() - lastFailedFollow) < 2000) {
            return;
        }

        Creature::goToFollowCreature();

        if (followCreature && !hasFollowPath) {
            lastFailedFollow = OTSYS_TIME();
        }
    }
}

look the diference how i can change this? to work like a player follow player
 
i've got a idea

find this:
Code:
                    } else if (getMaster() != followCreature) {
                        //Our master has not ordered us to attack anything, lets follow him around instead.
                        setFollowCreature(getMaster());
                    }

change to this:
Code:
                    } else if (getMaster() != followCreature) {
                        //Our master has not ordered us to attack anything, lets follow him around instead.
                        setFollowCreature(getMaster());
goToFollowCreature();
                    }
 
Not working :(
because the GoToFollowCreature of the "creatures" Monsters its =
if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) {
hasFollowPath = true;
startAutoWalk(listWalkDir);

its a WALK event < slow because need to followCreature->getPosition(), listWalkDir, fpp)

:(
 
eu preciso que meu POKEMON de follow en min como si fora um player rapido--- ja coloquei distancia em 1 sqm, mais e muito lento, cuando eu vo pra otro lado, ele fica parado 1-2 secs
 
sim eu entendi,
não entendi o que disse:

Not working :(
because the GoToFollowCreature of the "creatures" Monsters its =
if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) {
hasFollowPath = true;
startAutoWalk(listWalkDir);

its a WALK event < slow because need to followCreature->getPosition(), listWalkDir, fpp)

:(
 
by the way

this is the original TFS code
Code:
                    } else if (getMaster() != followCreature) {
                        //Our master has not ordered us to attack anything, lets follow him around instead.
                        setFollowCreature(getMaster());
                    }

this is your code
Code:
                    } else if (getMaster() != followCreature) {
                        //Our master has not ordered us to attack anything, lets follow him around instead.
                        setFollowCreature(nullptr);
}

please check if am I right that your summon were coded to follow nobody
 
startAutoWalk(listWalkDir);
ai esta "caminando" pra position do player, nao esta dando follow como si fora otro player
 
yes, because i move that to LUA

Code:
function onThink(cid, interval)
local monster = Monster(cid)
local master = monster:getMaster()
local target = master:getTarget()

function pokemon ()
monster:setFollowCreature(master)
end

if last_interval == nil then
      last_interval = os.clock()
    end
    if (os.clock() - last_interval) > 0 then


if target ==(nullptr) then

monster:setFollowCreature(master)
addEvent(pokemon,250)
addEvent(pokemon,500)
addEvent(pokemon,750)
return true
end

last_interval= os.clock()

end
    return true
end
 
here its the problem ..
Code:
void Creature::goToFollowCreature()
{
    if (followCreature) {
        FindPathParams fpp;
        getPathSearchParams(followCreature, fpp);

        Monster* monster = getMonster();
        if (monster && !monster->getMaster() && (monster->isFleeing() || fpp.maxTargetDist > 1)) {
            Direction dir = DIRECTION_NONE;

            if (monster->isFleeing()) {
                monster->getDistanceStep(followCreature->getPosition(), dir, true);
            } else { //maxTargetDist > 1
                if (!monster->getDistanceStep(followCreature->getPosition(), dir)) {
                    // if we can't get anything then let the A* calculate
                    listWalkDir.clear();
                    if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) {
                        hasFollowPath = true;
                        startAutoWalk(listWalkDir);
                    } else {
                        hasFollowPath = false;
                    }
                    return;
                }
            }

            if (dir != DIRECTION_NONE) {
                listWalkDir.clear();
                listWalkDir.push_front(dir);

                hasFollowPath = true;
                startAutoWalk(listWalkDir);
            }
        } else {
            listWalkDir.clear();
            if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) {
                hasFollowPath = true;
                startAutoWalk(listWalkDir);
            } else {
                hasFollowPath = false;
            }
        }
    }

    onFollowCreatureComplete(followCreature);
}

when summon follow you "the summon go to your position, its not really following you like when a player follow other player (real follow)
 
here its the problem ..
Code:
void Creature::goToFollowCreature()
{
    if (followCreature) {
        FindPathParams fpp;
        getPathSearchParams(followCreature, fpp);

        Monster* monster = getMonster();
        if (monster && !monster->getMaster() && (monster->isFleeing() || fpp.maxTargetDist > 1)) {
            Direction dir = DIRECTION_NONE;

            if (monster->isFleeing()) {
                monster->getDistanceStep(followCreature->getPosition(), dir, true);
            } else { //maxTargetDist > 1
                if (!monster->getDistanceStep(followCreature->getPosition(), dir)) {
                    // if we can't get anything then let the A* calculate
                    listWalkDir.clear();
                    if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) {
                        hasFollowPath = true;
                        startAutoWalk(listWalkDir);
                    } else {
                        hasFollowPath = false;
                    }
                    return;
                }
            }

            if (dir != DIRECTION_NONE) {
                listWalkDir.clear();
                listWalkDir.push_front(dir);

                hasFollowPath = true;
                startAutoWalk(listWalkDir);
            }
        } else {
            listWalkDir.clear();
            if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) {
                hasFollowPath = true;
                startAutoWalk(listWalkDir);
            } else {
                hasFollowPath = false;
            }
        }
    }

    onFollowCreatureComplete(followCreature);
}

when summon follow you "the summon go to your position, its not really following you like when a player follow other player (real follow)

man... please...
this is the same code in both cases
put a std::cout in it to prove
 
ok did you tested mine code?

please be sure that you are not following the nullptr
AND disable that script

i've got a idea

find this:
Code:
                    } else if (getMaster() != followCreature) {
                        //Our master has not ordered us to attack anything, lets follow him around instead.
                        setFollowCreature(getMaster());
                    }

change to this:
Code:
                    } else if (getMaster() != followCreature) {
                        //Our master has not ordered us to attack anything, lets follow him around instead.
                        setFollowCreature(getMaster());
goToFollowCreature();
                    }
 
Back
Top