Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: c# Zombie spawner

  1. #1
    Scavenger
    Join Date
    Jul 2016
    Posts
    42
    Rep Power
    0

    c# Zombie spawner

    Englisch Google Translate

    Good evening,
    I have a problem with the zombie spawner here.

    I go through this loop every 30 minutes,
    spawning a zombie, it also works until there is a mistake.

    What could be the reason ?

    Here is the code excerpt:

    Code:
    private static void Spawn(Vector3 _pos, int _rotation){
    	foreach (KeyValuePair<string, int> kvp in test)
    	{
    		var random = new System.Random();
    		int index = random.Next(z_namenlist.Count);
    		string z_name = z_namenlist[index];
    		string name = z_name;
    		Entity Spawn_zombie = EntityFactory.CreateEntity(EntityClass.FromString(name), _pos);
    		Vector3 vec = Spawn_zombie.rotation;
    		vec.y = _rotation;
    		Spawn_zombie.SetRotation(vec);
    		Spawn_zombie.SetPosition(_pos);
    		GameManager.Instance.World.SpawnEntityInWorld(Spawn_zombie);
    	}
    }
    Here the error from the log:
    Receiving unhandled NULL exception
    #0 0x007fd15059b780 in _L_unlock_13
    #1 0x007fd15059be10 in physx::Cm::CmEventNameProvider::~CmEventNameProvid er()
    #2 0x007fd15059be70 in physx::Cm::CmEventNameProvider::~CmEventNameProvid er()
    #3 0x007fd15059bea0 in physx::Cm::CmEventNameProvider::~CmEventNameProvid er()
    #4 0x007fd15059bef0 in operator new[](unsigned long, std::nothrow_t const&)
    #5 0x007fd15059bf50 in (Unknown)
    #6 0x007fd15059bf60 in (Unknown)
    Deutsch:

    Schönen guten Abend,
    ich habe hier ein Problem beim Zombie spawner.

    Ich durchlaufe alle 30 Minuten diese schleife,
    um ein ein Zombie spawnen, dies funktioniert auch, bis es ein Fehler gibt.

    An was kann das liegen ?

    Code siehe oben.

    Who can help me ?

    MFG cookyman
    Last edited by cookyman; 4 Weeks Ago at 08:29 PM.

  2. #2
    Super Moderator Roland's Avatar
    Join Date
    Feb 2014
    Location
    On a Zipline
    Posts
    14,750
    Rep Power
    2
    Thanks for PMing me about your code. I wish I could help but beyond simple xml edits I am useless. Hopefully someone else around here will be able to help you.

  3. #3
    Colony Founder KhaineGB's Avatar
    Join Date
    Apr 2017
    Location
    Liverpool, UK
    Posts
    1,576
    Rep Power
    1
    Look at the spawnvehicle item class or SpawnEntity block class in the DLL.

    Both can be used to spawn entities. They might help you identify the problem.

    Google Translate Deutsche.

    Schauen Sie sich die Spawnvehicle-Elementklasse oder die SpawnEntity-Blockklasse in der DLL an.

    Beide können verwendet werden, um Entitäten zu erzeugen. Sie können Ihnen helfen, das Problem zu identifizieren.

  4. #4
    Scavenger
    Join Date
    Jul 2016
    Posts
    42
    Rep Power
    0
    That works so far,
    after about 10 passes this error comes as written above.
    I have tried and tested a lot but the error keeps coming back.

    Here is my whole script with the loop.
    Code:
            public static void Auto_spawn()
            {
                if (pos.Count > 0 && ConnectionManager.Instance.ClientCount() > 0)
                {
                    try
                    {
                        foreach (KeyValuePair<string, int> kvp in pos)
                        {
                            Entities = GameManager.Instance.World.Entities.list;
                            string[] _pos = kvp.Key.Split(',');
                            int.TryParse(block_pos[0], out int _pos_x);
                            int.TryParse(block_pos[1], out int _pos_y);
                            int.TryParse(block_pos[2], out int _pos_z);
    
                            var vector3_block_pos = new Vector3((float)_pos_x, (float)_pos_y, (float)_pos_z);
    
                            World world = GameManager.Instance.World;
                            bool spieler_da = false;
                            bool trader_da = false;
    
                            List<EntityPlayer> PlayerList = world.Players.list;
                            for (int i = 0; i < PlayerList.Count; i++)
                            {
                                EntityPlayer _player = PlayerList[i];
                                if (_player != null)
                                {
                                    ClientInfo _cInfo = ConnectionManager.Instance.Clients.ForEntityId(_player.entityId);
                                    if (_cInfo != null && _player.IsSpawned() && _player.IsAlive())
                                    {
                                        EntityPlayer _douche = world.GetClosestPlayer(vector3_block_pos, 75, false);
                                        if (_douche != null)
                                        {
                                            spieler_da = true;
                                            continue;
                                        }
                                    }
                                }
                            }
    
                            if (spieler_da)
                            {
                                List<ClientInfo> _cInfoList = ConnectionManager.Instance.Clients.List.ToList();
                                ClientInfo _cInfo = _cInfoList.RandomObject();
    
                                int entityID = EntityGroups.GetRandomFromGroup("Z_Spawner");
                                Entity spawnEntity = EntityFactory.CreateEntity(entityID, vector3_block_pos) as EntityEnemy;
    
                                //world.entityDistributer.Add(spawnEntity);
                                //world.aiDirector.AddEntity((Entity)spawnEntity);
                                
    
                                world.SpawnEntityInWorld(spawnEntity);
                                //world.AddEntityToMap(spawnEntity);
                                SdtdConsole.Instance.ExecuteSync(string.Format("saveworld"), _cInfo);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logs.MYSQL_Log(Class_Name, MethodBase.GetCurrentMethod().Name, string.Format("Es ist ein Fehler aufgetreten. Fehler Bezeichnung: {0}", e.Message));
                    }
                }
            }
    Last edited by cookyman; 4 Weeks Ago at 12:38 PM.

  5. #5
    Colony Founder sphereii's Avatar
    Join Date
    Dec 2015
    Posts
    3,536
    Rep Power
    1
    Quote Originally Posted by cookyman View Post
    That works so far,
    after about 10 passes this error comes as written above.
    I have tried and tested a lot but the error keeps coming back.

    Here is my whole script with the loop.
    Code:
            public static void Auto_spawn()
            {
                if (pos.Count > 0 && ConnectionManager.Instance.ClientCount() > 0)
                {
                    try
                    {
                        foreach (KeyValuePair<string, int> kvp in pos)
                        {
                            Entities = GameManager.Instance.World.Entities.list;
                            string[] _pos = kvp.Key.Split(',');
                            int.TryParse(block_pos[0], out int _pos_x);
                            int.TryParse(block_pos[1], out int _pos_y);
                            int.TryParse(block_pos[2], out int _pos_z);
    
                            var vector3_block_pos = new Vector3((float)_pos_x, (float)_pos_y, (float)_pos_z);
    
                            World world = GameManager.Instance.World;
                            bool spieler_da = false;
                            bool trader_da = false;
    
                            List<EntityPlayer> PlayerList = world.Players.list;
                            for (int i = 0; i < PlayerList.Count; i++)
                            {
                                EntityPlayer _player = PlayerList[i];
                                if (_player != null)
                                {
                                    ClientInfo _cInfo = ConnectionManager.Instance.Clients.ForEntityId(_player.entityId);
                                    if (_cInfo != null && _player.IsSpawned() && _player.IsAlive())
                                    {
                                        EntityPlayer _douche = world.GetClosestPlayer(vector3_block_pos, 75, false);
                                        if (_douche != null)
                                        {
                                            spieler_da = true;
                                            continue;
                                        }
                                    }
                                }
                            }
    
                            if (spieler_da)
                            {
                                List<ClientInfo> _cInfoList = ConnectionManager.Instance.Clients.List.ToList();
                                ClientInfo _cInfo = _cInfoList.RandomObject();
    
                                int entityID = EntityGroups.GetRandomFromGroup("Z_Spawner");
                                Entity spawnEntity = EntityFactory.CreateEntity(entityID, vector3_block_pos) as EntityEnemy;
    
                                //world.entityDistributer.Add(spawnEntity);
                                //world.aiDirector.AddEntity((Entity)spawnEntity);
                                
    
                                world.SpawnEntityInWorld(spawnEntity);
                                //world.AddEntityToMap(spawnEntity);
                                SdtdConsole.Instance.ExecuteSync(string.Format("saveworld"), _cInfo);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logs.MYSQL_Log(Class_Name, MethodBase.GetCurrentMethod().Name, string.Format("Es ist ein Fehler aufgetreten. Fehler Bezeichnung: {0}", e.Message));
                    }
                }
            }
    Maybe move yuor SdtdConsole.instance.ExecuteSync() outside of all your loops? I am not sure what that does. I have not used it.

    Maybe also set spawner type?

    Code:
                spawnEntity.SetSpawnerSource(EnumSpawnerSource.Dynamic);
                world.SpawnEntityInWorld(spawnEntity);

  6. #6
    Scavenger
    Join Date
    Jul 2016
    Posts
    42
    Rep Power
    0
    The SdtdConsole.instance.ExecuteSync () was just a test, I removed that.

    I have now tested several things and again after several times through the loop he has brought me this mistake.

    I then tested everything and checked it line by line,
    as soon as I add this line:
    Code:
    Entity spawnEntity = EntityFactory.CreateEntity(entityID, vector3_block_pos);
    , the error comes.

    Here is my New code:

    Code:
                        foreach (KeyValuePair<string, int> kvp in pos)
                        {
                            Entities = GameManager.Instance.World.Entities.list;
                            string[] block_pos = kvp.Key.Split(',');
                            int.TryParse(block_pos[0], out int pos_x);
                            int.TryParse(block_pos[1], out int pos_y);
                            int.TryParse(block_pos[2], out int pos_z);
    
                            var vector3_pos = new Vector3((float)pos_x, (float)pos_y, (float)pos_z);
    
                            World world = GameManager.Instance.World;
                            int entityID = EntityGroups.GetRandomFromGroup("Z_Spawner");
    
                            if (entityID > 0)
                            {
                                Entity spawnEntity = EntityFactory.CreateEntity(entityID, vector3_pos);
                                spawnEntity.SetSpawnerSource(EnumSpawnerSource.Dynamic);
                                world.SpawnEntityInWorld(spawnEntity);
                            }
                            Thread.Sleep(5000);
                        }

  7. #7
    Colony Founder sphereii's Avatar
    Join Date
    Dec 2015
    Posts
    3,536
    Rep Power
    1
    Quote Originally Posted by cookyman View Post
    The SdtdConsole.instance.ExecuteSync () was just a test, I removed that.

    I have now tested several things and again after several times through the loop he has brought me this mistake.

    I then tested everything and checked it line by line,
    as soon as I add this line:
    Code:
    Entity spawnEntity = EntityFactory.CreateEntity(entityID, vector3_block_pos);
    , the error comes.

    Here is my New code:

    Code:
                        foreach (KeyValuePair<string, int> kvp in pos)
                        {
                            Entities = GameManager.Instance.World.Entities.list;
                            string[] block_pos = kvp.Key.Split(',');
                            int.TryParse(block_pos[0], out int pos_x);
                            int.TryParse(block_pos[1], out int pos_y);
                            int.TryParse(block_pos[2], out int pos_z);
    
                            var vector3_pos = new Vector3((float)pos_x, (float)pos_y, (float)pos_z);
    
                            World world = GameManager.Instance.World;
                            int entityID = EntityGroups.GetRandomFromGroup("Z_Spawner");
    
                            if (entityID > 0)
                            {
                                Entity spawnEntity = EntityFactory.CreateEntity(entityID, vector3_pos);
                                spawnEntity.SetSpawnerSource(EnumSpawnerSource.Dynamic);
                                world.SpawnEntityInWorld(spawnEntity);
                            }
                            Thread.Sleep(5000);
                        }
    I would suggest printing out using Debug.Log() the values of the vector3_pos and the entityID you are getting. Maybe a pattern will emerge.

  8. #8
    Scavenger
    Join Date
    Jul 2016
    Posts
    42
    Rep Power
    0
    Here is the log,
    for the data:

    Code:
    New Loop --> this is the ( 11 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-37.0, 49.0, 511.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 551429383
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombieCrawl, name=zombieSteveCrawler, id=407]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 12 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-29.0, 49.0, 512.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 700142925
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieSteve, id=408]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 13 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-40.0, 49.0, 524.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 1862556927
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieDarlene, id=409]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 14 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-37.0, 49.0, 511.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 684120619
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieBiker, id=410]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 15 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-29.0, 49.0, 512.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 700142925
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieSteve, id=411]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 16 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-40.0, 49.0, 524.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 1957301067
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieStripper, id=412]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 17 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-37.0, 49.0, 511.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = -428337742
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieBoe, id=413]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 18 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-29.0, 49.0, 512.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = -428330054
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieJoe, id=414]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 19 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-40.0, 49.0, 524.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 700142925
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieSteve, id=415]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 20 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-37.0, 49.0, 511.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 551429383
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombieCrawl, name=zombieSteveCrawler, id=416]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 21 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-29.0, 49.0, 512.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 817467356
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieYo, id=417]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 22 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-40.0, 49.0, 524.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 1862556927
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieDarlene, id=418]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 23 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-37.0, 49.0, 511.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 817467356
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieYo, id=419]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 24 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-29.0, 49.0, 512.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 817467356
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieYo, id=420]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 25 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-40.0, 49.0, 524.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 817467356
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieYo, id=421]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 26 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-37.0, 49.0, 511.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 350518692
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieOldTimer, id=422]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    2019-04-20T00:01:47 272.876 INF VehicleManager Save
    New Loop --> this is the ( 27 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-29.0, 49.0, 512.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = -428327171
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieMoe, id=423]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 28 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-40.0, 49.0, 524.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 700142925
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieSteve, id=424]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 29 ) run
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the vector3_pos = (-37.0, 49.0, 511.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the entityID = 700142925
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 3:this is the spawnEntity = [type=EntityZombie, name=zombieSteve, id=425]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the ( 30 ) Loop
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    New Loop --> this is the vector3_pos = (-29.0, 49.0, 512.0)
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 1: this is the entityID = -428327171
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Step 2: this is the spawnEntity = [type=EntityZombie, name=zombieMoe, id=426]
     
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
    
    Receiving unhandled NULL exception
    #0  0x007f6d728a3700 in _L_unlock_13
    #1  0x007f6d728a3d90 in operator new[](unsigned long, std::nothrow_t const&)
    #2  0x007f6d728a3e00 in operator new[](unsigned long, std::nothrow_t const&)
    #3  0x007f6d728a3e40 in operator new[](unsigned long, std::nothrow_t const&)
    #4  0x007f6d728a3e80 in operator new[](unsigned long, std::nothrow_t const&)
    #5  0x007f6d728a3ef0 in operator new[](unsigned long, std::nothrow_t const&)
    #6  0x007f6d728a3f00 in operator new[](unsigned long, std::nothrow_t const&)
    #7  0x007f6d728a3f20 in start_thread
    #8  0x007f6d728a3fc0 in clone

  9. #9
    Colony Founder HAL9000's Avatar
    Join Date
    Feb 2014
    Posts
    1,911
    Rep Power
    1
    Check the KVP key to see if it's null when looping.

    You shouldn't sleep the main thread as that will freeze your whole game and you may be getting physics errors because of the time jumps.

    If this isn't the main thread that could be the problem and you're getting cross-threading issues.

    Use an coroutine if you want to delay the spawn or something that tracks the time on each frame.

    I posted an example a while ago: https://7daystodie.com/forums/showthread.php?40959

    Cheers,

    Hal

  10. #10
    Scavenger
    Join Date
    Jul 2016
    Posts
    42
    Rep Power
    0
    I tested everything and all the values ​​have an entry,
    I have also tested their function and run multiple times
    the same error has come.

    On the stable 16.4 is my option working fine, not on this stable.

    I'll give you the 2 functions that are responsible.

    The Timer class this is calling all:
    Code:
    using System.Timers;
    
    namespace test
    {
        class Class1
        {
            private static bool timer1Running = false;
    
            private static System.Timers.Timer t1 = new System.Timers.Timer();
            public static int z_spawn = 0;
    
            public static void Timer_Start()
            {
                if (!timer1Running)
                {
                    timer1Running = true;
                    t1.Interval = 1000;
                    t1.Start();
                    t1.Elapsed += new ElapsedEventHandler(Init);
                }
            }
    
    
            public static void Init(object sender, ElapsedEventArgs e)
            {
                if (Spawner.IsEnabled)
                {
                    z_spawn++;
                    if (z_spawn >= 15) //if (_auto_block_spawner >= Auto_Block_spawner * 60)
                    {
                        z_spawn = 0;
                        if (!Spawner.auto_laeuft)
                        {
                            //Spawner.Auto_spawn();
    
                            GameManager.Instance.StartCoroutine(Spawner.StartSpawn());
                        }
                    }
                }
                else
                {
                    z_spawn = 0;
                }
    
            }
        }
    }
    The spawner class:

    your option
    Code:
            public static IEnumerator StartSpawn()
            {
                if (block_pos.Count > 0 && ConnectionManager.Instance.ClientCount() > 0)
                {
                    if (!auto_laeuft)
                    {
                        auto_laeuft = true;
                        int x = -40;
                        int y = 49;
                        int z = 524;
    
                        World world = GameManager.Instance.World;
                        EntityPlayer _player = world.GetClosestPlayer(new Vector3((float)x, (float)y, (float)z), 75, false);
                        if (_player != null && _player.IsSpawned() && !_player.IsDead())
                        {
                            System.Random zufall = new System.Random();
                            int number = zufall.Next(4, 5);
                            auto_laeuft = true;
                            object wait = new WaitForSeconds(number);
                            string entityGroup = "ZombiesAll";
    
                            long _chunkval = 0;
                            int spawnCount = 0;
    
                            for (spawnCount = 0; spawnCount < 1; spawnCount++)
                            {
                                int entityID = EntityGroups.GetRandomFromGroup(entityGroup);
                                Entity spawnEntity = EntityFactory.CreateEntity(entityID, new Vector3((float)x, (float)y, (float)z));
                                spawnEntity.SetSpawnerSource(EnumSpawnerSource.StaticSpawner, _chunkval, entityGroup);
                                GameManager.Instance.World.SpawnEntityInWorld(spawnEntity);
                                spawnEntity = null;
                                yield return wait;
                            }
                            auto_laeuft = false;
                            yield return null;
                        }
                    }
                }
            }
    My option:
    Code:
            public static void Auto_spawn()
            {
                if (pos.Count > 0 && ConnectionManager.Instance.ClientCount() > 0)
                {
                    foreach (KeyValuePair<string, int> kvp in pos)
                    {
                        if (kvp.Key == null) continue;
                        string[] pos = kvp.Key.Split(',');
                        int.TryParse(pos[0], out int pos_x);
                        int.TryParse(pos[1], out int pos_y);
                        int.TryParse(pos[2], out int pos_z);
    
                        var vector3_pos = new Vector3((float)pos_x, (float)pos_y, (float)pos_z);
                        World world = GameManager.Instance.World;
                        int entityID = EntityGroups.GetRandomFromGroup("ZombiesAll");
                        Entity spawnEntity = EntityFactory.CreateEntity(entityID, vector3_pos);
                        spawnEntity.SetSpawnerSource(EnumSpawnerSource.Dynamic);
                        world.SpawnEntityInWorld(spawnEntity);
                    }
                }
            }
    All these functions bring the same error after some time, not for the first try, but after a short time.
    Code:
    Receiving unhandled NULL exception
    #0  0x007fb48489f340 in _L_unlock_13
    #1  0x007fb48489f9d0 in operator new[](unsigned long, std::nothrow_t const&)
    #2  0x007fb48489fd50 in operator new[](unsigned long, std::nothrow_t const&)
    #3  0x007fb48489fe00 in operator new[](unsigned long, std::nothrow_t const&)
    #4  0x007fb48489fe40 in operator new[](unsigned long, std::nothrow_t const&)
    #5  0x007fb48489fe80 in operator new[](unsigned long, std::nothrow_t const&)
    #6  0x007fb48489fef0 in operator new[](unsigned long, std::nothrow_t const&)
    #7  0x007fb48489ff00 in operator new[](unsigned long, std::nothrow_t const&)
    #8  0x007fb48489ff20 in start_thread
    #9  0x007fb48489ffc0 in clone
    Last edited by cookyman; 4 Weeks Ago at 12:23 PM.

  11. #11
    Scavenger
    Join Date
    Jul 2016
    Posts
    42
    Rep Power
    0
    If I run
    Code:
    GameManager.Instance.StartCoroutine(Spawner.StartSpawn());
    via a chat command or something, then the spawn will run without an error, but if I do this over the timer then the error will come after a while. How can I solve this ?

    I test it now over 4 hours, without result.

    Can someone help me ?

  12. #12
    Colony Founder HAL9000's Avatar
    Join Date
    Feb 2014
    Posts
    1,911
    Rep Power
    1
    Where are you starting the timer? If the code runs without error if run from a console command then it sounds like the problem is in the other code not listed here.

  13. #13
    Scavenger
    Join Date
    Jul 2016
    Posts
    42
    Rep Power
    0
    I start because of this timer:

    Code:
    public void GameAwake()
    {
    Timers.TimerStart();
    }
    Here The timer class:
    Code:
    using System.Timers;
    
    namespace test
    {
        class Timers
        {
            private static bool timer1Running = false;
    
            private static System.Timers.Timer t1 = new System.Timers.Timer();
            public static int z_spawn = 0;
    
            public static void Timer_Start()
            {
                if (!timer1Running)
                {
                    timer1Running = true;
                    t1.Interval = 1000;
                    t1.Start();
                    t1.Elapsed += new ElapsedEventHandler(Init);
                }
            }
    
    
            public static void Init(object sender, ElapsedEventArgs e)
            {
                if (Spawner.IsEnabled)
                {
                    z_spawn++;
                    if (z_spawn >= 15) //if (_auto_block_spawner >= Auto_Block_spawner * 60)
                    {
                        z_spawn = 0;
                        if (!Spawner.auto_laeuft)
                        {
                            //Spawner.Auto_spawn();
    
                            GameManager.Instance.StartCoroutine(Spawner.StartSpawn());
                        }
                    }
                }
                else
                {
                    z_spawn = 0;
                }
    
            }
        }
    }
    The rest of the code in the timer works perfectly,
    only spawn that.
    This is a .dll file like this one.

    https://7daystodie.com/forums/showth...2-Server-Tools
    Last edited by cookyman; 4 Weeks Ago at 09:16 AM.

  14. #14
    Colony Founder HAL9000's Avatar
    Join Date
    Feb 2014
    Posts
    1,911
    Rep Power
    1
    I'd get rid of the timer object. I'm not sure how Mono handles it but I'm pretty sure you'll be cross-threading the call into the spawn routine which could cause issues.

    You can use the coroutine I posted above to be a timer as well. Using the yield return WaitForSeconds() causes that code to pause for the time specified without stopping the whole thread.

    Cheers,

    Hal

  15. #15
    Colony Founder StompyNZ's Avatar
    Join Date
    Apr 2015
    Posts
    3,893
    Rep Power
    1
    EntityFactory.CreateEntity can not be run in a subthread

    Is this for an api mod?

    When adding spawns you can add them to a Queue list, this can be the subthreaded part

    In the GameUpdate I checks if certain conditions are met like enough time since the last run has passed so it doesnt deadlock the main thread trying to process spawns

    If the conditions are met and a spawn is required it then calls the CreateEntity in the main thread using the spawn data created previously

    some code samples:

    Code:
        private static void GameStartDone()
        {
          IsAwake = true;
        }
    
        private static void GameUpdate()
        {
          if (IsAwake)
          {
            EntitySpawner.ProcessSpawnQueue();
          }
        }
    Code:
                EntitySpawner.SpawnQueue.Enqueue(new Spawn
                {
                  EntityClassId = classId, // "EntityClassName".GetHashCode();
                  SpawnPos = position,
                  TargetPos = position
                });
    Code:
      class EntitySpawner {
        public static readonly Queue<Spawn> SpawnQueue = new Queue<Spawn>();
        private static long _lastTick;
    
        public void ProcessSpawnQueue()
        {
          // 10,000,000 ticks per second
          if (DateTime.UtcNow.Ticks <= _lastTick + 500000L) { return; }
    
          _lastTick = DateTime.UtcNow.Ticks;
          if (SpawnQueue.Count == 0) { return; }
    
          lock (SpawnQueue)
          {
            var sw = new MicroStopwatch();
            for (; SpawnQueue.Count > 0 && sw.ElapsedTicks < 250000L;)
            {
              try
              {
                //if obey maxspawns use below
                //if (GameStats.GetInt(EnumGameStats.EnemyCount) >= GamePrefs.GetInt(EnumGamePrefs.MaxSpawnedZombies)) return;
    
                var world = GameManager.Instance.World;
                var spawn = SpawnQueue.Dequeue();
                var pos = new Vector3(0,40,0);
    
                  var entity = EntityFactory.CreateEntity(spawn.EntityClassId, pos) as EntityEnemy;
                  if (entity == null) { continue; }
    
                  world.Entities.Add(entity.entityId, entity);
    
                  if (entity.IsEntityAttachedToChunk && !entity.addedToChunk)
                  {
                    var chunk = world.GetChunkFromWorldPos(entity.GetBlockPosition()) as Chunk;
                    chunk?.AddEntityToChunk(entity);
                  }
                  world.audioManager?.EntityAddedToWorld(entity, world);
                  world.entityDistributer.Add(entity);
                  entity.Spawned = true;
                  world.aiDirector.AddEntity(entity);
                  entity.SetInvestigatePosition(new Vector3(spawn.TargetPos.x, spawn.TargetPos.y, spawn.TargetPos.z), 6000);
              }
              catch (Exception e)
              {
                Log.Out($"Error in {GetType().Name}.{MethodBase.GetCurrentMethod().Name}: {e}");
              }
            }
            sw.Stop();
          }
        }
      }
    Last edited by StompyNZ; 4 Weeks Ago at 09:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •