Idea Motion Group
လူၾကီးမင္းတြင္ Idea Motion Group မွမွတ္ပံုတင္ျပီးေသာ Member Account ရွိပါက Log In မွ တဆင့္ဝင္ေရာက္ပါ။
New Guest ျဖစ္ပါက Register ျပဳလုပ္၍ဝင္ေရာက္ေပးပို႔ႏိုင္ပါသည္။။
*********Idea Motion Group*********

Join the forum, it's quick and easy

Idea Motion Group
လူၾကီးမင္းတြင္ Idea Motion Group မွမွတ္ပံုတင္ျပီးေသာ Member Account ရွိပါက Log In မွ တဆင့္ဝင္ေရာက္ပါ။
New Guest ျဖစ္ပါက Register ျပဳလုပ္၍ဝင္ေရာက္ေပးပို႔ႏိုင္ပါသည္။။
*********Idea Motion Group*********
Idea Motion Group
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Log in

I forgot my password

Latest topics
» Eternion/Wowwal repack 3.3.5a – TrinityCore
How to Create a Custom Command I_icon_minitimeTue Jan 17, 2017 5:58 am by janpara

» SolidWoW BlizzLike 4.0.6-4.3.0 Repack stable UPDATED
How to Create a Custom Command I_icon_minitimeThu Apr 10, 2014 5:39 pm by ycabrerag

» JZY’s Trinity Blizzlike Repack 3.35a (updated)
How to Create a Custom Command I_icon_minitimeSun Dec 01, 2013 8:38 am by Bottscan

» Hello Everyone Well
How to Create a Custom Command I_icon_minitimeThu Jun 27, 2013 12:56 pm by 

» ညီမေလး ဖတ္ဖို႔
How to Create a Custom Command I_icon_minitimeThu Jun 13, 2013 6:27 am by 

Country Codes

Timer

Total
  • >

/>

Test

How to Create a Custom Command

Go down

How to Create a Custom Command Empty How to Create a Custom Command

Post   Mon Jul 09, 2012 6:45 pm

In this little how-to I will be telling you how to make a custom command! First, there are a few things you need to know:

  • You will be using C#, which is the language MCForge was made in
  • A line starting with // is a comment and is ignored when using the command
  • Any text between a /* and a */ is also a comment
  • Blank lines are ignored, so feel free to delete them to make things easier
  • Use "curvy brackets" ({ }) to separate each part
    (a new pair of CB ("curvy brackets") is needed after every if, else if, and else)
  • Each command segment should be on its own line
    Note: while it is not
    necessary for each segment to be on its own line, doing so makes
    everything MUCH simpler. (Enters are basically counted as spaces in C#,
    if I'm not mistaken.
  • Put a semicolon (;) at the end of each line
  • Make sure that your CBs match up
  • Strings/events are connected with a +
  • If you want to display text, put it in quotes " " (also has to be inside of a segment that allows that)

If that made zero sense, just hang tight.


I.
First off, if you don't have C#, you can get the free express version here: [Only admins are allowed to see this link]
II.
Now that you have C#, open up your console and click the command box
(lower right hand corner). Type in "/cmdcreate [name of the command
you'd like to make]". This will create a .cs with some helpful comments
in it.
This is what is made if you type /cmdcreate test:
/*
Auto-generated command skeleton class.

Use this as a basis for custom commands implemented via the MCForge 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, MCForge is designed for .NET 3.5.
using System;

namespace MCForge
{
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)
{
Player.SendMessage(p, "Hello World!");
}

// This one controls what happens when you use /help [commandname].
public override void Help(Player p)
{
Player.SendMessage(p, "/test - Does stuff. Example command.");
}
}
}
It basically explains everything you need to know, apart from how to actually make the command, which goes into the public override void Use(Player p, string message) section. This is the only place where you will add lines. Be sure to start within the brackets; in other words replace Player.SendMessage(p, "Hello World!"); with your code.
III.
An incomplete list of command events can be found [Only admins are allowed to see this link]

You're almost done!
For now, I'll just walk you through my /bow command; a very simple command.

Here's the full command:

using System;

namespace MCForge
{
public class CmdBow : Command
{
//Created by Sinjai, for use with MCForge only.
public override string name { get { return "bow"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "other"; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public override void Use(Player p, string message)
{
Player who = Player.Find(message);
if (who == null) { Player.SendMessage(p, "Could not find player entered"); return; }
if (who == p) { Player.SendMessage(p, "Sorry, you can't bow to yourself"); return; }
Player.GlobalMessage(p.color + p.name + Server.DefaultColor + " bowed to " + who.color + who.name);
}
public override void Help(Player p)
{
Player.SendMessage(p, "/bow [player] - bow to a player.");
}
}
}
Now to walk you through each part.
using System;

namespace MCForge
{
public class CmdBow : Command
{
That bottom line that says Cmd[name] is the name of the command. That
top part that says "using..." is an assembly reference. All commands
need to be using system at the least. Some strings cannot be used if you
do not have the correct assembly reference. Don't touch the namespace MCForge
//Created by Sinjai, for use with MCForge only.
Basically my signature. (notice the //, marking this as a comment (will also show up green in C#))
public override string name { get { return "bow"; } }
This designates that the command is named bow.
public override string shortcut { get { return ""; } }

The
shortcut for the command would usually go in the quotes, but since this
is a three-letter command name, I just left it blank.




Code:

public override string type { get { return "other"; } }
This places my command in the "other" section of the /help index




Code:

public override bool museumUsable { get { return true; } }
Note the true. This means that people in museum mode can still use the command.




Code:

public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
This makes it so that the default permission for this command is guest, or permission 0.




Code:

public override void Use(Player p, string message)
{
This is where you put your code. Notice the open CB; your whole command
must be within the two CBs that are put there when you use /cmdcreate,
but you can add sub-CBs as needed.




Code:

Player who = Player.Find(message);
This is an important line for commands with a target. It enables you to use who.*




Code:

if (who == null) { Player.SendMessage(p, "Could not find player entered"); return; }
If the target can't be found, tell the player.




Code:

if (who == p) { Player.SendMessage(p, "Sorry, you can't bow to yourself"); return; }
If the target is the command user, tell them so.




Code:

Player.GlobalMessage(p.color + p.name + Server.DefaultColor + " bowed to " + who.color + who.name);
Lastly, this is what will happen if the target isn't yourself and they
are online. In this case, it basically just displays text. CommandUser
bowed to Target. It uses the name colors for both the command user and
the target, and uses the server's default command color for the "bowed
to".




Code:

}
Close the void...




Code:

public override void Help(Player p)
{
You generally don't want anything in here except the Player.SendMessage(p, cmdname - what it does);




Code:

Player.SendMessage(p, "/bow [player] - bow to a player.");
What will be sent to a player that uses /help bow




Code:

}
Close the help void...




Code:

}
}
Close the public class CmdBow : Command void and the namespace MCForge void.





IV.

Spoiler



Hopefully you've taken the time to actually read the whole post.
If something wasn't clear or if I made a mistake, let me know! I'll fix it!
If you have command troubles feel free to PM me and I'll see what I can do.
If you'd like another command explained, I can most likely do it, so never be afraid to ask.


Join date : 1970-01-01

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum