/punish

/punish

Postby leicestercity » 03 Apr 2014, 17:54

Ok so im not sure if its been done before. It punishes a player for their next punishment. It should warn them three times, then kick them twice and tempban them three times for 1hr and then ban them. This i have worked on for 24days im slow at coding im sure theres loads of mistakes on it so i posted it here to find them out if you spot any please tell me and i can hopefully get it working. So you just type /punish (playername) and it does the punishment for you. Heres the code.

Code: Select all
using System;
using System.IO;
using System.Threading;
     
namespace MCDzienny
{
    public class punish : Command
    {
        public override string name { get { return "punish"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
        public override void Use(Player p, string message)
        {
            Player.Sendmessage("Who do you want to punish?" );
            return;
        }
        player who = Player.Find(message) ;
        if (who == null)
        {
            Player.SendMessage(p, message + " is not online.");
       
            Command.three.find("warn").Use(p, who.name);
            Player.sendmessage (who, "You have been warned read /rules");
            Command.two.find("kick").Use(p, who.name);
            player.sendmessage (who, "You have been kick read /rules when you rejoin");
            Command.three.find("tempban" "60");
            player.sendmessage (who, "You are tempbanned for 60minutes tempbanned read /rules next time you join");
            Command.one.find("ban").Use(p, who.name);
            player.sendmessage (who, "You have been banned get unbanned at the forums!");
            Command.one.find("banip")
            player.sendmessage (who, "You have been ipbanned please dont connect on any other accounts"
        public override void Help(Player p)
        { 
            Player.SendMessage(p, "/punish - Punishes the player for their next punishment.
        }
    }
}
LEICESTER TILL I DIE
leicestercity
 
Posts: 33
Joined: 08 Mar 2014, 16:36

Re: /punish

Postby _Retaliate_ » 04 Apr 2014, 00:55

I'm sorry, wat, you say it took you 24 days to make this?
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16

Re: /punish

Postby leicestercity » 04 Apr 2014, 07:03

I'm a very slow coder
LEICESTER TILL I DIE
leicestercity
 
Posts: 33
Joined: 08 Mar 2014, 16:36

Re: /punish

Postby Conor » 04 Apr 2014, 14:35

You have quite a few problems but you are on the right track. I will not correct it all for you as you just need to understand the correct layout and then you can easily go through it yourself :)

This is how you find and use a command.

Format:
Command.all.Find("commandName").Use(Player, "commandParameters");

So, the "commandParameters" will hold a string which will be passed through to the Command.Use method (which is overrided by the specified command); the Player object is the Player in which the command will be executed from. So if you wanted Player A to use a command on Player B, you would do this:

Command.all.Find("commandName").Use(playerAObject, "playerBName");

You'll find in 90% of simple cases that 'playerAobject' will be 'p' and 'playerBName' will be 'message'.

Some simple examples:
Code: Select all
public override void Use(Player p, string message)
{
   // Attempt to use the kick command, the 'message' would need to be a player's name
   Command.all.Find("kick").Use(p, message);

   // Attempt to ban the player, the 'message' would need to be the player's name
   Command.all.Find("ban").Use(p, message);

   // Kill the specified player with your own custom message - 'message' would need to be the player's name
   Command.all.Find("kill").Use(p, message + " was eaten alive by zombies!");


   // Make the other player use a command

   // 1. Find the other player
   Player who = Player.Find(message);

   // 2. Check they exist
   if (who == null) { Player.SendMessage(p, "Player could not be found."); return; }
   
   // 3. Execute the command
   Command.all.Find("me").Use(who, " was just forced to use a command!");

   // The above would cause the player specified to use the 'me' command, as if they were typing themself:
   // /me was just forced to use a command!
}


So take note of the correct format and you may find your solution quicker. Also take note that it is always 'Command.all' - this is a list of all commands (stored as Command objects) inside the Command class. You are searching this list for your command. There are no such lists in the Command class called "one", "two", "three".

Good luck!
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /punish

Postby Leeizazombie » 04 Apr 2014, 19:48

If you want to see your errors and how to fix please check here:
Please note that this will only fix errors, not run your command the way you want, you can ask if you want it fully fixed, I suggest you use these to learn your mistakes.
Spoiler:


I recommend you learn about it all, refer to Connor's message.
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: /punish

Postby leicestercity » 06 Apr 2014, 15:16

Thank you lee for helping me with my mistake ridden code XD told ya im a crap coder :P so s it more like this then?

Code: Select all
using System;
using System.IO;
using System.Threading;
     
namespace MCDzienny
{
    public class punish : Command
    {
        public override string name { get { return "punish"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
        public override void Use(Player p, string message)
        {
            Player.Sendmessage(p, "Who do you want to punish?" );
       
        player who = Player.Find(message);
        if (who == null)
        {
            Player.SendMessage(p, message + " is not online.");
       
            Command.all.find("warn").Use(p, who.name);
            Player.sendmessage (who, "You have been warned read /rules");
            Command.all.find("kick").Use(p, who.name);
            player.sendmessage (who, "You have been kick read /rules when you rejoin");
            Command.all.find("tempban" "60");
            player.sendmessage (who, "You are tempbanned for 60minutes tempbanned read /rules next time you join");
            Command.all.find("ban").Use(p, who.name);
            player.sendmessage (who, "You have been banned get unbanned at the forums!");
            Command.all.find("banip")
            player.sendmessage (who, "You have been ipbanned please dont connect on any other accounts"
        public override void Help(Player p)
        { 
            Player.SendMessage(p, "/punish - Punishes the player for their next punishment.");
        }
    }
}
LEICESTER TILL I DIE
leicestercity
 
Posts: 33
Joined: 08 Mar 2014, 16:36

Re: /punish

Postby leicestercity » 06 Apr 2014, 19:37

So how would i get it working the way i want it to then?
LEICESTER TILL I DIE
leicestercity
 
Posts: 33
Joined: 08 Mar 2014, 16:36

Re: /punish

Postby Bboy505 » 14 Apr 2014, 01:19

What do you want it to do? If the player has been given a certain punishment recently you want the player to be given the next punishment?
Founder of McClassicHosting
Need to contact me? Visit:
irc.geekshed.net
#mcclassichosting, #Panda
Bboy505
 
Posts: 13
Joined: 24 Jun 2013, 01:24


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 5 guests

cron