Deleting all mobs

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Issen
Posts: 11
Joined: Sat Oct 31, 2015 5:27 pm

Deleting all mobs

Post by Issen »

Hello everybody. I started using L2j some months ago (even though I know some Java, this project is really confusing) and today I came across this problem. I want to delete from the spawnlist every single mob & raidboss (not from the instances). I searched the net for hints but every solution I found was for pre-h5 chronicles (i can't find the npc table now :/ ). I really do not want to empty the whole Spawnlist table cause that removes the npcs as well. What can I do?
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Deleting all mobs

Post by UnAfraid »

wipe spawnlist and raidboss_spawnlist database tables and it should do it, the rest are script handled and u gotta go and disable them or delete them
Image
Issen
Posts: 11
Joined: Sat Oct 31, 2015 5:27 pm

Re: Deleting all mobs

Post by Issen »

What about the npcs though? I thought wiping the spawnlist would also remove the npcs
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Deleting all mobs

Post by UnAfraid »

You can use the server to delete them, for example create admin handler that iterates over all spawns and check if its L2Attackable and delete it right away
Image
Issen
Posts: 11
Joined: Sat Oct 31, 2015 5:27 pm

Re: Deleting all mobs

Post by Issen »

I actually found a better way (at least for me) to do this. Since I want to load only my custom mobs, I decided to remove the monsters for good. I wrote a script in c# which deletes every mob in the XMLs. If someone faces the same problem, here's the code:

Code: Select all

 static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
        doc.Load(XMLPath);
    
       XmlNodeList nodes = doc.GetElementsByTagName("npc");
        foreach (XmlNode node in nodes)
        {
            foreach (XmlAttribute attribute in node.Attributes)
            {
               
                if ((attribute.Name == "type") && (attribute.Value == "L2Monster"))
                {
                 
                    node.RemoveAll();
                    break;
                }
            }
        }
      
        doc.Save(XMLPath);
        }
It might not be in Java, but the idea is there.
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7005
Joined: Tue Aug 11, 2009 3:36 am

Re: Deleting all mobs

Post by Zoey76 »

The code looks clean.
Powered by Eclipse 4.30 ๐ŸŒŒ | Eclipse Temurin 21 โ˜• | MariaDB 11.2.2 ๐Ÿ—ƒ๏ธ | L2J Server 2.6.3.0 - High Five ๐Ÿš€

๐Ÿ”— Join our Discord! ๐ŸŽฎ๐Ÿ’ฌ
Issen
Posts: 11
Joined: Sat Oct 31, 2015 5:27 pm

Re: Deleting all mobs

Post by Issen »

Zoey76 wrote:The code looks clean.
Haha well fuck me. I thought removing all attributes would work (since there would be no ID for the gameserver to look for) but it turned out causing errors. This is the new code which works flawlessly and for all XMLs.

Code: Select all

 static void RemoveAllNodes(string fname)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(fname);
            XmlNodeList nodes = doc.GetElementsByTagName("npc");
   
            for (int i = nodes.Count -1; i >= 0; i--)
            {
                XmlNode node = nodes[i];
                foreach (XmlAttribute attribute in node.Attributes)
                {
                    if (attribute.Name == "type" && attribute.Value == "L2Monster")
                    {
                        doc.DocumentElement.RemoveChild(node);
                    }
                }
            }     
   
                doc.Save(fname);
        }
        static void Main(string[] args)
        {
                   String[] fnames = Directory.GetFiles(@"C:\Users\001\Desktop\Npcs");
            foreach (string fname in fnames)
            {

                RemoveAllNodes(fname);
               

               
                }
 
              
            }
        }
Post Reply