Help for new command

Help for new command

Postby Alshima » 17 Jun 2013, 03:52

So while I was making a command that I think was removed from MCDzienny, which was /op; I ran into a compiler error. Here are the errors:

Code: Select all
-------------------------

Error #CS1010
Message: Newline in constant
Line: 28

-------------------------

Error #CS1012
Message: Too many characters in character literal
Line: 28


Here is the command, I think I really screwed up here. :oops:

Code: Select all
//Made by Alshima
//Based on the creepypasta2 command
using System;
using System.Threading;
using System.IO;

namespace MCDzienny
{
   public class Cmdmakeop : Command
   {
      public override string name { get { return "makeop"; } }
      public override string shortcut { get { return ""; } }
      public override string type { get { return "other"; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }

      public override void Use(Player p, string message)
      {
         if (message != "")
         {
            Help(p);
            return;
         }
         else
         {
            //You can change the rank to a different rank
            Command.all.Find("setrank").Use(null, "operator");
            Player.GlobalMessage("who.color + who.PublicName + Server.DefaultColor + "'s rank was set to %4operator");
            Player.GlobalMessage("%6Congratulations!");
         Player.SendMessage(p, "%fYou are now ranked founder, type /help for your new set of commands.");
         }
      }
   
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/makeop [player] - turns a player into a %4operator");
      }
   }
}


Thanks. :D
Alshima
 
Posts: 160
Joined: 11 Mar 2013, 02:22
Location: Alshima Island

Re: Help for new command

Postby dryfly21 » 17 Jun 2013, 04:02

here you go fixed. if you wanan know the problems you can ask ;)

Code: Select all
//Made by Alshima
//Based on the creepypasta2 command
using System;

namespace MCDzienny
{
   public class CmdMakeop : Command
   {
      public override string name { get { return "makeop"; } }
      public override string shortcut { get { return ""; } }
      public override string type { get { return "other"; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }

      public override void Use(Player p, string message)
      {
         if (message != "") { Help(p); return; }
         Player who = Player.Find(message);

         //You can change the rank to a different rank
         Command.all.Find("setrank").Use(p, "operator");
         Player.GlobalMessage(who.color + who.name + Server.DefaultColor + "'s rank was set to

%4operator");
         Player.GlobalMessage(who.name + "%6Congratulations!");
         Player.SendMessage(p, "%fYou are now ranked founder, type /help for your new set of

commands.");
      }
   
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/makeop [player] - turns a player into a %4operator");
      }
   }
}
dryfly21
 
Posts: 135
Joined: 07 Apr 2012, 03:27

Re: Help for new command

Postby Alshima » 17 Jun 2013, 04:07

dryfly21 wrote:here you go fixed. if you wanan know the problems you can ask ;)

Code: Select all
//Made by Alshima
//Based on the creepypasta2 command
using System;

namespace MCDzienny
{
   public class CmdMakeop : Command
   {
      public override string name { get { return "makeop"; } }
      public override string shortcut { get { return ""; } }
      public override string type { get { return "other"; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }

      public override void Use(Player p, string message)
      {
         if (message != "") { Help(p); return; }
         Player who = Player.Find(message);

         //You can change the rank to a different rank
         Command.all.Find("setrank").Use(p, "operator");
         Player.GlobalMessage(who.color + who.name + Server.DefaultColor + "'s rank was set to

%4operator");
         Player.GlobalMessage(who.name + "%6Congratulations!");
         Player.SendMessage(p, "%fYou are now ranked founder, type /help for your new set of

commands.");
      }
   
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/makeop [player] - turns a player into a %4operator");
      }
   }
}


Sure, I'd like to know the problems please, anyways thanks for the help :D
Alshima
 
Posts: 160
Joined: 11 Mar 2013, 02:22
Location: Alshima Island

Re: Help for new command

Postby Alshima » 17 Jun 2013, 04:13

dryfly21 wrote:here you go fixed. if you wanan know the problems you can ask ;)

Code: Select all
//Made by Alshima
//Based on the creepypasta2 command
using System;

namespace MCDzienny
{
   public class CmdMakeop : Command
   {
      public override string name { get { return "makeop"; } }
      public override string shortcut { get { return ""; } }
      public override string type { get { return "other"; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }

      public override void Use(Player p, string message)
      {
         if (message != "") { Help(p); return; }
         Player who = Player.Find(message);

         //You can change the rank to a different rank
         Command.all.Find("setrank").Use(p, "operator");
         Player.GlobalMessage(who.color + who.name + Server.DefaultColor + "'s rank was set to

%4operator");
         Player.GlobalMessage(who.name + "%6Congratulations!");
         Player.SendMessage(p, "%fYou are now ranked founder, type /help for your new set of

commands.");
      }
   
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/makeop [player] - turns a player into a %4operator");
      }
   }
}


:shock: Nvm I had another compiler error with the fixed command.

Code: Select all
-------------------------

Error #CS1010
Message: Newline in constant
Line: 23

-------------------------

Error #CS1010
Message: Newline in constant
Line: 25
Alshima
 
Posts: 160
Joined: 11 Mar 2013, 02:22
Location: Alshima Island

Re: Help for new command

Postby dryfly21 » 17 Jun 2013, 04:15

firstly you needed
Code: Select all
Player who = Player.Find(message);
nextly you had a " infront of who.color
Code: Select all
Player.GlobalMessage("who.color + who.name + Server.DefaultColor + "'s rank was set to %4operator");

you also should do who.name instead of who.PublicName
dryfly21
 
Posts: 135
Joined: 07 Apr 2012, 03:27

Re: Help for new command

Postby Alshima » 17 Jun 2013, 04:23

dryfly21 wrote:firstly you needed
Code: Select all
Player who = Player.Find(message);
nextly you had a " infront of who.color
Code: Select all
Player.GlobalMessage("who.color + who.name + Server.DefaultColor + "'s rank was set to %4operator");

you also should do who.name instead of who.PublicName


I still have compiler errors
Alshima
 
Posts: 160
Joined: 11 Mar 2013, 02:22
Location: Alshima Island

Re: Help for new command

Postby dryfly21 » 17 Jun 2013, 04:32

there seem to be allot of spaces in it just delete the spaces you might have to enlarge the file your using to edit the code to see that there is extra space. it should compile after
dryfly21
 
Posts: 135
Joined: 07 Apr 2012, 03:27

Re: Help for new command

Postby Conor » 17 Jun 2013, 18:39

dryfly21 wrote:you also should do who.name instead of who.PublicName


who.PublicName is a more recent variable which allows better functionality with players with a long email name, you should actually use this one.

With respect to the command, there are a few things you could fix up, I'll outline them below.

You do not need speech marks around of who.color as it is actually a variable. Speech marks are only needed to put in direct text.

I think you are also using the setrank command incorrectly, the command is /setrank [player] [rank]. I don't think you can directly set your own rank just with /setrank [rank] but I haven't checked, so I could be wrong on that.

Your errors are due to the lines you've made randomly between the code, keep the code on one line, sometimes it is acceptable to break to the next line, but if you leave a line empty, you will stumble upon this error.

Also, you don't need to tell everybody that you changed the rank of the player, as the setrank command you're using already does this. Your 'use' method could look something like this:

Code: Select all
public override void Use(Player p, string message)
{
   // If the message is empty or contains a space, Help(p);
   if (String.IsNullOrEmpty(message) || message.IndexOf(' ') != -1)
   {
       Help(p);
       return;
   }

   // Find the player
   Player who = Player.Find(message);
   
   // If they are hidden or offline, tell the player.
   if (who == null || who.hidden)
   {
       Player.SendMessage(p, "Player could not be found.");
       return;
   }

   // Don't allow them to use the command on players of greater or equal rank
   if (who.group.Permission >= p.group.Permission)
   {
       Player.SendMessage(p, "Cannot use command on players of greater or equal rank.");
       return;
   }
   
   // Set their rank to the operator rank
   Command.all.Find("setrank").Use(p, who.PublicName + " " + Group.findPerm(LevelPermission.Operator).name);
}


Hopefully that is okay, and you can understand it a little more.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 6 guests

cron