I made my first command :P

I made my first command :P

Postby Leeizazombie » 08 Jul 2013, 07:17

Haha so I'm starting to code, and here is my first try:

Code: Select all

using System;

namespace MCDzienny
{
   public class Cmdsecretcode : 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 "scode"; } }

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

      // 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 true; } }

      // 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)
        {
            if ((message == "code")) { Player.GlobalMessage("&aSuccess"); }
            else
            {
                Player.GlobalMessage("&cFailed");
            }
        }
   

      // This one controls what happens when you use /help [commandname].
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/secretcode - test command.  Example command.");
      }
   }
}


I wana be able to give an award and that the person can only use the command once, but I have no idea.
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: I made my first command :P

Postby joppiesaus » 09 Jul 2013, 13:45

Congratsioulations on your first command! And on your first code, more importantly.
try this:
Code: Select all
       
public override void Use(Player p, string message)
        {
            if (message == "code" && p.ExtraData["CODED!"] != 1)
            {
                Player.GlobalMessage("&aSuccess");
                p.ExtraData.Add("CODED!",1)
            }
            else
            {
                Player.GlobalMessage("&cFailed");
                return;
            }
        }
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: I made my first command :P

Postby Leeizazombie » 09 Jul 2013, 14:41

Thanks :P can you explain how diffrent that is?
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: I made my first command :P

Postby joppiesaus » 10 Jul 2013, 17:00

Leeizazombie wrote:Thanks :P can you explain how diffrent that is?


That will add extra data to the player, called CODED!
if the message is displayed, it will set it to one.
the != will return true if it is NOT the number.

so: message displayed --> CODED! set to one --> if you do it again the if snippet will say false --> return.
Clear? :)
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: I made my first command :P

Postby Leeizazombie » 13 Jul 2013, 09:50

Now I get it :D that will be perfect for if I put in a reward so it can't be done over again, I might also have the code change the secret, but i don't know about csharp and if it can choose a random string from a list
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.


Return to General Chat

Who is online

Users browsing this forum: No registered users and 7 guests

cron