/clearmap

/clearmap

Postby Warren1001 » 11 Jun 2013, 19:24

It compiles perfectly fine, but when I try to use the command, I get a "An error occured when using the command!" message and this error every time I use it:
Code: Select all
Type: IndexOutOfRangeException
Source: Cmdclearmap
Message: Index was outside the bounds of the array.
Target: Use
Trace:    at MCDzienny.CmdClearmap.Use(Player p, String message)
   at MCDzienny.Player.<>c__DisplayClass26.<HandleCommand>b__21()

Code: Select all
using System;
namespace MCDzienny
{
    public class CmdClearmap : Command
    {
        public override string name { get { return "clearmap"; } }
        public override string shortcut { get { return "cm"; } }
        public override string type { get { return "build"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
        public override bool ConsoleAccess { get { return false; } }
      
      public override void Use(Player p, string message)
      {
         string split1 = message.Split(' ')[0];
         string split2 = message.Split(' ')[1];
         
         if (message == "") { Help(p); return; }
         if (split1 == "all")
         {
            Command.all.Find("cuboid").Use(p, "air");
            Command.all.Find("click").Use(p, "0 63 63");
            Command.all.Find("click").Use(p, "63 0 0");
            Player.SendMessage(p, Server.DefaultColor + "Map has been completely cleared.");
         }
         if (split1 == "ground")
         {
            Command.all.Find("cuboid").Use(p, "air");
            Command.all.Find("click").Use(p, "0 63 63");
            Command.all.Find("click").Use(p, "63 1 0");
            Player.SendMessage(p, Server.DefaultColor + "Map has been cleared except for the ground.");
         }
         else
         {
            Command.all.Find("cuboid").Use(p, "air");
            Command.all.Find("click").Use(p, "1 63 62");
            Command.all.Find("click").Use(p, "62 1 1");
            Player.SendMessage(p, Server.DefaultColor + "Map has been cleared except for the ground and walls.");
         }
      }
      public override void Help(Player p)
      {
         Player.SendMessage(p, "Only works for 64x64x64 maps! Shortcut: /cm");
         Player.SendMessage(p, "/clearmap - clears map except for ground and walls.");
         Player.SendMessage(p, "/clearmap all - clears map completely.");
         Player.SendMessage(p, "/clearmap ground - clears map except for ground.");
      }
   }
}
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /clearmap

Postby ismellike » 11 Jun 2013, 19:38

The coordinates on the click may be messed up.

Try the same command in a 128^3 map and then experiment with other coordinates on the 64^3 map.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /clearmap

Postby Warren1001 » 11 Jun 2013, 23:20

It still doesn't work... I can type /click 0 63 63 manually and it works (only in lava). /clearmap doesn't work in lava though.
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /clearmap

Postby Conor » 11 Jun 2013, 23:24

Your error is more than likely coming from this:

Code: Select all
         string split1 = message.Split(' ')[0];
         string split2 = message.Split(' ')[1];


The index was out of bounds - that suggests that you're calling an item of an array which doesn't exist - i.e. message.Split(' ')[1] - there may not be a string at index [1] - or possibly even [0] as the message might not have a space in it, so it cannot be split.

Basically, if you don't put a space in your message, it will derp. You need a try { } catch { } statement or you could also check beforehand to see if there is a space:

Code: Select all
if (message.IndexOf(' ') == -1)
{
   // No space in the message
}
else
{
   // They have a space in the message
}
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /clearmap

Postby HETAL » 11 Jun 2013, 23:27

How exactly is this command suppose to work? Do you have to click something for the command or when you do it it automatically does it
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: /clearmap

Postby Warren1001 » 11 Jun 2013, 23:30

HETAL wrote:How exactly is this command suppose to work? Do you have to click something for the command or when you do it it automatically does it

No, /clearmap would erase the map, depending on what option you put.
Conor wrote:Your error is more than likely coming from this:

Code: Select all
         string split1 = message.Split(' ')[0];
         string split2 = message.Split(' ')[1];


The index was out of bounds - that suggests that you're calling an item of an array which doesn't exist - i.e. message.Split(' ')[1] - there may not be a string at index [1] - or possibly even [0] as the message might not have a space in it, so it cannot be split.

Basically, if you don't put a space in your message, it will derp. You need a try { } catch { } statement or you could also check beforehand to see if there is a space:

Code: Select all
if (message.IndexOf(' ') == -1)
{
   // No space in the message
}
else
{
   // They have a space in the message
}

Ohhh okie ty :3
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /clearmap

Postby Warren1001 » 11 Jun 2013, 23:50

It won't work ._.
Image
Code: Select all
using System;
namespace MCDzienny
{
    public class CmdClearmap : Command
    {
        public override string name { get { return "clearmap"; } }
        public override string shortcut { get { return "cm"; } }
        public override string type { get { return "build"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
        public override bool ConsoleAccess { get { return false; } }
      
      public override void Use(Player p, string message)
      {
         if (message.IndexOf(' ') == -1)
         {
            Command.all.Find("cuboid").Use(p, "air");
            Command.all.Find("click").Use(p, "1 63 62");
            Command.all.Find("click").Use(p, "62 1 1");
            Player.SendMessage(p, Server.DefaultColor + "Map has been cleared except for the ground and walls.");
         }
         else
         {
            string split1 = message.Split(' ')[0];
            string split2 = message.Split(' ')[1];
            
            if (split2 != "") { Help(p); return; }
            if (split1 == "all")
            {
               Command.all.Find("cuboid").Use(p, "air");
               Command.all.Find("click").Use(p, "0 63 63");
               Command.all.Find("click").Use(p, "63 0 0");
               Player.SendMessage(p, Server.DefaultColor + "Map has been completely cleared.");
            }
            if (split1 == "ground")
            {
               Command.all.Find("cuboid").Use(p, "air");
               Command.all.Find("click").Use(p, "0 63 63");
               Command.all.Find("click").Use(p, "63 1 0");
               Player.SendMessage(p, Server.DefaultColor + "Map has been cleared except for the ground.");
            }
         }
      }
      public override void Help(Player p)
      {
         Player.SendMessage(p, "Only works for 64x64x64 maps! Shortcut: /cm");
         Player.SendMessage(p, "/clearmap - clears map except for ground and walls.");
         Player.SendMessage(p, "/clearmap all - clears map completely.");
         Player.SendMessage(p, "/clearmap ground - clears map except for ground.");
      }
   }
}
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /clearmap

Postby Conor » 12 Jun 2013, 00:08

Try a manual approach, you can do the cuboid yourself.

As most blocks are already air, it'll be a faster clearance if you check the block in the loop is air, before setting an air block. So, as an example, to clear the top half of a 128 x 128 x 128 map (above ground), you'd do this:

Code: Select all
ushort bottomX = 0;
ushort bottomY = 65;
ushort bottomZ = 0;

ushort topX = 128;
ushort topY = 128;
ushort topZ = 128;

for (ushort x = bottomX; x <= topX; ++x)
{
   for (ushort y = bottomY; y <= topY; ++y)
   {
       for (ushort z = bottomZ; z <= topZ; ++z)
       {
           if (p.level.GetTile(x, y, z) != Block.air)
           {
               p.level.Blockchange(p, x, y, z, Block.air);
           }
       }
   }
}


Modify the ushort vairables to your needs.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /clearmap

Postby Warren1001 » 12 Jun 2013, 02:24

Conor wrote:Try a manual approach, you can do the cuboid yourself.

As most blocks are already air, it'll be a faster clearance if you check the block in the loop is air, before setting an air block. So, as an example, to clear the top half of a 128 x 128 x 128 map (above ground), you'd do this:

Code: Select all
ushort bottomX = 0;
ushort bottomY = 65;
ushort bottomZ = 0;

ushort topX = 128;
ushort topY = 128;
ushort topZ = 128;

for (ushort x = bottomX; x <= topX; ++x)
{
   for (ushort y = bottomY; y <= topY; ++y)
   {
       for (ushort z = bottomZ; z <= topZ; ++z)
       {
           if (p.level.GetTile(x, y, z) != Block.air)
           {
               p.level.Blockchange(p, x, y, z, Block.air);
           }
       }
   }
}


Modify the ushort vairables to your needs.

Say I wanted to use this to make an adminium wall across the entire x-axis, how would I do that?
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /clearmap

Postby ismellike » 12 Jun 2013, 02:57

Take out the "for(ushort z" part and on the inside of the fors put this
Set ushort z to where the wall will be.
Code: Select all
p.level.Blockchange(p,x,y,z,Block.blackrock);
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Next

Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 7 guests

cron