0
\$\begingroup\$

Dabbling with basic MMO code because it intrigues me.

How does the server handle monsters / mobs?

I understand that generally on each game tick, the server loops through each player to send them updated positions of each other nearby player or mob.

So every player loop you're also looping through every other player but is it just standard to loop through the entire mob list too? I mean there could be 1000+ mobs idling around the game world/zone. Would this just slow the loops down?

I thought maybe they keep a seperate list of ACTIVE mobs, ones that are either near a player or are chasing a player, but that would still require looping the idle ones to check if a moving player comes near one. Unless the aggro loop is less frequent (thinking out loud here)..

Is there some tricks or common workarounds involved? Or is that just how they work?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

If a monster is in the forest, but there's nobody there to see it, does it really exist?

  • If a monster is in an area with no players, just ignore it. Nobody will attack it, and it won't attack anyone. So just pretend its not there. In fact, don't even bother initialising it. Its data probably exist in a file, hidden away from the CPU and memory.
  • Whenever the player moves to an area, if that area is meant to have monsters, initialise them. Now you'd need to send their data to that player.
  • If a player moves to a location but another player is already there, don't initialise the monsters, but make sure the new player is now getting their location and stats.

Don't forget that all games are full of illusions to make you believe things are less complicated than they actually are.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks, that makes sense. So just split up the idle mob list into map chunks or something, and only loop through the parts where players are. For mobs that chase a player and end up outside of their zone would be in the active mob list anyway (until they lose focus if the player escapes, then... dunno) \$\endgroup\$ Feb 20, 2019 at 12:26
  • \$\begingroup\$ @user1022585 there are plenty of ways to do it, each with its own ups and downs. What you described is one of them, you can also give the players a list of "mob chunks" so that you know which monsters to send to which player. \$\endgroup\$
    – TomTsagk
    Feb 20, 2019 at 12:27
  • \$\begingroup\$ Taking WoW as an example, if you take a flight with a Hunter that has tracking turned on you can easily see how the server uses a coarse grid to position the player and then a radius around that position to keep a circular area of mobs active and reporting to the player's client. When landing you can tell how only a smaller radius around the player is updated to the client, but how the larger coarse grid is still active because if you leave a mob behind and come back it has moved while you're away. MMOs mix a lot of techniques to create illusions! \$\endgroup\$ Feb 20, 2019 at 19:56
  • 1
    \$\begingroup\$ @PatrickHughes Not very familiar with how WoW handles monsters, but I used to play Lineage2 and whenever a monster would have no enemy target, it would go to its default position and start healing. That could be easily handled as "if monster is damaged, keep it active and healing, once its fully healed, de-spawn it until a player comes closer" this would give the illusion that a monster is "always active". As you said, there are indeed multiple ways to do that, each for different situations. \$\endgroup\$
    – TomTsagk
    Feb 21, 2019 at 0:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .