/hungergames

/hungergames

Postby Breakdown901 » 07 Aug 2013, 17:18

This is a very simple command, yet fun :)

Code: Select all
//By Breakdown901
using System;
using System.Threading;
namespace MCDzienny
{
   public class CmdHungergames : Command
   {
      public override string name { get { return "hungergames"; } }
      public override string shortcut { get { return "hg"; } }
      public override string type { get { return "other"; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
      public override bool ConsoleAccess { get { return false; } }
      
      public override void Use(Player p, string message)
      {
         if (p == null)
         {
         Player.SendMessage(p, "You cannot play hungergames from the console!");
         }
      {   
         Command.all.Find("goto").Use(p, "hungergames");
         Player.GlobalMessage(p.color + p.PublicName + Server.DefaultColor + " has joined the hunger games!");
         Thread.Sleep (2000);
         Player.SendMessage(p, "You are being given a gun, fight to the death!");
         Command.all.Find("gun").Use(p, "");
      }
   }         
   
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/hungergames - Fight to the death. A level called hungergames must be made first.");
      }
   }
}
Owner of:
Breakdown901 Lava Survival/Zombie Survival/Freebuild
Host of NeonGaming Lava Survival.
Breakdown901
 
Posts: 320
Joined: 24 May 2013, 12:54

Re: /hungergames

Postby Breakdown901 » 07 Aug 2013, 17:33

If you havent read the help message, you will need to make a level prior to using the command called "hungergames".
Owner of:
Breakdown901 Lava Survival/Zombie Survival/Freebuild
Host of NeonGaming Lava Survival.
Breakdown901
 
Posts: 320
Joined: 24 May 2013, 12:54

Re: /hungergames

Postby joppiesaus » 07 Aug 2013, 18:50

Yeah...
What if you haven't a level called "Hungergames"?
Why not create a random level if it does not exist? :)
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: /hungergames

Postby Breakdown901 » 07 Aug 2013, 19:43

I was worrying that, because every time someone uses /hungergames, it would make a new level called hunger games. So your going to end up with about 5 different hunger games levels. Idk how I would code it to make just one level.
Owner of:
Breakdown901 Lava Survival/Zombie Survival/Freebuild
Host of NeonGaming Lava Survival.
Breakdown901
 
Posts: 320
Joined: 24 May 2013, 12:54

Re: /hungergames

Postby HETAL » 07 Aug 2013, 20:27

try this
Code: Select all
    public class CmdHungergames : Command
    {
        const string mapname = "tnt";
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: /hungergames

Postby HETAL » 07 Aug 2013, 20:34

replace tnt with whatever mapname you want I got that from ismellikes tntwars
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: /hungergames

Postby Conor » 07 Aug 2013, 23:39

HETAL wrote:try this
Code: Select all
    public class CmdHungergames : Command
    {
        const string mapname = "tnt";

Creating a variable is not going to help Hetal. Though; it is a start.

@Breakdown901, you can check if the level exists first, if it doesn't then you can create one. Here, I coded it for you to see.

Code: Select all
using System;
using System.Threading;
namespace MCDzienny
{
   public class CmdHungergames : Command
   {
      public override string name { get { return "hungergames"; } }
      public override string shortcut { get { return "hg"; } }
      public override string type { get { return "other"; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
      public override bool ConsoleAccess { get { return false; } }

      private static string mapName = "hungergames";
     
      public override void Use(Player p, string message)
      {
         if (!LevelExists())
         {
             Command.all.Find("newlvl").Use(null, mapName + " 128 64 128 flat");
             Thread.Sleep(5000);
         }

         if (Level.Find(mapName) == null)
         {
              Player.SendMessage(p, mapName + " map could not be found. Ensure it is loaded.");
              return;
         }

         Command.all.Find("goto").Use(p, "hungergames");
         Player.GlobalMessage(p.color + p.PublicName + Server.DefaultColor + " has joined the hunger games!");
         Thread.Sleep (2000);
         Player.SendMessage(p, "You are being given a gun, fight to the death!");

         if (!p.aiming)
         {
             Command.all.Find("gun").Use(p, "");
         }
      }         

      private bool LevelExists()
      {
         foreach (FileInfo f in new DirectoryInfo("levels").GetFiles("*.lvl"))
         {
             if (f.Name.Split('.')[0] == mapName)
             {
                  return true;
             }
         }
         return false;
      }
 
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/hungergames - Fight to the death. A level called hungergames must be made first.");
      }
   }
}


I haven't tested that but I think it should work, let me know if you want some more help (or if it doesn't work).
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: /hungergames

Postby Breakdown901 » 08 Aug 2013, 10:14

Thank you Conor, I appreciate it a lot. Could you tell me what this part of the code is doing?

Code: Select all
private bool LevelExists()
      {
         foreach (FileInfo f in new DirectoryInfo("levels").GetFiles("*.lvl"))
         {
             if (f.Name.Split('.')[0] == mapName)
             {
                  return true;
             }
         }
         return false;
      }
 


I understand that it is looking for the level in the "levels" folder, but why would you need that if it has already made the level?
Owner of:
Breakdown901 Lava Survival/Zombie Survival/Freebuild
Host of NeonGaming Lava Survival.
Breakdown901
 
Posts: 320
Joined: 24 May 2013, 12:54

Re: /hungergames

Postby Breakdown901 » 08 Aug 2013, 10:21

Conor, I got some compiler errors with your version, I think it was the piece of code I posted a few minutes ago that is the problem.

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

Error #CS0246
Message: The type or namespace name 'DirectoryInfo' could not be found (are you missing a using directive or an assembly reference?)
Line: 43

-------------------------

Error #CS0246
Message: The type or namespace name 'FileInfo' could not be found (are you missing a using directive or an assembly reference?)
Line: 43
Owner of:
Breakdown901 Lava Survival/Zombie Survival/Freebuild
Host of NeonGaming Lava Survival.
Breakdown901
 
Posts: 320
Joined: 24 May 2013, 12:54

Re: /hungergames

Postby joppiesaus » 08 Aug 2013, 14:34

Breakdown901 wrote:Conor, I got some compiler errors with your version, I think it was the piece of code I posted a few minutes ago that is the problem.

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

Error #CS0246
Message: The type or namespace name 'DirectoryInfo' could not be found (are you missing a using directive or an assembly reference?)
Line: 43

-------------------------

Error #CS0246
Message: The type or namespace name 'FileInfo' could not be found (are you missing a using directive or an assembly reference?)
Line: 43


I think you forgot this at the top of your code:
Code: Select all
using System.IO;

This will fix the problem.
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Next

Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 5 guests

cron