How to make a basic command?

How to make a basic command?

Postby peterkap » 03 Aug 2011, 15:06

I want to make a sort of /help thingy command. How do i make a basic command just reading a .txt file?
[BlockCraft] Lava Survival/Zombie Survival
Thatssss A Nissse Everything You Have....
SSSsssss
User avatar
peterkap
 
Posts: 28
Joined: 31 Jul 2011, 00:15

Re: How to make a basic command?

Postby dzienny » 03 Aug 2011, 23:24

Here's a simple example, that you have to adjust to work, but it shouldn't be overly difficult for you. You have to just change the path and the file name.

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 CmdTest : 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 "test"; } }

      // 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 fileContent = File.ReadAllText("filePath/fileName.txt");
                     Player.SendMessage(p, fileContent);
      }

      // This one controls what happens when you use /help [commandname].
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/test - Does stuff.  Example command.");
      }
   }
}
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 7 guests

cron