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).