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

Solved Weird monster behaviour in TFS 1.1?

Ahilphino

Excellent OT User
Joined
Jun 5, 2013
Messages
1,667
Solutions
1
Reaction score
726
The monster AI in tfs 1.1 (idk about 1.0) is EXTREMELY dumb. This has discouraged me from using TFS 1.1 even though i've spent so much time with it.

A couple of examples:

If you chase any ranged mob, let's take lizard legionaire, they will turn around every time they make an attack and this causes them to barely run away even if you set their speed to 2000.

If you're getting chased by a fast monster, let's say a grim reaper - he will stop at times. Especially when you're in melee range, then just decide to run away. It will take him like one second to react and start running after you.


There's youtube videos about it a couple of posts below
 
Last edited:
Hello @geisor, man I have noted that when monster are being chased by a player they run, turn around almost every step to look at player a, then begin to run and turn the look again,this occurs every step is there a fix for this?
There are many problems with monsters AI in TFS. I made fixes for Kasteria.pl, but it took me few weeks and it's not compatible with TFS.
Someone made 'TFS real tibia monsters AI' and sells it for 1000$, but I don't remember nick.
 
There are many problems with monsters AI in TFS. I made fixes for Kasteria.pl, but it took me few weeks and it's not compatible with TFS.
Someone made 'TFS real tibia monsters AI' and sells it for 1000$, but I don't remember nick.
I know a guy that is selling it and the whole server for 1.5k s: won't say name :/
Have this Multithread pathfinding · gesior/forgottenserver@48cb292 (https://github.com/gesior/forgottenserver/commit/48cb292d56d36e87ab25e2bc00bcc5c61c4cc842) got to be merge with the previous code posted in this thread?
 
Last edited:
As I posted here:
1 player fighting vs. 15 demons may consume 10% of CPU (Intel i9-9900K). On cheap VPS it would be 20% of CPU consumed just by 1 player.
Here are custom CPU optimized algorithms:
can I do it so for example in config lua there is (and how if its possible):
WhatAlgoToUse: x (x = 0 default, x = 1 algo nr 1, x = 2 algo nr 2 ... ) ?
thx in advance
 
can I do it so for example in config lua there is (and how if its possible):
WhatAlgoToUse: x (x = 0 default, x = 1 algo nr 1, x = 2 algo nr 2 ... ) ?
thx in advance
It's in my code:
C++:
const uint32_t algo = g_config.getNumber(ConfigManager::PZ_LOCKED);
I did it for tests only, so I picked some already existing value from config.lua: pzLocked.
TFS uses it to set pz lock time after attacking players, but I set it to 0/1/2/3/4 to choose algorithm for walking.
If you want to add new key to config.lua, you got to edit configmanager.cpp and configmanager.h.
 
It's in my code:
C++:
const uint32_t algo = g_config.getNumber(ConfigManager::PZ_LOCKED);
I did it for tests only, so I picked some already existing value from config.lua: pzLocked.
TFS uses it to set pz lock time after attacking players, but I set it to 0/1/2/3/4 to choose algorithm for walking.
If you want to add new key to config.lua, you got to edit configmanager.cpp and configmanager.h.
wow, it was so easy lol. Tested and works.
1661160004883.png
Dzięki :)
 
wow, it was so easy lol. Tested and works.
View attachment 70027
Dzięki :)
You can also try algo 4. Monsters react as with 1 (instant reaction), but it should use much less CPU:
C++:
            } else if (algo == 4) { // try to reduce cpu, fast reaction v3
                if (!isUpdatePathScheduled) {
                    int64_t walkDelay = getWalkDelay();
                    isUpdatePathScheduled = true;
                    if (walkDelay <= 0) {
                        g_dispatcher.addTask(createTask(std::bind(&Game::updateCreatureWalk, &g_game, getID())));
                    } else {
                        g_scheduler.addEvent(createSchedulerTask(walkDelay, std::bind(&Game::updateCreatureWalk, &g_game, getID())));
                    }
                }
                isUpdatingPath = true;
            }
To test it, you got to add in creature.h (public Creature variable):
C++:
isUpdatePathScheduled = false;
and in game.cpp under:
C++:
void Game::updateCreatureWalk(uint32_t creatureId)
{
   Creature* creature = getCreatureByID(creatureId);
add:
C++:
if (creature) {
   creature->isUpdatePathScheduled = false;
}
 
You can also try algo 4. Monsters react as with 1 (instant reaction), but it should use much less CPU:
C++:
            } else if (algo == 4) { // try to reduce cpu, fast reaction v3
                if (!isUpdatePathScheduled) {
                    int64_t walkDelay = getWalkDelay();
                    isUpdatePathScheduled = true;
                    if (walkDelay <= 0) {
                        g_dispatcher.addTask(createTask(std::bind(&Game::updateCreatureWalk, &g_game, getID())));
                    } else {
                        g_scheduler.addEvent(createSchedulerTask(walkDelay, std::bind(&Game::updateCreatureWalk, &g_game, getID())));
                    }
                }
                isUpdatingPath = true;
            }
To test it, you got to add in creature.h (public Creature variable):
C++:
isUpdatePathScheduled = false;
and in game.cpp under:
C++:
void Game::updateCreatureWalk(uint32_t creatureId)
{
   Creature* creature = getCreatureByID(creatureId);
add:
C++:
if (creature) {
   creature->isUpdatePathScheduled = false;
}
Why did you deleted the TFS with monster behavior optimization? Can you re up?
 
Why did you deleted the TFS with monster behavior optimization? Can you re up?
A better question is, why is the monster behavior optimization not in the main branch? The main reason not to use it seems to be server preformance issues. But this is only a problem with large amount of players. The servers with such vast amount of players should be much better equipped to revert this optimization if they find it to be necessary. All the small servers however, who only gets benefits from this optimization, surely would struggle more than the big servers to implement such a change... So why is it the burden is placed on those servers?
 
I got confused. Wich the difference between use:

C++:
            if (getWalkDelay() <= 0) {
                Dispatcher::getInstance().addTask(createTask(
                    boost::bind(&Game::updateCreatureWalk, &g_game, getID())));
            }
            isUpdatingPath = true;

instead

C++:
                if (getWalkDelay() <= 0) {
                    g_dispatcher.addTask(createTask(std::bind(&Game::updateCreatureWalk, &g_game, getID())));
                }
                isUpdatingPath = true;

?
 
I got confused. Wich the difference between use:

C++:
            if (getWalkDelay() <= 0) {
                Dispatcher::getInstance().addTask(createTask(
                    boost::bind(&Game::updateCreatureWalk, &g_game, getID())));
            }
            isUpdatingPath = true;

instead

C++:
                if (getWalkDelay() <= 0) {
                    g_dispatcher.addTask(createTask(std::bind(&Game::updateCreatureWalk, &g_game, getID())));
                }
                isUpdatingPath = true;

?
One is single ton interface and the second is a global variable call "g_dispatcher".
 
One is single ton interface and the second is a global variable call "g_dispatcher".
I see, my server being OTX (older) cannot compile the second option. Do I need to change something in this function to have a better optimization?
 
I see, my server being OTX (older) cannot compile the second option. Do I need to change something in this function to have a better optimization?
Use the first one instead if the second one does not work in your server.
 
Last edited:

Is there any fix out for this ? ( TFS 1.5 )

TFS: 0.3.6 and 0.4 reaction:
It's even commented in TFS code ensure ranged creatures turn to player:
Looks like in TFS 1.5 it's false by default [turn ONLY if did range attack], but in 1.4 it was true by default, so it did turn to player 1 time per second.

In 1.4 it was (true by default):
C++:
bool updateLook = true;
in void Monster::doAttacking(uint32_t interval). Change it to false and it won't turn unless it execute some spell (ex. Dragon Lord wave/area hit)
 
Last edited:
Necroing this thread. Tested Marks version but can't produce same results as Geisor. Don't notice any noticable difference between being in combat and not. My CPU usage seems normal and it goes up and down based on procesess on my PC I assume. At some point it goes down even though I'm in combat with the monsters and then sometimes go up while not in combat.

Using overclocked AMD Ryzen 7 3700X can see in the top right corner.

I'm gonna test Marks version in production for 50-100 players soon.

 
Necroing this thread. Tested Marks version but can't produce same results as Geisor. Don't notice any noticable difference between being in combat and not. My CPU usage seems normal and it goes up and down based on procesess on my PC I assume. At some point it goes down even though I'm in combat with the monsters and then sometimes go up while not in combat.

Using overclocked AMD Ryzen 7 3700X can see in the top right corner.

I'm gonna test Marks version in production for 50-100 players soon.

Try Multithread pathfinding · gesior/forgottenserver-gesior@48cb292 (https://github.com/gesior/forgottenserver-gesior/commit/48cb292d56d36e87ab25e2bc00bcc5c61c4cc842)
 
Geisor version.

Also found something weird. Monsters always look at you directly. And it leads to them snapping back and forth.

Fixed with Geisor additional fix above.

Geisor Version.

Geisor Version with 6 characters
 
Last edited:
To conclude this thread once a for all.

Short answer: Use Marks change

Long answer:
With a dedicated CPU from Hetzner
Name: CCX13, vCPU 2 cores AMD, RAM: 8 GB
I hosted my server with 150 players at launch with 5-10% CPU usage no lags.

Thoughts:
If your server over 2000 players online using very intrecate systems where chasing monsters are plenty and super fast. You should probably redo my tests.
 
Back
Top