/addmap - Zombie Survival Infection Map Applier
Posted: 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)]
Feel free to change the code as you wish, and suggestions/constructive criticism is always welcome.
Enjoy
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