help with my version on /bye

help with my version on /bye

Postby dryfly21 » 17 Jun 2013, 19:57

first i'd like to get somethings clear. everything compiled fine and it all works till you put a username that doesnt exist. it stems from
Code: Select all
if (who.hidden || who == null)
so i got rid of it and just did
Code: Select all
if (who == null)
this seemed to fix my error and everything worked perfect but i would like to be able to have the who.hidden in it


here is a version with just "if (who == null)" and the one that works 100%
Code: Select all
/*
   (c) by GurkE
       moddified by dryfly21
*/
using System;
using System.Threading;

namespace MCDzienny
{
    public class CmdBye : Command
    {
        public override string name { get { return "bye"; } }
        public override string shortcut { get { return "bb"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
        //public CmdBye() { }

        public override void Use(Player p, string message)
        {
            if (String.IsNullOrEmpty(message) || message.IndexOf(' ') != -1)
            {
              Player.GlobalMessage(p.color + p.PublicName + Server.DefaultColor + ": goodbye all!");
              Thread.Sleep(3000);
              p.Kick("You said goodbye to your friends and left");
              return;
            }
            Player who = Player.Find(message);

            if (who == null)
            {
               Player.SendMessage(p, p.color + p.PublicName + Server.DefaultColor + ": sorry we couldn't find the player for you!");
               return;             
            }
            if (who == p)
            {
               Player.SendMessage(p, p.color + p.PublicName + Server.DefaultColor + ": sorry you have no friends :(");
               return;
            }
            Player.GlobalMessage(p.color + p.PublicName + Server.DefaultColor + " said bye to " + who.color + who.PublicName + Server.DefaultColor + "!");
            Thread.Sleep(1000);
            Player.GlobalMessage(p.color + p.PublicName + Server.DefaultColor + ": bai bai!");
            Thread.Sleep(2000);
            p.Kick("You said goodbye to your friends and left");
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/bye - says goodbye and kicks you.");
            Player.SendMessage(p, "/bye [Player] - says good bye to player.");
        }
    }
}


here is the version that didnt work with "if (who.hidden || who == null)"

Code: Select all
/*
   (c) by GurkE
       moddified by dryfly21
*/
using System;
using System.Threading;

namespace MCDzienny
{
    public class CmdBye : Command
    {
        public override string name { get { return "bye"; } }
        public override string shortcut { get { return "bb"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
        //public CmdBye() { }

        public override void Use(Player p, string message)
        {
            if (String.IsNullOrEmpty(message) || message.IndexOf(' ') != -1)
            {
              Player.GlobalMessage(p.color + p.PublicName + Server.DefaultColor + ": goodbye all!");
              Thread.Sleep(3000);
              p.Kick("You said goodbye to your friends and left");
              return;
            }
            Player who = Player.Find(message);

            if (who.hidden || who == null)
            {
               Player.SendMessage(p, p.color + p.PublicName + Server.DefaultColor + ": sorry we couldn't find the player for you!");
               return;             
            }
            if (who == p)
            {
               Player.SendMessage(p, p.color + p.PublicName + Server.DefaultColor + ": sorry you have no friends :(");
               return;
            }
            Player.GlobalMessage(p.color + p.PublicName + Server.DefaultColor + " said bye to " + who.color + who.PublicName + Server.DefaultColor + "!");
            Thread.Sleep(1000);
            Player.GlobalMessage(p.color + p.PublicName + Server.DefaultColor + ": bai bai!");
            Thread.Sleep(2000);
            p.Kick("You said goodbye to your friends and left");
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/bye - says goodbye and kicks you.");
            Player.SendMessage(p, "/bye [Player] - says good bye to player.");
        }
    }
}
dryfly21
 
Posts: 135
Joined: 07 Apr 2012, 03:27

Re: help with my version on /bye

Postby ismellike » 17 Jun 2013, 20:19

who.hidden suggests that the player is already online.
The computer would be looking for the stats of a player at the same time it is checking if the player is even online.
Just make sure it checks for hide after it checks for online status.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: help with my version on /bye

Postby dryfly21 » 17 Jun 2013, 20:49

thank you! works perfectly! here is a working and finished version of /bye :D modified by me

Code: Select all
/*
   (c) by GurkE
       moddified by dryfly21
*/
using System;
using System.Threading;

namespace MCDzienny
{
    public class CmdBye : Command
    {
        public override string name { get { return "bye"; } }
        public override string shortcut { get { return "bb"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

        public override void Use(Player p, string message)
        {
            if (String.IsNullOrEmpty(message) || message.IndexOf(' ') != -1)
            {
              Player.GlobalMessage(p.color + "[" + p.title + "]" + p.PublicName + ":" + Server.DefaultColor + " goodbye all!");
              Thread.Sleep(3000);
              p.Kick("Has said goodbye to their friends and left");
              return;
            }
            Player who = Player.Find(message);

            if (who == null || who.hidden)
            {
               Player.SendMessage(p, p.color + "[" + p.title + "]" + p.PublicName + ":" + Server.DefaultColor + " sorry we couldn't find the player for you!");
               return;             
            }
            if (who == p)
            {
               Player.SendMessage(p, p.color + "[" + p.title + "]" + p.PublicName + ":" + Server.DefaultColor + " sorry you have no friends :(");
               return;
            }
            Player.GlobalMessage(p.color + "[" + p.title + "]" + p.PublicName + Server.DefaultColor + " said bye to " + who.color + "[" + who.title + "]" +

who.PublicName + Server.DefaultColor + "!");
            Thread.Sleep(1000);
            Player.GlobalMessage(p.color + "[" + p.title + "]" + p.PublicName + ":" + Server.DefaultColor + " bai bai!");
            Thread.Sleep(2000);
            p.Kick("Has said goodbye to their friends and left");
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/bye - says goodbye and kicks you.");
            Player.SendMessage(p, "/bye [Player] - says good bye to player.");
        }
    }
}
dryfly21
 
Posts: 135
Joined: 07 Apr 2012, 03:27


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 5 guests

cron