adder lava maps

adder lava maps

Postby qpqpqp123 » 07 Jul 2013, 12:19

that code need add lava map
he compile him but when I type /addlava he give me error

Code: Select all
/*
   Auto-generated command skeleton class.

   Use this as a basis for custom commands implemented via the MCDzienny scripting framework.
   File and class should be named a specific way.  For example, /update is named 'CmdUpdate.cs' for the file, and 'CmdUpdate' for the class.
*/

// Add any other using statements you need up here, of course.
// As a note, MCDzienny is designed for .NET 3.5.
using System;
using System.IO;
namespace MCDzienny
{
    public class CmdAddlava : Command
    {
        // The command's name, in all lowercase.  What you'll be putting behind the slash when using it.
        public override string name { get { return "addlava"; } }

        // Command's shortcut (please take care not to use an existing one, or you may have issues.
        public override string shortcut { get { return ""; } }

        // Determines which submenu the command displays in under /help.
        public override string type { get { return "other"; } }

        // Determines whether or not this command can be used in a museum.  Block/map altering commands should be made false to avoid errors.
        public override bool museumUsable { get { return false; } }

        // Determines the command's default rank.  Valid values are:
        // LevelPermission.Nobody, LevelPermission.Banned, LevelPermission.Guest
        // LevelPermission.Builder, LevelPermission.AdvBuilder, LevelPermission.Operator, LevelPermission.Admin
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

        // This is where the magic happens, naturally.
        // p is the player object for the player executing the command.  message is everything after the command invocation itself.
        public override void Use(Player p, string message)
        {
            string a = System.IO.Directory.GetCurrentDirectory();
            Player.SendMessage(p, a + ":" + p.level.name);
            //copy
            string[] lines= new string[int.MaxValue];
            System.IO.StreamReader file =
   new System.IO.StreamReader(a + @"\lava\maps.txt");
            string line;
            int count = 0;
            while ((line = file.ReadLine()) != null)
            {
               
                lines[count] = line;
                count++;
               
            }
            Array.Resize(ref lines, count);
            File.WriteAllLines(a + @"\lava\maps.txt", lines);
           
            copy(a + @"\lava\maps", a + @"\levels", p.level.name + ".cfg.txt");
            copy(a + @"\lava\maps", a + @"\levels", p.level.name + ".lvl");
            using (var writer = File.AppendText(a + @"\lava\maps.txt"))
            {

                writer.WriteLine( "<Map name=" + @"""" + p.level.name + @"""" + " phase1=" + @"""" + 0 + @"""" + " phase2=" + @"""" + "0" + @"""" + " author=" + @""""+p.name + @"""" + ">" );
                writer.WriteLine("<Source block=" + @"""" + " ahl" + @"""" + " x=" + @"""" + "39" + @"""" + " y=" + @"""" + "62" + @"""" + " z=" + @"""" + "39" + @"""" + " type=" + @"""" + " delay=" + @"""" + "0" + @"""" + " /> ");
                writer.WriteLine("</Map>");
                writer.WriteLine("</Maps>");
            }
        }


        public static void copy(string targetPath, string sourcePath, string fileName)
        {


            // Use Path class to manipulate file and directory paths.
            string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
            string destFile = System.IO.Path.Combine(targetPath, fileName);

            // To copy a folder's contents to a new location:
            // Create a new target folder, if necessary.
            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

            // To copy a file to another location and 
            // overwrite the destination file if it already exists.
            System.IO.File.Copy(sourceFile, destFile, true);

            // To copy all the files in one directory to another directory.
            // Get the files in the source folder. (To recursively iterate through
            // all subfolders under the current directory, see
            // "How to: Iterate Through a Directory Tree.")
            // Note: Check for target path was performed previously
            //       in this code example.
            if (System.IO.Directory.Exists(sourcePath))
            {
                string[] files = System.IO.Directory.GetFiles(sourcePath);

                // Copy the files and overwrite destination files if they already exist.
                foreach (string s in files)
                {
                    // Use static Path methods to extract only the file name from the path.
                    fileName = System.IO.Path.GetFileName(s);
                    destFile = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(s, destFile, true);
                }
            }
        }
        // This one controls what happens when you use /help [commandname].
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/addlava - Does stuff.  Example command.");
        }
    }
}
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: adder lava maps

Postby qpqpqp123 » 07 Jul 2013, 12:23

that the errror

----07-07-2013 Sunday 14:22:57 ----
Type: OutOfMemoryException
Source: Cmdaddlava
Message: Exception of type 'System.OutOfMemoryException' was thrown.
Target: Use
Trace: at MCDzienny.CmdAddlava.Use(Player p, String message)
at MCDzienny.Player.<>c__DisplayClass26.<HandleCommand>b__21()
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: adder lava maps

Postby ismellike » 07 Jul 2013, 16:51

I'm guessing there was an infinite loop somewhere.
If you want you can use my /add command instead.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 5 guests