I am working on a C++ server. I already implemented some stuff as you can see below.
I am not using anything from unet.
The sending rate of my scripts in this video is set to 9.
https://gfycat.com/gifs/detail/CheapRegalConch
However, I am starting to code the nonplayer stuff. I have multiple questions. I would like to get some advice, like good practices, what should I do to easily scale my server, etc.
It is obvious that the server will be responsible to define where and when to spawn the nonplayers characters (monsters, etc.), however, how should I control the behavior of the NPC after spawned?
I thought something like:
- During the first time running the server, I would have to transfer to the server a bunch of data for each NPC.
- For that, I would make a separated build responsible to export in SQL the data of each NPC (location, id, slug, etc.).
- Based on that I would create the database of the server, and the server would know each NPC to control.
- I would send this information to the player when necessary, e.g., in range, other stuff, etc.
Here is the problem, after I detect each NPC and when to send, how could I control the behavior of the NPC? I mean, the server will not have access to the update method of the unity object.
In this way, one option would be:
5. All info of the NPC are registered in the server, started and then put to sleep.
6. When a condition related to the function that sends that information to the player is satisfied, the server sends to the player an action to instantiate the monster, and after that, this player would synchronize this monster actions with the server, and the server to the others.
7. When the monster dies, the server waits for the respawn time and return to state 5.
Another question, how could I implement something easy to sync variables?
I would appreciate some advice.
Thanks,
Willian