/xclientfreeze (Bare with me this time)

/xclientfreeze (Bare with me this time)

Postby leicestercity » 20 Dec 2014, 20:16

OK so I got help and have took my coding further so hopefully it wont be like my horrific code of last time where I guessed at most factors of the code.
OLD CODE!:
Code: Select all
using System;
using System.IO;
using System.Threading;
     
namespace MCDzienny
{
    public class clientfreeze : Command
    {
        public override string name { get { return "clientfreeze"; } }
        public override string shortcut { get { return "cf"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.trusted; } }
        public override void Use(Player p, string message)
        {

        player who = Player.Find(message);
        if (who == null) 
        }
            Player.Sendmessage(p, message + "Player is not online");
           
            Command.all.find("freeze").Use(p, who.name);
            Player.GlobalMessage(p.color + p.publicname " has been frozen please turn off your hacks");

        public override void Help(Player p)
        {
            Player.SendMessage(p, "/clientfreeze or /cf - Freezes the chosen player and tell them to get off their hacks.");
        }
    }
}

Horrific I know the braces usage is horrific.

Now in 7 months of slow learning I feel it's right!
Thanks to AFK_Games helping learn I'm getting better with coding in C# (especially braces XD)

Now heres the new code. Same drill though any error let me know where they are and how to fix them as I am really enjoying my coding at the minute.
NEW AND IMPROVED CODE!:
Code: Select all
using System;

namespace MCDzienny
{
    public class CmdXclientfreeze : Command
    {
        public override string name { get { return "xclientfreeze"; } }
        public override string shortcut { get { return "xcf"; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }

        public bool freeze = false;

        public override void Use(Player p, string message)
        {
            Player who = Player.Find(message);
            if (who == null)
            {
                Player.SendMessage(p, "Player is not online");
                return;
            }
            else
            {
                if (who.group.Permission >= p.group.Permission)
                {
                    Player.SendMessage(p, "Cannot client freeze a player of an equal or higher rank");
                    return;
                }
                else
                {
                    if (freeze == false)
                    {
                         Command.all.Find("freeze").Use(p, who.name);
                    Player.GlobalMessage("Please turn off your client hacks immediatly!");
                    }
                    else
                    {
                        if (freeze == true)
                        {
                            Command.all.Find("freeze").Use(p, who.name);
                        }
                    }
                   
                }

            }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/xclientfreeze - Freezes the player for client hacking ONLY!");
        }
    }
}
LEICESTER TILL I DIE
leicestercity
 
Posts: 33
Joined: 08 Mar 2014, 16:36

Re: /xclientfreeze (Bare with me this time)

Postby Leeizazombie » 21 Dec 2014, 20:23

There's a problem in this code, you're not actually changing the boolean "freeze" when you use the command, to tell wether it's true or not.

You don't even need to use a custom boolean, there's already a boolean to tell you wether a person is frozen or not:

Code: Select all
p.frozen


So for example:

Code: Select all
if (p.frozen == false)
                    {
                         Command.all.Find("freeze").Use(p, who.name);
                         Player.GlobalMessage("Please turn off your client hacks immediatly!");
                    }


or

Code: Select all
if (!p.frozen)
                    {
                         Command.all.Find("freeze").Use(p, who.name);
                         Player.GlobalMessage("Please turn off your client hacks immediatly!");
                    }



Also in your code you put in an "if" statement to see if the boolean is false, even though is supposed to be false because of the "else", everything in that "else" happens because your boolean is false as you already tried to see if it's true.

Hope I helped.

Fixed code:
Spoiler:
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: /xclientfreeze (Bare with me this time)

Postby leicestercity » 21 Dec 2014, 23:41

Thanks Lee I fixed this and I'll edit the code on the post but its fixed on my computer (hard to code on tablet xD) Sorry Lee I didn't see the fixed code but I was able to edit it myself and get it working. Thanks again for the help.
LEICESTER TILL I DIE
leicestercity
 
Posts: 33
Joined: 08 Mar 2014, 16:36

Re: /xclientfreeze (Bare with me this time)

Postby leicestercity » 22 Dec 2014, 11:31

Hmm I tested my command under the code I posted and it compiled and worked.
LEICESTER TILL I DIE
leicestercity
 
Posts: 33
Joined: 08 Mar 2014, 16:36


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 4 guests

cron