/nick fail

/nick fail

Postby lordmaker1234 » 24 Dec 2013, 15:07

Im trying to make a /nick command where you can only nick people witha lower rank, but I cant get it to work. Can someone find what is wrong with it Please. (This is my 1st command and I kinda suck at this sort of stuff)

Code: Select all
using System;
using MCDzienny_;

namespace MCDzienny
{
    public class Cmdnick : Command
    {
        public override string name { get { return "nicktest"; } }
        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[0] == '#')
            {
                message = message.Remove(0, 1);
                foreach (Player current in Player.players)
                {
                    current.PublicName = message;
                }

                return;
            }

            if (message == "undo")
            {
                foreach (Player current in Player.players)
                {
               string name = current.name;
               if (name.Contains("@"))
               {
                  name = name.Remove(name.IndexOf('@') + 1);
               }
               
                    current.PublicName = name;
                }
           
            return;
            }

            Player who = Player.Find(message.Split(' ')[0]);
            if (who != null)
            {
                who.PublicName = message.Split(' ')[1];
           {
         Player.SendMessage(p, "Player not found.");
            }
        }

          }
            else
            {
         }
         if (who.group.Permission > p.group.Permission)
         {
            Player.SendMessage(p, "You cannot use this command someone ranked higher than you.");
            return;
               
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/nick <player> [name] - Changes <name> name");
        }
    }
lordmaker1234
 
Posts: 9
Joined: 15 Dec 2013, 18:25

Re: /nick fail

Postby HETAL » 24 Dec 2013, 22:16

Your namespace is suppose to be MCDzienny not mcdzienny_
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: /nick fail

Postby lordmaker1234 » 25 Dec 2013, 14:23

HETAL wrote:Your namespace is suppose to be MCDzienny not mcdzienny_


Oh ye i knew about that just after i posted it, but error is:

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

Error #CS1519
Message: Invalid token 'else' in class, struct, or interface member declaration
Line: 53

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

Error #CS1519
Message: Invalid token '>' in class, struct, or interface member declaration
Line: 56

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

Error #CS1519
Message: Invalid token ')' in class, struct, or interface member declaration
Line: 56

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

Error #CS1519
Message: Invalid token '(' in class, struct, or interface member declaration
Line: 58

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

Error #CS1519
Message: Invalid token ',' in class, struct, or interface member declaration
Line: 58


I Am A Noob's Noob At This Sort Of Stuff, So I Dont Know What Any Of That Means
lordmaker1234
 
Posts: 9
Joined: 15 Dec 2013, 18:25

Re: /nick fail

Postby joppiesaus » 25 Dec 2013, 15:36

I think you messed up your brackets.
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: /nick fail

Postby Leeizazombie » 26 Dec 2013, 00:53

There was a good few errors in the code. Here's an error free one I hope, I didn't compile it to test so let me know! <ok>

Code: Select all
using System;
using MCDzienny;

namespace MCDzienny
{
    public class Cmdnick : Command
    {
        public override string name { get { return "nicktest"; } }
        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[0] == '#')
            {
                message = message.Remove(0, 1);
                foreach (Player current in Player.players)
                {
                    current.PublicName = message;
                }

                return;
            }

            if (message == "undo")
            {
                foreach (Player current in Player.players)
                {
                    string name = current.name;
                    if (name.Contains("@"))
                    {
                        name = name.Remove(name.IndexOf('@') + 1);
                    }

                    current.PublicName = name;
                }

                return;
            }

            Player who = Player.Find(message.Split(' ')[0]);
            if (who != null)
            {
                who.PublicName = message.Split(' ')[1];
                {
                    if (who.group.Permission > p.group.Permission)
                    {
                        Player.SendMessage(p, "You cannot use this command someone ranked higher than you.");
                        return;
                    }

                    Player.SendMessage(p, "Player not found.");
                }
            }
        }

        public override void Help(Player p)
        {
            Player.SendMessage(p, "/nick <player> [name] - Changes <name> name");
        }
    }
}
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.

Re: /nick fail

Postby joppiesaus » 26 Dec 2013, 10:58

Ok, I see some errors now...
message[0] is undifined, change it to
if (message.Substring(1))

the second, did you meant this(?):
if (message.Split(' ')[0] == "undo")

Remember that message.Split(' ')[1] is unsafe code, it can cause a IndexOutOfRange exception if you don't provide any spaces.

The brackets after who.PublicName = message.Split(' ')[1]; are useless, remove them.

But the rest is good I think! :D
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: /nick fail

Postby ismellike » 26 Dec 2013, 16:10

message[0] is undifined, change it to
if (message.Substring(1))

message.Substring(1) returns everything that is after position e.g. hello -> llo

message[0] is valid; maybe you should check to make sure that message != "".

if (message.Split(' ')[0] == "undo")

could be used but is not needed since he is not splitting elsewhere after that clause.

Other than that, try what joppie said if you get errors.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /nick fail

Postby lordmaker1234 » 26 Dec 2013, 20:14

Thanks Guys, I Think I Get It Now :lol:
lordmaker1234
 
Posts: 9
Joined: 15 Dec 2013, 18:25

Re: /nick fail

Postby joppiesaus » 26 Dec 2013, 20:46

ismellike wrote:
message[0] is undifined, change it to
if (message.Substring(1))

message.Substring(1) returns everything that is after position e.g. hello -> llo

message[0] is valid; maybe you should check to make sure that message != "".

if (message.Split(' ')[0] == "undo")

could be used but is not needed since he is not splitting elsewhere after that clause.

Other than that, try what joppie said if you get errors.


Yeah... I mixed up the Substring part! :(

And it's not about the
if (message.Split(' ')[0] == "undo")

but the
who.PublicName = message.Split(' ')[1];


Good luck lordmaker1234! <ok>
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 3 guests

cron