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.
Latest TFS.
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.When I edit this or increase distance server start to lag.
have a look at this,Anyone know how can I increase Creatures detection range?
So player can be detected not from basic 12 to more distance?
I was thinking this was a solution but not. When I edit this or increase distance server start to lag.have a look at this,
![]()
forgottenserver/src/monster.cpp at master · otland/forgottenserver
A free and open-source MMORPG server emulator written in C++ - otland/forgottenservergithub.com
i do not use these sources myself so i could be providing the wrong cpp file, try a search for 'cansee' and peak around.I was thinking this was a solution but not. 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.When I edit this or increase distance server start to lag.
setIdle(true);
setIdle(false);
setIdle(true);
setIdle(false);
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);
}
void Monster::updateIdleStatus()
{
setIdle(false);
}
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.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.
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.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 have tested now. You was right lags became HUGE after this. So yeah is not worth it.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) ):
to:C++:setIdle(true);
C++:setIdle(false);
2. Change ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L751) )
to:C++:setIdle(true);
3. Replace ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L679-L689) )C++:setIdle(false);
with: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); }
C++:void Monster::updateIdleStatus() { setIdle(false); }
Hi Sir! you know if this system are in the TFS 0.4?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) ):
to:C++:setIdle(true);
C++:setIdle(false);
2. Change ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L751) )
to:C++:setIdle(true);
3. Replace ( forgottenserver/src/monster.cpp at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/src/monster.cpp#L679-L689) )C++:setIdle(false);
with: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); }
C++:void Monster::updateIdleStatus() { setIdle(false); }
I think all OTSes made in last 20 years have system to make monsters go 'idle', when there is no player 'on screen'.i want do that monters dont move is not player on screen range or same floor
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:i looking around monster.cpp but can't find the Default range that you say bro
onCreatureAppear - creature appear (player logged in/monster spawned in range): tfs-old-svn/monster.cpp at curated/r3884 · otland/tfs-old-svn (https://github.com/otland/tfs-old-svn/blob/curated/r3884/monster.cpp#L138)onCreatureDisappear- creature disappear (player logged out/player or monster died in range): tfs-old-svn/monster.cpp at curated/r3884 · otland/tfs-old-svn (https://github.com/otland/tfs-old-svn/blob/curated/r3884/monster.cpp#L154)onCreatureMove - creature make step in range: tfs-old-svn/monster.cpp at curated/r3884 · otland/tfs-old-svn (https://github.com/otland/tfs-old-svn/blob/curated/r3884/monster.cpp#L168)onCreatureMove is send here:getSpectators function, but you should not modify it too, as half of OTS logic is based on that range.monster.cpp functions that call onCreatureFound and onCreatureLeave. These are functions that update targetList and it makes monsters go idle (when list is empty).im happy to SEE You Gesior, i Will for sure test it right now when Back HomeI 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').
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:
onCreatureAppear- creature appear (player logged in/monster spawned in range): tfs-old-svn/monster.cpp at curated/r3884 · otland/tfs-old-svn (https://github.com/otland/tfs-old-svn/blob/curated/r3884/monster.cpp#L138)onCreatureDisappear- creature disappear (player logged out/player or monster died in range): tfs-old-svn/monster.cpp at curated/r3884 · otland/tfs-old-svn (https://github.com/otland/tfs-old-svn/blob/curated/r3884/monster.cpp#L154)onCreatureMove- creature make step in range: tfs-old-svn/monster.cpp at curated/r3884 · otland/tfs-old-svn (https://github.com/otland/tfs-old-svn/blob/curated/r3884/monster.cpp#L168)
onCreatureMoveis send here:
![]()
tfs-old-svn/tile.cpp at a8df96dc1ddb6f005324e2a3d4ce43f62d7968fc · otland/tfs-old-svn
TFS repository once kept private, converted from SVN - otland/tfs-old-svngithub.com
but you should not modify it there, as there are many other systems of Player/NPC that are based on it.![]()
tfs-old-svn/tile.cpp at a8df96dc1ddb6f005324e2a3d4ce43f62d7968fc · otland/tfs-old-svn
TFS repository once kept private, converted from SVN - otland/tfs-old-svngithub.com
'range' is definied ingetSpectatorsfunction, 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 inmonster.cppfunctions that callonCreatureFoundandonCreatureLeave. These are functions that updatetargetListand 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:
![]()
feat: monsters react only to players on same floor by gesior · Pull Request #4 · otland/tfs-old-svn
Optional feature to make monsters see only players on same floor. It should ignores players on other floors and keep monsters idle: reduces CPU usage blocks 'random step', when player is o...github.com