Monster movement in server side?(Server NodeJS)

Nyro17

Member
Hello everyone's here!

Im creating somehow an MMORPG 2D top-down. (Something like Pokemon)

I would like to know what are different ways you would use to make a monster move to a player and collide with other objects in the whole room .

I know that everything must be in the server to avoid people cheating.

Feel free to post here your ideas to make the movement to the player and collisions, if you have any reference about where should i look for them, i will appreciate it.

Additional information:
Grid 16x16
No diagonals while movement(only north, west,east,south).

Thanks =]
 

Binsk

Member
If it is a host / client situation then things are going to start getting really expensive for your server if literally everything is calculated server-side. Offload what you can to the client and only have the server calculate the important bits.

If you have a monster in cell A that must move to cell B, then just pass cell A and cell B to the client and let the client calculate the path and movement for the monster. Assuming the maps are the same on all clients (which may not be the case w/ dynamic collideable objects due to game lag, but I don't know your setup here) this shouldn't be an issue. If you are worried about the client messing w/ the movement data then have the AI ping back to the server when it arrives at the location for verification to make sure it is in the right spot.
 
I would like to know what are different ways you would use to make a monster move to a player and collide with other objects in the whole room .
For horizontal movement: use x += horizontal_speed
For vertical movement: use y += vertical_speed
For collisions, you can use the collision event.
And you should start with creating a chatroom or an online tic-tac-toe to start with, because just by how you formulated your question, I'm pretty sure things are not ready for this on your side just yet.

I don't buy what @Binsk is saying, looping through an array won't be <<really expensive>>, plus, chances are you're not ever going to have enough players to make it lag.
 
  • Thinking
Reactions: Roa

Nyro17

Member
If it is a host / client situation then things are going to start getting really expensive for your server if literally everything is calculated server-side. Offload what you can to the client and only have the server calculate the important bits.

If you have a monster in cell A that must move to cell B, then just pass cell A and cell B to the client and let the client calculate the path and movement for the monster. Assuming the maps are the same on all clients (which may not be the case w/ dynamic collideable objects due to game lag, but I don't know your setup here) this shouldn't be an issue. If you are worried about the client messing w/ the movement data then have the AI ping back to the server when it arrives at the location for verification to make sure it is in the right spot.
Hi! Thanks for your reply 😄
Well, i create monsters in server(nodejs), they move to player, but sometimes they stuck.

About ur idea, i know what u said, but it wont work, since movement is managed from server, in client u only see data from server.
 

Nyro17

Member
For horizontal movement: use x += horizontal_speed
For vertical movement: use y += vertical_speed
For collisions, you can use the collision event.
And you should start with creating a chatroom or an online tic-tac-toe to start with, because just by how you formulated your question, I'm pretty sure things are not ready for this on your side just yet.

I don't buy what @Binsk is saying, looping through an array won't be <<really expensive>>, plus, chances are you're not ever going to have enough players to make it lag.
Hey! Thanks for ur idea.
The code must be in server side, NodeJS doesnt reconogize horizontal_speed or vertical, thats from GMS :(
 

Binsk

Member
I don't buy what @Binsk is saying, looping through an array won't be <<really expensive>>, plus, chances are you're not ever going to have enough players to make it lag.
MMORPG by definition means 'massive', meaning a lot of players. If you have 2000 players on a server then sending an array of, say, 10 cells for just ONE monster who knows how often takes a lot of bandwidth for the server, especially once scaled to numerous AI. Of course there are region-based optimizations and whatnot to be done but that wasn't the question. While I would tend to agree that this project would never get to a large enough scale the idea of, "If it can be broken, the player will find a way to be break it" applies here. In the case that the game does get very large you want the system to be designed from the ground-up to handle it; you don't want a last-minute panic where all your network code needs to be redone while you have a large active user-base complaining at you.

The code must be in server side, NodeJS doesnt reconogize horizontal_speed or vertical, thats from GMS :(
This is a GameMaker forum and your question is very unspecific nor is it related to GameMaker. You may have better luck asking on a forum more suited to the language you are using. To be honest, if you are asking these kinds of questions then you aren't ready to build an MMO. You should at least have some idea as to how you will tackle this and if you don't do some research online.
 
Hey! Thanks for ur idea.
The code must be in server side, NodeJS doesnt reconogize horizontal_speed or vertical, thats from GMS :(
Just send them over with buffers from GM, or (even better) send the player's key presses and calculate those speed and positions server-side. There's no reason NodeJS won't take floats (just convert to double if you have trouble with that) or bools.

To be honest, if you are asking these kinds of questions then you aren't ready to build an MMO.
+ rep
 

Nyro17

Member
Just send them over with buffers from GM, or (even better) send the player's key presses and calculate those speed and positions server-side. There's no reason NodeJS won't take floats (just convert to double if you have trouble with that) or bools.


+ rep
Hello, thanks for your reply.

Thats what Im actually doing, and its perfect! I send player position from client to server, update it, and give it back to player, so other players notice about this event and get that new player info(in case they move or stop moving)

Im asking about movement of monster in server side, this way having player positions, with a good pathfind I can move monster. Im using now Easy Star by PrettyMuchBryce, pathfind is good but not the best because I see some paths better and it choose other one...

So thats what Im asking 😅

Any idea? Im really tired trying and getting 0 results :(

Additional info:

Monster must be created in server so people cant cheat hp, experience or loot ^^(thats done).

Any other way to make a pathfind or library suggested?🥺
 
Sounds like it's just a pathfinding problem, if you can already send, receive, transform, and send back your data.
I'm not really an asset guy, I can't suggest stuff that's already been made that I'm not familiar with.
Just make your own, you can tail it just like your project needs. Especially if you want to have something somewhat optimized that runs smoothly, you should just start from the ground up.
 

Nyro17

Member
Sounds like it's just a pathfinding problem, if you can already send, receive, transform, and send back your data.
I'm not really an asset guy, I can't suggest stuff that's already been made that I'm not familiar with.
Just make your own, you can tail it just like your project needs. Especially if you want to have something somewhat optimized that runs smoothly, you should just start from the ground up.
Im not able to create my own library, thays why I wrote the post 😅

Anyways, thanks for your time man. 😊
 

NightFrost

Member
If you're doing a multiplayer game (MMO or othewise) it should be the server that does the simulation. The desktop program is just a client that connects to the server and delivers a graphical representation of server state to players. Any decisionmaking process that is deferred to client side offers an opportunity for players to cheat, simply by returning bogus data through some program tailored to discuss with your server. To put it simply, client only requests to do an action; the server decides whether it is allowed.

To take movement as example. The client very likely would have collision detection on movement, both for visual convenience and to stop it making pointless movement requests to server when the client can clearly see the movement is not allowed. But any movement request that comes through to server must be checked by the server and either allowed or disallowed. Allowing means it updates the state of simulation with new player location, disallowing means no updates to simulation.

For a client that attempts to move into a forbidden position and on client side somehow manages it, this manifests as rubberbanding (no doubt familiar to any MMO player) as the update from server repositions them to last legal position they are holding in the server's simulation. (And this is where the thing turns to fights between the server and cheaters. Simulating legal actions is the simple part. Blocking all the stuff cheaters try to pass in is the complex part. For example, movement updates that set destination far away from current position should not go through.)
 
Last edited:
Top