It is currently October 15th, 2018, 9:31 am


All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: My first command :D
PostPosted: January 3rd, 2012, 7:03 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
Well, just started modding fCraft, and I'm slowly learning C#!
This is my first command, lol:
Code:
 
        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^^


Top
Offline Profile  
Reply with quote  
 Post subject: Re: My first command :D
PostPosted: January 3rd, 2012, 7:25 pm 
User avatar

Joined: October 20th, 2011, 9:20 am
Posts: 220
Location: Subnet
I laughed.

You should have made "Hello World"... either way, good job on picking up C#!

_________________
A = {x ∈ P(U) | x ∉ x}

Show
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: My first command :D
PostPosted: January 3rd, 2012, 7:26 pm 
fCraft Developer
User avatar

Joined: May 21st, 2011, 10:53 pm
Posts: 1386
I recommend using player.Message() instead of .MessageNow(), unless you know exactly what you're doing ;)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: My first command :D
PostPosted: January 3rd, 2012, 7:27 pm 
User avatar

Joined: October 20th, 2011, 9:20 am
Posts: 220
Location: Subnet
Well of course he knows what he's doing, he's a programmer!

_________________
A = {x ∈ P(U) | x ∉ x}

Show
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: My first command :D
PostPosted: January 3rd, 2012, 7:45 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
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?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: My first command :D
PostPosted: January 3rd, 2012, 10:37 pm 
fCraft Developer
User avatar

Joined: May 21st, 2011, 10:53 pm
Posts: 1386
MessageNow sends message directly to the player at once. It uses SendNow:
Code:
/// <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:
/// <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 );
}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: My first command :D
PostPosted: January 3rd, 2012, 10:57 pm 
User avatar

Joined: October 20th, 2011, 9:20 am
Posts: 220
Location: Subnet
The public access modifier is a bug.

_________________
A = {x ∈ P(U) | x ∉ x}

Show
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: My first command :D
PostPosted: January 4th, 2012, 1:52 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
I see, changed.

Thank you fragmer :)


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net