/tempjail

/tempjail

Postby lucasds12 » 04 Jun 2013, 04:44

Hello, I would like the /tempjail command.
Basically it temp /jail(s) you for the amount of seconds you type in.
/tempjail [player] [seconds]
Here is what the global message and the send message should be:
Send Message: You have been jailed for [amount of seconds] and will be un-jailed until the limit reaches.
Global Message: [player] is now jailed for [amount of seconds]!
Thanks for reading this and like and subscribe, oh wait I did the mistake again, "IT'S NOT YOUTUBE!"
Anyways lol, put a reply down please.
-Lucas
There is only one thing I do in life, that's contributing here.
lucasds12
 
Posts: 334
Joined: 17 Apr 2013, 16:17
Location: In the deep caves.

Re: /tempjail

Postby Conor » 04 Jun 2013, 12:34

lucasds12 wrote:Hello, I would like the /tempjail command.
Basically it temp /jail(s) you for the amount of seconds you type in.
/tempjail [player] [seconds]
Here is what the global message and the send message should be:
Send Message: You have been jailed for [amount of seconds] and will be un-jailed until the limit reaches.
Global Message: [player] is now jailed for [amount of seconds]!
Thanks for reading this and like and subscribe, oh wait I did the mistake again, "IT'S NOT YOUTUBE!"
Anyways lol, put a reply down please.
-Lucas


Subscribed.

Code: Select all
using System;
using System.Threading;

namespace MCDzienny
{
      public class CmdTempjail : Command
      {
            public override string name { get { return "tempjail"; } }
            public override string shortcut { get { return "tj"; } }
            public override string type { get { return "mod"; } }
            public override bool museumUsable { get { return true; } }
            public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
            public override bool ConsoleAccess { get { return true; } }

            public override void Use(Player p, string message)
            {
                 if (!message.Contains(" ") || message.Trim().Length == 0)
                 {
                      Help(p);
                      return;
                 }

                  Player who = Player.Find(message.Split(' ')[0]);
                  if (who == null || who.hidden)
                  {
                      Player.SendMessage(p, "Player could not be found.");
                      return;
                  }

                  int time = 0;
                  try
                  {
                       time = int.Parse(message.Split(' ')[1]);
                  }
                  catch
                  {
                       Player.SendMessage(p, "Invalid amount.");
                       return;
                  }

                  if (who.group.Permission >= p.group.Permission)
                  {
                       Player.SendMessage(p, "Cannot jail a player of greater or equal rank.");
                  }
                  else if (who.jailed)
                  {
                       Player.SendMessage(p, "Player is already in jail.");
                  }
                  else
                  {
                        Command.all.Find("jail").Use(p, who.PublicName);
                        Thread.Sleep(time * 1000);
                       
                        if (who.jailed && !who.disconnected && who != null)
                        {
                             if (p != null && !p.disconnected)
                             {
                                 Command.all.Find("jail").Use(p, who.PublicName);
                             }
                             else
                             {
                                 Command.all.Find("jail").Use(null, who.PublicName);
                             }
                        }
                  }
            }
        public override void Help(Player p)
        {
          Player.SendMessage(p,"/tempjail [x] -- jails someone for x amount of seconds.");
           }
      }
}


I just wrote that here from scratch as I'm too lazy to open visual studio (bad decision - would have saved a lot of time), so just paste any compiler errors you may get here and I can fix them, or if the command doesn't work how you want it to then let me know how I can amend it.
Last edited by ismellike on 04 Jun 2013, 23:41, edited 3 times in total.
Reason: added /help tempjail, added return on the catch
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /tempjail

Postby Warren1001 » 04 Jun 2013, 21:48

You forgot the help part at the end.
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /tempjail

Postby ismellike » 04 Jun 2013, 21:53

Added the /help tempjail in, should compile correctly now :o
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /tempjail

Postby Conor » 04 Jun 2013, 21:58

ismellike wrote:Added the /help tempjail in, should compile correctly now :o


Thank you haha, school boy error from me.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /tempjail

Postby Warren1001 » 04 Jun 2013, 22:29

Code: Select all
-------------------------

Error CS0165
Message: Use of unassigned local variable 'time'
Line: 51
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /tempjail

Postby Conor » 04 Jun 2013, 23:38

Warren1001 wrote:
Code: Select all
-------------------------

Error CS0165
Message: Use of unassigned local variable 'time'
Line: 51


Change:
Code: Select all
int time;

To:
Code: Select all
int time = 0;


I'll also edit my post to amend this bug.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Requests for Addon

Who is online

Users browsing this forum: No registered users and 2 guests

cron