/addmap - Zombie Survival Infection Map Applier

/addmap - Zombie Survival Infection Map Applier

Postby Bboy505 » 09 Dec 2014, 03:29

I made this little command for my own personal use to add maps to my zombie survival without all of the manual hassle of making .cfg files and adding the lines of information to maps.txt with all of the data for the map. This will instead, create the .cfg file, add to the maps.txt file all of the information necessary for the map to be added, as written in command form on the server. All that is needed is the command to be compiled and loaded on the server, and the .lvl file for the map you want in the survival in the infection/maps folder.

In order to use this command, you type:
/addmap [mapname] [author] [countdown] [roundtime] [build (true/false)] [pillar (true/false)]

Code: Select all
//AddMap command created by Panda
using System;
using System.IO;

namespace MCDzienny
{
   public class CmdAddmap : Command
   {
      public override string name { get { return "addmap"; } }
      public override string shortcut { get { return "am"; } }
      public override string type { get { return "mod"; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
      public override void Use(Player p, string message)
      {

            string mapname, author, countDown, roundTime, build, pillar;
            mapname = message.Split(' ')[0];
            author = message.Split(' ')[1];
            countDown = message.Split(' ')[2];
            roundTime = message.Split(' ')[3];
            build = message.Split(' ')[4];
            pillar = message.Split(' ')[5];

            int numCountDown = Convert.ToInt16(countDown);
            int numRoundTime = Convert.ToInt16(roundTime);

            //Checking if everything is correctly done
            if (!File.Exists("infection/maps/" + mapname + ".lvl"))
            {
                Player.SendMessage(p, "That map does not exist. Sorry!");
                return;
            }
            else if (author == "")
            {
                Player.SendMessage(p, "You can't have a map without a maker...");
                return;
            }
            else if (numCountDown <= 0)
            {
                Player.SendMessage(p, "You need a countdown that is greater than zero.");
                return;
            }
            else if (numRoundTime <= 0)
            {
                Player.SendMessage(p, "You need a rountime that is greater than zero.");
                return;
            }
            else if (build != "true" && build != "True" && build != "false" && build != "False")
            {
                Player.SendMessage(p, "You entered an invalid parameter for building on the map!");
                return;
            }
            else if (pillar != "true" && pillar != "True" && pillar != "false" && pillar != "False")
            {
                Player.SendMessage(p, "You entered an invalid parameter for pillaring on the map!");
                return;
            }
            else
            {
                //Fixing build perms
                switch (build)
                {
                    case "true":
                    case "True":
                        build = "True";
                        break;
                    case "false":
                    case "False":
                        build = "False";
                        break;
                }

                //Fixing pillaring perms
                switch (pillar)
                {
                    case "true":
                    case "True":
                        pillar = "True";
                        break;
                    case "false":
                    case "False":
                        pillar = "False";
                        break;
                }

                //Creating the file if something broke
                if (!File.Exists("infection/maps.txt"))
                {
                    File.WriteAllText("infection/maps.txt", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + Environment.NewLine + Environment.NewLine);
                    File.AppendAllText("infection/maps.txt", "<!--For help visit http://mcdzienny.cba.pl and go to the Help section.-->" + Environment.NewLine);
                    File.AppendAllText("infection/maps.txt", "<!--Infection map list-->" + Environment.NewLine + Environment.NewLine);
                    File.AppendAllText("infection/maps.txt", "<Map name=\"" + mapname + "\" author=\"" + author + "\" countdown-seconds=\"" + numCountDown + "\" round-time-minutes=\"" + numRoundTime + "\" allow-building=\"" + build + "\" allow-pillaring=\"" + pillar + "\" />" + Environment.NewLine);
                    File.AppendAllText("infection/maps.txt", "</Maps>");

                    //Creating a cfg file
                    if (!File.Exists("infection/maps/" + mapname + ".cfg.txt"))
                    {
                        File.WriteAllText("infection/maps/" + mapname + ".cfg.txt", "<MapSettings>" + Environment.NewLine);
                        File.AppendAllText("infection/maps/" + mapname + ".cfg.txt", "</MapSettings>" + Environment.NewLine);
                    }
                }
                else
                {
                    //Deletes </Maps> because otherwise the map would not be put into the survival
                    string tempFile = Path.GetTempFileName();

                    using (var sr = new StreamReader("infection/maps.txt"))
                    using (var sw = new StreamWriter(tempFile))
                    {
                        string line;

                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line != "</Maps>")
                                sw.WriteLine(line);
                        }
                    }

                    File.Delete("infection/maps.txt");
                    File.Move(tempFile, "infection/maps.txt");
                   
                    File.AppendAllText("infection/maps.txt", "<Map name=\"" + mapname + "\" author=\"" + author + "\" countdown-seconds=\"" + numCountDown + "\" round-time-minutes=\"" + numRoundTime + "\" allow-building=\"" + build + "\" allow-pillaring=\"" + pillar + "\" />" + Environment.NewLine);
                    File.AppendAllText("infection/maps.txt", "</Maps>");

                    //Creating a cfg file
                    if (!File.Exists("infection/maps/" + mapname + ".cfg.txt"))
                    {
                        File.WriteAllText("infection/maps/" + mapname + ".cfg.txt", "<MapSettings>" + Environment.NewLine);
                        File.AppendAllText("infection/maps/" + mapname + ".cfg.txt", "</MapSettings>" + Environment.NewLine);
                    }
                }
            }

            //Impliments the map into the survival
            Command.all.Find("setzombie").Use(null, " reloadmaps");

      }

      public override void Help(Player p)
      {
         Player.SendMessage(p, "/addmap - Adds a map to the zombie survival (automatically loads the map into the survival).");
            Player.SendMessage(p, "/addmap - Only use when the map.lvl is already in the infection/maps folder.");
            Player.SendMessage(p, "/addmap {mapname} {author} {countdown} {roundtime} {build (true/false)} {pillar (true/false)}");
      }
   }
}


Feel free to change the code as you wish, and suggestions/constructive criticism is always welcome.
Enjoy :)
Founder of McClassicHosting
Need to contact me? Visit:
irc.geekshed.net
#mcclassichosting, #Panda
Bboy505
 
Posts: 13
Joined: 24 Jun 2013, 01:24

Re: /addmap - Zombie Survival Infection Map Applier

Postby Minecrafter4ty6 » 15 Dec 2014, 21:27

Could you give an example on how to actually use it?
Minecrafter4ty6
 
Posts: 16
Joined: 16 Dec 2013, 20:37

Re: /addmap - Zombie Survival Infection Map Applier

Postby Leeizazombie » 15 Dec 2014, 21:36

Minecrafter4ty6 wrote:Could you give an example on how to actually use it?

Hello,
If you observe the /help (command) function with this command, it should show you this line:
Code: Select all
/addmap {mapname} {author} {countdown} {roundtime} {build (true/false)} {pillar (true/false)}


So for example, if I wanted to add a map to zombie survival called "MyBuilds" that was put in the "/infection/maps/" folder, just simply use the following input:
Code: Select all
/addmap MyBuilds Minecrafter4ty6 10 5 false false


So that will make you the author of the map, set's the countdown timer to 10 seconds, doesn't allow people to build/break blocks on the map and prevents pillaring.

Hope I've helped.
Last edited by Leeizazombie on 15 Dec 2014, 21:39, edited 1 time in total.
Reason: Just read the code, realised I was saying something very wrong.
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron