[Question] Best way to do the SpawnSystem.

Results 1 to 17 of 17
  1. #1
    DBO Developer Nicolas321 is offline
    MemberRank
    May 2014 Join Date
    482Posts

    [Question] Best way to do the SpawnSystem.

    Hi everybody, I just want to ask if anybody can give me one example or somewhere to search about the SpawnSystem to player, for example in MMORPG have 6.000 mobs and 2.000 NPC if I send all of them to the players gets really laggy...

    So how can I make this system?

    I got this, one for who is called every 50 miliseconds so checks all of the monsters & npc, yes one for with 8.000 things who is called every 50 miliseconds to all players and that is get laggy and I want to know how do it better or maybe change all the system but make it the best way.

    Example I got 30 players online...

    Servers SPAM every 50 ml 8.000 to one player, then to other, then to other and send all informations of the mobs/npc one by one. Only spawn the mob/npc who are less than 20 of distance ( The calculation between Mobs X/Y/Z and Player X/Y/Z ).

    Packet, packet.

    So the servers get a little bit laggy...

    Example of code
    Code:
    while (ServerIsRunning())
    {
        // I got a map with players and mobs
        for ( USERLISTIT it = userList.begin(); it != userList.end(); it++ ) {
        
            for ( MOBLISTIT it2 = mobList.begin(); it2 != mobList.end(); ++it2 ){
                if ( GetDistance(it->second->GetPosition(), it2->second->GetPosition()) && !AlreadySeeIt(it2->second->mobId) ) {
                    //SPAWNMOB...
                }
                else
                    //DESPAWNMOB...
            }
        }
        Sleep(50);
    }
    Last edited by Nicolas321; 03-05-15 at 02:22 AM.


  2. #2
    Enthusiast Arthur Padilha is offline
    MemberRank
    Jul 2013 Join Date
    41Posts

    Re: [Question] Best way to do the SpawnSystem.

    Create only the mobs where players are close

  3. #3
    DBO Developer Nicolas321 is offline
    MemberRank
    May 2014 Join Date
    482Posts

    Re: [Question] Best way to do the SpawnSystem.

    I mean... when I startup the server, I send all the data of the MOBS inside one MAP, then when someplayer connect the while start and said if player are close to the mob for 20 steps show to him, but this spawm every 50 milisecond or every step the player made, for that I want to know if there is a better way.

    Because imagine there are 30 players online so the server start to spam the action SPAWNMOB...

    The code already have spawning the mobs where are close to the player... but spam so many times, maybe there is a better way, i don't know, for that i'm asking.

    This is what I do

    Code:
    // This for calls every players inside the server example 20 players
    for ( USERLISTIT it = userList.begin(); it != userList.end(); it++ ) {
    	// This for is called 8.000 times... because the map have 8.000 mobs
    	for ( MOBLISTIT it2 = mobList.begin(); it2 != mobList.end(); ++it2 ){
    		// This said if the distance is less tan 20 steps AND I don't see it
    		if (TheDistanceBetween(mob, player) < 20 && !DontSee(mobId))
    		{
    			SendDontSee(mobId); // this said i look the mob
    			SendPacket(ShowMob);// for example can be 100 mobs
    		}
    	}
    }
    // So I got 8.000 times check the player pos and mob pos
    // Maybe I send one by one but this is going to do like 30 times, because are 30 players
    // So is 30 * 8.000 = 240.000 checks the server made in only 50 miliseconds
    Last edited by Nicolas321; 03-05-15 at 08:43 AM.

  4. #4
    Enthusiast Arthur Padilha is offline
    MemberRank
    Jul 2013 Join Date
    41Posts

    Re: [Question] Best way to do the SpawnSystem.

    Stop thinking about individual spawn and then returned to the area. Check if the player is near the area to send packages showing the monsters only for that specific player.


    example:


    1 - "Bee" Spawn
    2 - There are less than 10 "Bees" alive?


    Yes:
    Create a bee and wait a while to rescan


    not:
    Check again in 5 seconds




    You have to imagine that the player will not be killing this monster only. To do a better system, each monster is killed you can check the amount present in the area and check if it need more monster in the event of death, not by time.

  5. #5
    DBO Developer Nicolas321 is offline
    MemberRank
    May 2014 Join Date
    482Posts

    Re: [Question] Best way to do the SpawnSystem.

    You mean SpawnAreas? If some player enter to this area show to him the monsters?

    Because what I do is this.

    The player have one Circle (unseen) with 20 blocks of area, and, If one mob of 8.000 are inside of that circle show to him.

    For example I can say 20 mobs are inside of my Circle so, show that mobs to that player.

    But you are telling to me forgot about individual, so what I have to do is make Spawn area and if some player are close to that area or inside of that Spawn Area show to him every mob in that area?

  6. #6
    Enthusiast Arthur Padilha is offline
    MemberRank
    Jul 2013 Join Date
    41Posts

    Re: [Question] Best way to do the SpawnSystem.

    Yes, basically it. Try playing some mmo and see that the monster is visible when you get near to where it belongs

  7. #7
    DBO Developer Nicolas321 is offline
    MemberRank
    May 2014 Join Date
    482Posts

    Re: [Question] Best way to do the SpawnSystem.

    But I already have it, when I near of that monster is visible. Near of 20 steps, but what I say if I have to make Sawn Area for the entire map.

    I don't know if U understand what I said, the code make visible all the monster who are near to you, and what I ask if is there any better way to do it, because I got 8.000 mobs and gets laggy if I every 50 miliseconds make the server do the function again.

  8. #8
    Enthusiast Arthur Padilha is offline
    MemberRank
    Jul 2013 Join Date
    41Posts

    Re: [Question] Best way to do the SpawnSystem.

    You may have missed a point that I said. Do not make that spawn with so little time, do a test to find out how much living mobs in their death event. So you save a lot of processing

  9. #9
    DBO Developer Nicolas321 is offline
    MemberRank
    May 2014 Join Date
    482Posts

    Re: [Question] Best way to do the SpawnSystem.

    What is how much living in their death event? I know when they are death, I use monster->bMobDead() true or false...

  10. #10
    Enthusiast Arthur Padilha is offline
    MemberRank
    Jul 2013 Join Date
    41Posts

    Re: [Question] Best way to do the SpawnSystem.

    Remove the check of time to see the amount of monsters, when the monster's death event is active you spawn a new one.

  11. #11
    DBO Developer Nicolas321 is offline
    MemberRank
    May 2014 Join Date
    482Posts

    Re: [Question] Best way to do the SpawnSystem.

    Ahh you mean with HOW MANY mobs are? But the systems isn't that way...

    And with Spawn System I don't mean the ReSpawn System, I already got the ReSpawn System, what I want to do is make the monster who are near to player visible to the player...

    Like this...

    If player is near to mob Show the mob to player is all I want to do, but I ask if there is a better way because mine checks every time what the player move, checks 8.000 mobs position.

  12. #12
    ◝(⁰▿⁰)◜Smile◝ (⁰▿⁰)◜ Taiga is offline
    DeveloperRank
    May 2007 Join Date
    InternetLocation
    2,464Posts

    Re: [Question] Best way to do the SpawnSystem.

    This might be a massive bump but I would like to suggest this.

    @Nicolas321, you should implement an area system, you don't have to send the mobs to players which aren't in the area where the mobs spawn because that would only eat more CPU and bandwidth. An example: The player doesn't need to know that mob x spawned in the basement since he is on the 3rd floor of the castle. Feel free to reply if you've got more questions.

  13. #13
    DBO Developer Nicolas321 is offline
    MemberRank
    May 2014 Join Date
    482Posts

    Re: [Question] Best way to do the SpawnSystem.

    Yes, what I mean with spawn the mob, I don't mean the respawn system, I mean the player see the mob, like this, one second.

    https://www.youtube.com/watch?v=lZy-HMDGp4c

    This is my OLD file, you see, he have a circle around him, invisible of course, and when he is around one of one MOB/NPC that just make visible to him.

    So I have this, one MAP who contains all the data of the mobs, there are 35.000 mobs, and when I walk, I check the 35.000, and if one of them is like 20 fets close to me, I spawn it, so my dude is, is better to do Spawn System, or I just leave the things like I have?

  14. #14
    ◝(⁰▿⁰)◜Smile◝ (⁰▿⁰)◜ Taiga is offline
    DeveloperRank
    May 2007 Join Date
    InternetLocation
    2,464Posts

    Re: [Question] Best way to do the SpawnSystem.

    Quote Originally Posted by Nicolas321 View Post
    So I have this, one MAP who contains all the data of the mobs, there are 35.000 mobs, and when I walk, I check the 35.000, and if one of them is like 20 fets close to me, I spawn it, so my dude is, is better to do Spawn System, or I just leave the things like I have?
    I suggest using a region system, you should spawn all NPCs which are in that area.
    The region system decreases the size of the loop so it will save CPU power.

  15. #15
    DBO Developer Nicolas321 is offline
    MemberRank
    May 2014 Join Date
    482Posts

    Re: [Question] Best way to do the SpawnSystem.

    What is Region System? Some example?

  16. #16
    Enthusiast JustJay1978 is offline
    MemberRank
    Sep 2013 Join Date
    38Posts

    Re: [Question] Best way to do the SpawnSystem.

    basicly spawns npc's to the area when your char comes close to contact making a loop as CodeDragon say's thats is less intensive on your CPU

  17. #17
    Account Upgraded | Title Enabled! jonnybravo is offline
    MemberRank
    Sep 2006 Join Date
    773Posts

    Re: [Question] Best way to do the SpawnSystem.

    If it's something like C++ I would do.

    Code:
    std::map<unsigned int, NpcAI::NPC, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, NpcAI::NPC> > > n_mapNPC;
    Basically create NpcAi std::map and MobAi std::map loop thru them base on mapID and only spawn them base on the mapID. Since all npcs have cords only spawn them when X and Y cord meet whatever.

    As for mobAI would be the samething once you setup visibility code you can loop thru them base on the region they are in.

    Some games put terrain on server side and know where the player is and only spawn mobs base on visibility code.



Advertisement