Page 1 of 1

Deleting all mobs

Posted: Mon Mar 14, 2016 4:36 pm
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?

Re: Deleting all mobs

Posted: Mon Mar 14, 2016 4:38 pm
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

Re: Deleting all mobs

Posted: Mon Mar 14, 2016 4:40 pm
by Issen
What about the npcs though? I thought wiping the spawnlist would also remove the npcs

Re: Deleting all mobs

Posted: Mon Mar 14, 2016 5:56 pm
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

Re: Deleting all mobs

Posted: Wed Mar 16, 2016 4:41 pm
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.

Re: Deleting all mobs

Posted: Sat Mar 26, 2016 12:20 am
by Zoey76
The code looks clean.

Re: Deleting all mobs

Posted: Mon Mar 28, 2016 7:52 pm
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);
               

               
                }
 
              
            }
        }