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

TFS 1.X+ Monsters Behavior

endziu2222

Well-Known Member
Joined
Nov 2, 2010
Messages
234
Solutions
1
Reaction score
63
Does anybody know how to change monster behavior so it moves around when player is not on the screen??

Latest TFS.
 
Solution
When I edit this or increase distance server start to lag.
Of course it will lag. That's why monsters go 'idle', when there are no players within some range. What does it change for players, if monsters move, when they are not on screen? Nothing. Default distance is 11 sqm, 3-4 sqm more than range visible in client, so monsters move, even when players can't see them in client.

With 500 players online you got around 1-2k monsters 'active'. Rest of monsters - often 50-150k - is idle. If you make all monsters active, you will increase number of creatures 'to process' by server each second 50-100 TIMES.

Anyway, if you want to disable idle state:
1. Change ( forgottenserver/src/monster.cpp at master ·...
Anyone know how can I increase Creatures detection range?
So player can be detected not from basic 12 to more distance?
 
I believe it's a terrible idea to make monsters walks when the player is off-screen due to unnecessary resource consumption. Just imagine the strain on resources with thousands of monsters in motion when no one is on screen
 
When I edit this or increase distance server start to lag.
Of course it will lag. That's why monsters go 'idle', when there are no players within some range. What does it change for players, if monsters move, when they are not on screen? Nothing. Default distance is 11 sqm, 3-4 sqm more than range visible in client, so monsters move, even when players can't see them in client.

With 500 players online you got around 1-2k monsters 'active'. Rest of monsters - often 50-150k - is idle. If you make all monsters active, you will increase number of creatures 'to process' by server each second 50-100 TIMES.

Anyway, if you want to disable idle state:
1. Change ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L189) ):
C++:
setIdle(true);
to:
C++:
setIdle(false);

2. Change ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L751) )
C++:
setIdle(true);
to:
C++:
setIdle(false);
3. Replace ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L679-L689) )
C++:
void Monster::updateIdleStatus()
{
    bool idle = false;
    if (!isSummon() && targetList.empty()) {
        // check if there are aggressive conditions
        idle = std::find_if(conditions.begin(), conditions.end(),
                            [](Condition* condition) { return condition->isAggressive(); }) == conditions.end();
    }

    setIdle(idle);
}
with:
C++:
void Monster::updateIdleStatus()
{
    setIdle(false);
}
 
Solution
What does it change for players, if monsters move, when they are not on screen? Nothing.
That's true. The only thing I can think of is monsters position being more random when you get to their spawn. Instead of expected mob at the same position every time respawn happens, it would be moving around so next time you encounter it, it might end up somewhere else. Its more RPG feeling/immersion thing than actual usefulness of the feature.
But if that's what OP is aiming for, then he might as well give random path to mobs once they spawn and make them move.
 
That's true. The only thing I can think of is monsters position being more random when you get to their spawn. Instead of expected mob at the same position every time respawn happens, it would be moving around so next time you encounter it, it might end up somewhere else. Its more RPG feeling/immersion thing than actual usefulness of the feature.
But if that's what OP is aiming for, then he might as well give random path to mobs once they spawn and make them move.

Might there be some overhead with having thousands of monsters just moving around randomly when absolutely no one is around?

I could understand wanting them to still move around if a player changes floor, like how they changed it from 7.4-ish to 7.7, but tens of thousands of randomly wandering 100% of the time seems excessive... Idk if that really makes much difference though
 
That's true. The only thing I can think of is monsters position being more random when you get to their spawn. Instead of expected mob at the same position every time respawn happens, it would be moving around so next time you encounter it, it might end up somewhere else. Its more RPG feeling/immersion thing than actual usefulness of the feature.
But if that's what OP is aiming for, then he might as well give random path to mobs once they spawn and make them move.
I will test what gesior advised and see how it affects the server. Currently I have over 50k monsters on my ots. I did heard you can give monsters a path they have to follow but I have not seen any example on how to do it.

@Gesior.pl thanks.
Post automatically merged:

Of course it will lag. That's why monsters go 'idle', when there are no players within some range. What does it change for players, if monsters move, when they are not on screen? Nothing. Default distance is 11 sqm, 3-4 sqm more than range visible in client, so monsters move, even when players can't see them in client.

With 500 players online you got around 1-2k monsters 'active'. Rest of monsters - often 50-150k - is idle. If you make all monsters active, you will increase number of creatures 'to process' by server each second 50-100 TIMES.

Anyway, if you want to disable idle state:
1. Change ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L189) ):
C++:
setIdle(true);
to:
C++:
setIdle(false);

2. Change ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L751) )
C++:
setIdle(true);
to:
C++:
setIdle(false);
3. Replace ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L679-L689) )
C++:
void Monster::updateIdleStatus()
{
    bool idle = false;
    if (!isSummon() && targetList.empty()) {
        // check if there are aggressive conditions
        idle = std::find_if(conditions.begin(), conditions.end(),
                            [](Condition* condition) { return condition->isAggressive(); }) == conditions.end();
    }

    setIdle(idle);
}
with:
C++:
void Monster::updateIdleStatus()
{
    setIdle(false);
}
I have tested now. You was right lags became HUGE after this. So yeah is not worth it.
 
Last edited:
Of course it will lag. That's why monsters go 'idle', when there are no players within some range. What does it change for players, if monsters move, when they are not on screen? Nothing. Default distance is 11 sqm, 3-4 sqm more than range visible in client, so monsters move, even when players can't see them in client.

With 500 players online you got around 1-2k monsters 'active'. Rest of monsters - often 50-150k - is idle. If you make all monsters active, you will increase number of creatures 'to process' by server each second 50-100 TIMES.

Anyway, if you want to disable idle state:
1. Change ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L189) ):
C++:
setIdle(true);
to:
C++:
setIdle(false);

2. Change ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L751) )
C++:
setIdle(true);
to:
C++:
setIdle(false);
3. Replace ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L679-L689) )
C++:
void Monster::updateIdleStatus()
{
    bool idle = false;
    if (!isSummon() && targetList.empty()) {
        // check if there are aggressive conditions
        idle = std::find_if(conditions.begin(), conditions.end(),
                            [](Condition* condition) { return condition->isAggressive(); }) == conditions.end();
    }

    setIdle(idle);
}
with:
C++:
void Monster::updateIdleStatus()
{
    setIdle(false);
}
Hi Sir! you know if this system are in the TFS 0.4?

i want do that monters dont move is not player on screen range or same floor
i looking around monster.cpp but can't find the Default range that you say bro
 
i want do that monters dont move is not player on screen range or same floor
I think all OTSes made in last 20 years have system to make monsters go 'idle', when there is no player 'on screen'.

Only change in that system was made on some version of Tibia 7.x, as it was changed on RL Tibia.
Before (ex. Tibia 7.1) monsters stopped walking, when there was no player on same floor, but if you were hunting solo and ex. went +1 floor by stairs, monsters on lower floor stopped walking. It was a problem for people trying to go up/down by stairs and ex. use SD rune on monster.
After change, monsters stay active, when there is player on screen on any floor, so you could jump up/down by stairs and if monster finally went next to stairs, you could just wait on other floor and monster would walk away by making random steps (it does 'random steps', when it has no target, but is 'not idle').

i looking around monster.cpp but can't find the Default range that you say bro
Inactive monsters do not 'scan' for 'players in range' every second. It would use too much CPU. OTSes already have functions that notify all players/monsters in range, every time some other player/monster make step. There are 3 important events:

onCreatureMove is send here:
but you should not modify it there, as there are many other systems of Player/NPC that are based on it.
'range' is definied in getSpectators function, but you should not modify it too, as half of OTS logic is based on that range.

If you want to make monsters go 'idle', when there is no player on same floor, you should modify logic in monster.cpp functions that call onCreatureFound and onCreatureLeave. These are functions that update targetList and it makes monsters go idle (when list is empty).
Someone asked me to make that change few weeks ago on TFS 1.4. I made it with AI and it had only 2 logic bugs that I had to fix manually.

EDIT:
I made these changes to TFS 0.4 r3884 with Cursor Composer-2.5-fast AI for 0.24$. It's most popular TFS 0.4 for 8.6 after 'r3777'. Changed files:
 
Last edited:
Back
Top