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

Someone can help with c++ tfs 1.2

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
Hello community

In this npc code here
C++:
bool Npc::getNextStep(Direction& dir, uint32_t& flags)
{
    if (Creature::getNextStep(dir, flags)) {
        return true;
    }

    if (baseSpeed <= 0) {
        return false;
    }

    if (focusCreature != 0) {
        return false;
    }

    if (OTSYS_TIME() < staticMovementTime) {
        return false;
    }

    if (getTimeSinceLastMove() < 100 + getStepDuration() + getStepSpeed()) {
        return false;
    }

    return getRandomStep(dir);
}
How can i add a condition check inside this function, to npc check spectators, if have players more than 10 sqm of npc's, return false the function getNextStep, someone can help me?

Thanks in advance
 
Try this way, i'm still learning cpp.

C++:
bool Npc::getNextStep(Direction& dir, uint32_t& flags)
{
    if (Creature::getNextStep(dir, flags)) {
        return true;
    }

    SpectatorVec spectators;
    g_game.map.getSpectators(spectators, this->getPosition(), false, true);

    if (spectators.empty() || !spectator) {
        return false;
    }

    if (baseSpeed <= 0) {
        return false;
    }

    if (focusCreature != 0) {
        return false;
    }

    if (OTSYS_TIME() < staticMovementTime) {
        return false;
    }

    if (getTimeSinceLastMove() < 100 + getStepDuration() + getStepSpeed()) {
        return false;
    }

    return getRandomStep(dir);
}
 
Try this way, i'm still learning cpp.

C++:
bool Npc::getNextStep(Direction& dir, uint32_t& flags)
{
    if (Creature::getNextStep(dir, flags)) {
        return true;
    }

    SpectatorVec spectators;
    g_game.map.getSpectators(spectators, this->getPosition(), false, true);

    if (spectators.empty() || !spectator) {
        return false;
    }

    if (baseSpeed <= 0) {
        return false;
    }

    if (focusCreature != 0) {
        return false;
    }

    if (OTSYS_TIME() < staticMovementTime) {
        return false;
    }

    if (getTimeSinceLastMove() < 100 + getStepDuration() + getStepSpeed()) {
        return false;
    }

    return getRandomStep(dir);
}
not working
 
Last edited:
This should work:

C++:
bool Npc::getNextStep(Direction& dir, uint32_t& flags)
{
    SpectatorVec spectators;
    g_game.map.getSpectators(spectators, this->getPosition(), false, true, 10, 10);

    if (spectators.empty() || !spectator) {
        return false;
    }
    
    if (Creature::getNextStep(dir, flags)) {
        return true;
    }

    if (baseSpeed <= 0) {
        return false;
    }

    if (focusCreature != 0) {
        return false;
    }

    if (OTSYS_TIME() < staticMovementTime) {
        return false;
    }

    if (getTimeSinceLastMove() < 100 + getStepDuration() + getStepSpeed()) {
        return false;
    }

    return getRandomStep(dir);
}

I don't know exactly what you are doing but I am almost sure that change this method is not the best approach...
 
Back
Top