ID:1399475
 
I was thinking about how most byond games have their mobs, and all i see is mobs place on the map by the map editor made to either sit there and take space waiting for players or cause mass amounts of lag randomly walking.

I wanted to know if my ideas i had for a spawn system would cause any extra lag then the other options.

Idea 1
To make a spawn system based on the move proc of the players when they enter certain areas to turn on the spawn list for that area, like you walk into the dark woods and it activates every few steps randomly selecting a mob in that list based on a % value i decide that mob should spawn at. Some question come to mind with the system more like flaws, this sounds like it would be a cpu hog and spawn a lot of mobs when players are trying to fend off the already spawned one. But then again i could just make a state meant like if the player is in combat to turn off the system for a set amount of time or to limit the amount of mobs that can be spawned by each player.

Idea 2
This idea is like the first but instead of the set area i would have the mob tied to a preset turfs that they spawn from when walking on.

Could someone tell me if these seem like they would be cpu hogs?
Lag, in the context of what we talk about here, means network latency.

If your CPU usage is bottlenecked due to poor code/too much processing, that is not lag.


Neither idea sounds particularly viable.

It'd probably be better to simply disable mobs when their area no longer has an active user in it. There's no need to delete them, or cause them to not exist, since as long as the AI isn't running, they won't suck up any processing power.

For every player in an area, increase the "observer" count.

When observer count is equal to 0 after a player exits the area, signal the mobs to stop moving.

When the observer count is equal to 0, but becomes 1 when a player enters the area, signal the mobs in the area to start moving.

Of course, there are better ways to handle this, but this is the simplest form of ensuring your NPCs are not sucking up valuable CPU power where there's no reason for them to be working.
In response to Ter13
I don't think you understand what i'm trying to say, i don't want mobs on the map at all i want them to be spawned by the players when they are in the area that way i can adjust which mob spawns and how offend they spawn, kinda like how you have chance to find rare pokemon when you are walking around. I don't quiet understand the observer part you talked about.
He means that you could keep track of how many players are in an area and use that to decide what to do with mobs. Which would work perfectly for what you are trying to do - especially if you want the number of players to affect the types of mobs that spawn