My first command :D

For all mod-related questions and custom code.
Post Reply
BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

My first command :D

Post by BobKare »

Well, just started modding fCraft, and I'm slowly learning C#!
This is my first command, lol:

Code: Select all

  
        static readonly CommandDescriptor CdBob = new CommandDescriptor
        {
            Name = "Bob",
            Category = CommandCategory.Chat,
            Aliases = new[] { "BobLol" },
            IsConsoleSafe = true,
            NotRepeatable = false,
            DisableLogging = true,
            Permissions = new[] { Permission.Chat },
            Usage = "/Bob",
            Help = "Shows something awesome!",
            Handler = BobHandler
        };

        static void BobHandler( Player player, Command cmd) {

            player.MessageNow("Bob is AWESOME");
        }
It's working^^

User avatar
Hellenion
Offline
Posts: 220
Joined: October 20th, 2011, 9:20 am
Location: Subnet
Contact:

Re: My first command :D

Post by Hellenion »

I laughed.

You should have made "Hello World"... either way, good job on picking up C#!
A = {x ∈ P(U) | x ∉ x}
Mods:
  1. /Su - Allows players to temporarily become a different rank
  2. /Snap - Like /Line but only draws straight or diagonal lines.
  3. pre-0.630 skip/none block

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: My first command :D

Post by fragmer »

I recommend using player.Message() instead of .MessageNow(), unless you know exactly what you're doing ;)

User avatar
Hellenion
Offline
Posts: 220
Joined: October 20th, 2011, 9:20 am
Location: Subnet
Contact:

Re: My first command :D

Post by Hellenion »

Well of course he knows what he's doing, he's a programmer!
A = {x ∈ P(U) | x ∉ x}
Mods:
  1. /Su - Allows players to temporarily become a different rank
  2. /Snap - Like /Line but only draws straight or diagonal lines.
  3. pre-0.630 skip/none block

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: My first command :D

Post by BobKare »

Hellenion wrote:Well of course he knows what he's doing, he's a programmer!
lol
fragmer wrote:I recommend using player.Message() instead of .MessageNow(), unless you know exactly what you're doing ;)
KK. What's the difference?

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: My first command :D

Post by fragmer »

MessageNow sends message directly to the player at once. It uses SendNow:

Code: Select all

/// <summary> Send packet to player (not thread safe, sync, immediate).
/// Should NEVER be used from any thread other than this session's ioThread.
/// Not thread-safe (for performance reason). </summary>
public void SendNow( Packet packet ) {
    if( Thread.CurrentThread != ioThread ) {
        throw new InvalidOperationException( "SendNow may only be called from player's own thread." );
    }
    writer.Write( packet.Data );
    BytesSent += packet.Data.Length;
}
Message puts the message into player's outgoing packet queue. It uses Send:

Code: Select all

/// <summary> Send packet (thread-safe, async, priority queue).
/// This is used for most packets (movement, chat, etc). </summary>
public void Send( Packet packet ) {
    if( canQueue ) priorityOutputQueue.Enqueue( packet );
}

User avatar
Hellenion
Offline
Posts: 220
Joined: October 20th, 2011, 9:20 am
Location: Subnet
Contact:

Re: My first command :D

Post by Hellenion »

The public access modifier is a bug.
A = {x ∈ P(U) | x ∉ x}
Mods:
  1. /Su - Allows players to temporarily become a different rank
  2. /Snap - Like /Line but only draws straight or diagonal lines.
  3. pre-0.630 skip/none block

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: My first command :D

Post by BobKare »

I see, changed.

Thank you fragmer :)

Post Reply