/clientfreeze

/clientfreeze

Postby leicestercity » 09 Apr 2014, 20:14

Ok i know im a terrible coder and i have taken dziennys advice but am still at the very basics but i thourght i could try it and the worst that can happen is i get it wrong. Ok so its supposed to freeze them and send a message out saying to turn off your hacks. Heres the code tell me if its wrong and if you know tell me what went wrong (i did this on notepad as im still getting used to c#).

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.");
        }
    }
}
LEICESTER TILL I DIE
leicestercity
 
Posts: 33
Joined: 08 Mar 2014, 16:36

Re: /clientfreeze

Postby HETAL » 09 Apr 2014, 20:18

Your "{" & "}" are off, I would help you right now but I'm off for a few days.
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: /clientfreeze

Postby Leeizazombie » 09 Apr 2014, 23:55

You've made a few errors such as not using the right caps, I've corrected the code so if you look at it you can compare with the mistakes, also if you are posting this as a command to ask for help with, please post it in "Help in Coding" in future reference. :)

Note: You cannot use custom ranks like LevelPermission.trusted;
You have to use one of the following: Banned, Guest, Builder, AdvBuilder, Operator, Admin, Nobody.
In your case I chose AdvBuilder which has a permission value of 50, should be close to Trusted permissions, but you can always set the permission to a custom rank in-game.

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.AdvBuilder; } }
        public override void Use(Player p, string message)
        {

            Player who = Player.Find(message);
            if (who == null)
            {
                Player.SendMessage(p, message + "Player is not online");
                return;
            }
            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.");
        }
    }
}
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: /clientfreeze

Postby joppiesaus » 10 Apr 2014, 16:03

Learn how to use the brackets!
Instead of a ";" you make use of the brackets at the following keywords:
Code: Select all
if
else
while
for
foreach
void
namespace
class
struct
... and many more ...


Do this!
Code: Select all
if (who == null)
{ // Start bracktet
   Player.SendMessage(p, message + "Player is not online");
   return;
} // End bracket

put between these brackets code!

Not this!
Code: Select all
if (who == null) } {
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: /clientfreeze

Postby Bboy505 » 14 Apr 2014, 01:25

Here is the fix to Lee's fixes:

Code: Select all
using System;

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.AdvBuilder; } }
        public override void Use(Player p, string message)
        {

            Player who = Player.Find(message);
            if (who == null)
            {
                Player.SendMessage(p, message + "Player is not online");
                return;
            }
            else
            {
                Command.all.Find("freeze").Use(p, who.name);
                Player.GlobalMessage(who.color + who.name + Server.DefaultColor + " 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.");
            Player.SendMessage(p, "/clientfreeze {player}");
        }
    }
}
Founder of McClassicHosting
Need to contact me? Visit:
irc.geekshed.net
#mcclassichosting, #Panda
Bboy505
 
Posts: 13
Joined: 24 Jun 2013, 01:24

Re: /clientfreeze

Postby Leeizazombie » 14 Apr 2014, 11:15

Bboy505 wrote:Here is the fix to Lee's fixes:

Code: Select all
using System;

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.AdvBuilder; } }
        public override void Use(Player p, string message)
        {

            Player who = Player.Find(message);
            if (who == null)
            {
                Player.SendMessage(p, message + "Player is not online");
                return;
            }
            else
            {
                Command.all.Find("freeze").Use(p, who.name);
                Player.GlobalMessage(who.color + who.name + Server.DefaultColor + " 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.");
            Player.SendMessage(p, "/clientfreeze {player}");
        }
    }
}


It's not necessary to have the else statement when I have the code return if the player is not online, so your code makes no difference.
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: /clientfreeze

Postby Bboy505 » 14 Apr 2014, 19:25

Code: Select all
Player.GlobalMessage(p.color + p.PublicName + " has been frozen please turn off your hacks");


^ This needed to be changed from p.color + p.PublicName to who.color + who.name
Founder of McClassicHosting
Need to contact me? Visit:
irc.geekshed.net
#mcclassichosting, #Panda
Bboy505
 
Posts: 13
Joined: 24 Jun 2013, 01:24

Re: /clientfreeze

Postby dzienny » 15 Apr 2014, 12:51

Bboy505 wrote:
Code: Select all
Player.GlobalMessage(p.color + p.PublicName + " has been frozen please turn off your hacks");


^ This needed to be changed from p.color + p.PublicName to who.color + who.name


I strongly recommend to use Player.PublicName whenever the name is meant to be displayed. Player.name is supposed to be used internally only, for example when performing a search. LeeIzaZombie did correctly by using Player.PublicName in this case.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: /clientfreeze

Postby Leeizazombie » 15 Apr 2014, 13:00

I was only correcting the mistakes the would throw and error, but it seems that, that part of the command is directing it to "who" so it should be who.color + who.PublicName
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: /clientfreeze

Postby dzienny » 15 Apr 2014, 13:24

Leeizazombie wrote:I was only correcting the mistakes the would throw and error, but it seems that, that part of the command is directing it to "who" so it should be who.color + who.PublicName

I focused on 'PublicName' and I didn't notice the p/who change. Good catch Bboy505 <ok>
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Next

Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 2 guests

cron