This is a script that is based off of GenVendor.cs. It works fine but it uses default spawners and I would like it to use XMLspawners. My question is how can I change the spawner type this generates?

Code:
using System;
using System.Collections;
using Server.Mobiles;
using Server.Commands;


namespace Server
{
    public class GenGuards
    {
        private static int m_Count;

        //configuration
        private const int NPCCount = 1;//2 npcs per type (so a mage spawner will spawn 2 npcs, a alchemist and herbalist spawner will spawn 4 npcs total)
        private const int HomeRange = 5;//How far should they wander?
        private const bool TotalRespawn = true;//Should we spawn them up right away?
        private static TimeSpan MinTime = TimeSpan.FromMinutes(2.5);//min spawn time
        private static TimeSpan MaxTime = TimeSpan.FromMinutes(10.0);//max spawn time
        private const int Team = 0;//"team" the npcs are on

        public static void Initialize()
        {
            CommandSystem.Register("GenGuards", AccessLevel.Administrator, new CommandEventHandler(Generate_OnCommand));
        }

        [Usage("GenGuards")]
        [Description("Generates Guards/NPC spawners")]
        private static void Generate_OnCommand(CommandEventArgs e)
        {
            Parse(e.Mobile);
        }

        public static void Parse(Mobile from)
        {

            from.SendMessage("Generating All Town Guards & NPCs...");
           
            MakeSpawner(new string[] { "OrderGuard" }, 1400, 1623, 28);//Custom Brit
            MakeSpawner(new string[] { "OrderGuard" }, 1400, 1628, 28);
            MakeSpawner(new string[] { "OrderGuard" }, 1337, 1622, 50);
            MakeSpawner(new string[] { "OrderGuard" }, 1337, 1626, 50);
            MakeSpawner(new string[] { "ChaosGuard" }, 1521, 1457, 15);
            MakeSpawner(new string[] { "ChaosGuard" }, 1525, 1457, 15);
            MakeSpawner(new string[] { "ChaosGuard" }, 1524, 1453, 35);
            MakeSpawner(new string[] { "ChaosGuard" }, 1520, 1445, 15);
            MakeSpawner(new string[] { "WarriorGuard" }, 1409, 1716, 20);
            MakeSpawner(new string[] { "WarriorGuard" }, 1411, 1716, 20);
            MakeSpawner(new string[] { "OrderGuard" }, 1371, 1603, 30);//Lord British Castle
            MakeSpawner(new string[] { "OrderGuard" }, 1342, 1574, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1306, 1659, 52);
            MakeSpawner(new string[] { "WarriorGuard" }, 1315, 1656, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1326, 1681, 52);
            MakeSpawner(new string[] { "OrderGuard" }, 1395, 1684, 52);
            MakeSpawner(new string[] { "OrderGuard" }, 1353, 1647, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1324, 1676, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1325, 1677, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1337, 1672, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1339, 1672, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1341, 1672, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1337, 1672, 50);
            MakeSpawner(new string[] { "OrderGuard" }, 1339, 1672, 50);
            MakeSpawner(new string[] { "OrderGuard" }, 1341, 1672, 50);
            MakeSpawner(new string[] { "WarriorGuard" }, 1431, 1696, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 1434, 1687, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 3732, 2164, 20);//Magencia
            MakeSpawner(new string[] { "WarriorGuard" }, 2506, 554, 0);//Minoc
            MakeSpawner(new string[] { "WarriorGuard" }, 2506, 562, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 4459, 1172, 0);//Moonglow
            MakeSpawner(new string[] { "WarriorGuard" }, 4471, 1164, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 4476, 1145, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 3578, 1309, 0);//nujelm
            MakeSpawner(new string[] { "WarriorGuard" }, 3763, 1323, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 1907, 2687, 0);//Trinsic
            MakeSpawner(new string[] { "WarriorGuard" }, 1895, 2689, 10);
            MakeSpawner(new string[] { "WarriorGuard" }, 2892, 685, 0);//Vesper
            MakeSpawner(new string[] { "WarriorGuard" }, 2878, 683, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 2899, 667, 0);

        }

        private static Queue m_ToDelete = new Queue();

        public static void ClearSpawners(int x, int y, int z)
        {
            IPooledEnumerable eable = Map.Felucca.GetItemsInRange(new Point3D(x, y, z), 0);

            foreach (Item item in eable)
            {
                if (item is Spawner && item.Z == z)
                    m_ToDelete.Enqueue(item);
            }

            eable.Free();

            while (m_ToDelete.Count > 0)
                ((Item)m_ToDelete.Dequeue()).Delete();
        }

        private static void MakeSpawner(string[] types, int x, int y, int z)
        {
            if (types.Length == 0)
                return;

            ClearSpawners(x, y, z);

            for (int i = 0; i < types.Length; ++i)
            {

                Spawner sp = new Spawner(types[i]);

                sp.Count = NPCCount;
                sp.MinDelay = MinTime;
                sp.MaxDelay = MaxTime;
                sp.Team = Team;
                sp.HomeRange = HomeRange;

                sp.MoveToWorld(new Point3D(x, y, z), Map.Felucca);

                if (TotalRespawn)
                {
                    sp.Respawn();
                    sp.BringToHome();
                }

                ++m_Count;
            }
        }
    }
}
 
I couldn't figure out how to make the script convert the spawners but I did figure out how to convert them easily nonetheless. For anybody else that may want to convert their spawners to XML spawners here's the answer.

1) Spawn everything up in your shard that you want to convert to xmlspawners.
2) Use the command "[global exportspawner file.xml" (Name the file.xml whatever you want).
3) Clear the area, facet or shard of all the spawners.
4) Use the command "[xmlimportspawners file.xml" (Replacing the file.xml with whatever you named the file from step 2).
5) Profit! Now all your spawners are XMLSpawners.
 
Last edited:
This is a script that is based off of GenVendor.cs. It works fine but it uses default spawners and I would like it to use XMLspawners. My question is how can I change the spawner type this generates?

Code:
using System;
using System.Collections;
using Server.Mobiles;
using Server.Commands;


namespace Server
{
    public class GenGuards
    {
        private static int m_Count;

        //configuration
        private const int NPCCount = 1;//2 npcs per type (so a mage spawner will spawn 2 npcs, a alchemist and herbalist spawner will spawn 4 npcs total)
        private const int HomeRange = 5;//How far should they wander?
        private const bool TotalRespawn = true;//Should we spawn them up right away?
        private static TimeSpan MinTime = TimeSpan.FromMinutes(2.5);//min spawn time
        private static TimeSpan MaxTime = TimeSpan.FromMinutes(10.0);//max spawn time
        private const int Team = 0;//"team" the npcs are on

        public static void Initialize()
        {
            CommandSystem.Register("GenGuards", AccessLevel.Administrator, new CommandEventHandler(Generate_OnCommand));
        }

        [Usage("GenGuards")]
        [Description("Generates Guards/NPC spawners")]
        private static void Generate_OnCommand(CommandEventArgs e)
        {
            Parse(e.Mobile);
        }

        public static void Parse(Mobile from)
        {

            from.SendMessage("Generating All Town Guards & NPCs...");
  
            MakeSpawner(new string[] { "OrderGuard" }, 1400, 1623, 28);//Custom Brit
            MakeSpawner(new string[] { "OrderGuard" }, 1400, 1628, 28);
            MakeSpawner(new string[] { "OrderGuard" }, 1337, 1622, 50);
            MakeSpawner(new string[] { "OrderGuard" }, 1337, 1626, 50);
            MakeSpawner(new string[] { "ChaosGuard" }, 1521, 1457, 15);
            MakeSpawner(new string[] { "ChaosGuard" }, 1525, 1457, 15);
            MakeSpawner(new string[] { "ChaosGuard" }, 1524, 1453, 35);
            MakeSpawner(new string[] { "ChaosGuard" }, 1520, 1445, 15);
            MakeSpawner(new string[] { "WarriorGuard" }, 1409, 1716, 20);
            MakeSpawner(new string[] { "WarriorGuard" }, 1411, 1716, 20);
            MakeSpawner(new string[] { "OrderGuard" }, 1371, 1603, 30);//Lord British Castle
            MakeSpawner(new string[] { "OrderGuard" }, 1342, 1574, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1306, 1659, 52);
            MakeSpawner(new string[] { "WarriorGuard" }, 1315, 1656, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1326, 1681, 52);
            MakeSpawner(new string[] { "OrderGuard" }, 1395, 1684, 52);
            MakeSpawner(new string[] { "OrderGuard" }, 1353, 1647, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1324, 1676, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1325, 1677, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1337, 1672, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1339, 1672, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1341, 1672, 30);
            MakeSpawner(new string[] { "OrderGuard" }, 1337, 1672, 50);
            MakeSpawner(new string[] { "OrderGuard" }, 1339, 1672, 50);
            MakeSpawner(new string[] { "OrderGuard" }, 1341, 1672, 50);
            MakeSpawner(new string[] { "WarriorGuard" }, 1431, 1696, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 1434, 1687, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 3732, 2164, 20);//Magencia
            MakeSpawner(new string[] { "WarriorGuard" }, 2506, 554, 0);//Minoc
            MakeSpawner(new string[] { "WarriorGuard" }, 2506, 562, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 4459, 1172, 0);//Moonglow
            MakeSpawner(new string[] { "WarriorGuard" }, 4471, 1164, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 4476, 1145, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 3578, 1309, 0);//nujelm
            MakeSpawner(new string[] { "WarriorGuard" }, 3763, 1323, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 1907, 2687, 0);//Trinsic
            MakeSpawner(new string[] { "WarriorGuard" }, 1895, 2689, 10);
            MakeSpawner(new string[] { "WarriorGuard" }, 2892, 685, 0);//Vesper
            MakeSpawner(new string[] { "WarriorGuard" }, 2878, 683, 0);
            MakeSpawner(new string[] { "WarriorGuard" }, 2899, 667, 0);

        }

        private static Queue m_ToDelete = new Queue();

        public static void ClearSpawners(int x, int y, int z)
        {
            IPooledEnumerable eable = Map.Felucca.GetItemsInRange(new Point3D(x, y, z), 0);

            foreach (Item item in eable)
            {
                if (item is Spawner && item.Z == z)
                    m_ToDelete.Enqueue(item);
            }

            eable.Free();

            while (m_ToDelete.Count > 0)
                ((Item)m_ToDelete.Dequeue()).Delete();
        }

        private static void MakeSpawner(string[] types, int x, int y, int z)
        {
            if (types.Length == 0)
                return;

            ClearSpawners(x, y, z);

            for (int i = 0; i < types.Length; ++i)
            {

                Spawner sp = new Spawner(types[i]);

                sp.Count = NPCCount;
                sp.MinDelay = MinTime;
                sp.MaxDelay = MaxTime;
                sp.Team = Team;
                sp.HomeRange = HomeRange;

                sp.MoveToWorld(new Point3D(x, y, z), Map.Felucca);

                if (TotalRespawn)
                {
                    sp.Respawn();
                    sp.BringToHome();
                }

                ++m_Count;
            }
        }
    }
}

I found this old post of mine still unanswered after 2 years so I decided to answer it myself. LOL
This is a much easier way than the workaround I had above.

To convert this to using XMLSpawners you simply change this:
C#:
Spawner sp = new Spawner(types[i]);



                sp.Count = NPCCount;

                sp.MinDelay = MinTime;

                sp.MaxDelay = MaxTime;

                sp.Team = Team;

                sp.HomeRange = HomeRange;



                sp.MoveToWorld(new Point3D(x, y, z), Map.Felucca);

To This:
C#:
XmlSpawner xs = new XmlSpawner(types[i]);

                xs.MaxCount = NPCCount;
                xs.MinDelay = MinTime;
                xs.MaxDelay = MaxTime;
                xs.Team = Team;
                xs.HomeRange = HomeRange;
                xs.SpawnRange = SpawnRange;
                xs.SmartSpawning = SmartSpawning;

                xs.MoveToWorld(new Point3D(x, y, z), Map.Felucca);



I have updated this script to now use XMLSpawner2 instead of default spawners. It's pretty useful to me because I can insert this into my admin console when worldbuilding and I use it as a worldspawner. I have imported spawns into it and have over 15,000 spawners that populate the world and it just keeps growing as I make tweeks to the shard spawn. This is fantastic because I dont have to store any spawner information in the /Data folder. It's literally a drag and drop world spawner solution.

GenMonster.png

GenMonster2.png
As you can see you can configure the XML spawners in just about any way you want its super easy to add any xmlspawner option to the config.

C#:
       //configuration
        private const int NPCCount = 1;//2 npcs per type (so a mage spawner will spawn 2 npcs, a alchemist and herbalist spawner will spawn 4 npcs total)
        private const int HomeRange = 120;//How far should they wander?
        private const int SpawnRange = 20;//What should the spawnrange be?
        private const bool TotalRespawn = true;//Should we spawn them up right away?
        private static TimeSpan MinTime = TimeSpan.FromMinutes(2.5);//min spawn time
        private static TimeSpan MaxTime = TimeSpan.FromMinutes(10.0);//max spawn time
        private const int Team = 0;//"team" the npcs are on
        private const bool SmartSpawning = false;//Should Smartspawn be turned on?

You can use it to spawn anything you can think of that is spawnable:
C#:
            MakeSpawner(new string[] { "Orc" }, 1400, 1623, 28);//Monster
            MakeSpawner(new string[] { "TimberWolf" }, 1400, 1628, 28);//Animal
            MakeSpawner(new string[] { "Banker" }, 1337, 1622, 50);//Vendors
            MakeSpawner(new string[] { "Noble" }, 1337, 1626, 50);//Hireable NPC
            MakeSpawner(new string[] { "BloodMoss" }, 1521, 1457, 15);//Reagents
            MakeSpawner(new string[] { "Turnip" }, 1525, 1457, 15);//Crops
            MakeSpawner(new string[] { "TreasureChestlvl3" }, 1524, 1453, 35);//Treasure
            MakeSpawner(new string[] { "PlatemailChest" }, 1520, 1445, 15);//Items

I know this is just a modified stock uoamVendors.cs but it's been awesome for me.
 
Last edited:
Back