/fshop (freebuild shop)

/fshop (freebuild shop)

Postby Warren1001 » 24 Jun 2013, 02:36

This allows you to set your title, color, welcome, and farewell in freebuild, completely and fully tested.
You can change how much each costs in extra/fshop.
You'll get errors if you type the requirements right, but not all of them..
Otherwise it 100% works.
Code: Select all
using System;
using System.IO;
namespace MCDzienny
{
   public class CmdFshop : Command
   {
      public string path = "extra/fshop";
      public override string name { get { return "fshop"; } }
      public override string shortcut { get { return "fstore"; } }
      public override string type { get { return "other"; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
      public override bool ConsoleAccess { get { return false; } }
      /*
         Made by:
         ~Warren1001~
      */
      public override void Init()
      {
         if (!Directory.Exists(path))
         {
            Directory.CreateDirectory(path);
         }
         if (!File.Exists(path + "/titlecost.txt"))
         {
            using (var write = new StreamWriter(path + "/titlecost.txt"))
            {
               write.WriteLine("|~| To change the cost of the title, change the number below. Only use numbers! |~|");
               write.WriteLine("250");
            }
         }
         if (!File.Exists(path + "/colorcost.txt"))
         {
            using (var write = new StreamWriter(path + "/colorcost.txt"))
            {
               write.WriteLine("|~| To change the cost of the color, change the number below. Only use numbers! |~|");
               write.WriteLine("200");
            }
         }
         if (!File.Exists(path + "/welcomecost.txt"))
         {
            using (var write = new StreamWriter(path + "/welcomecost.txt"))
            {
               write.WriteLine("|~| To change the cost of the welcome message, change the number below. Only use numbers! |~|");
               write.WriteLine("150");
            }
         }
         if (!File.Exists(path + "/farewellcost.txt"))
         {
            using (var write = new StreamWriter(path + "/farewellcost.txt"))
            {
               write.WriteLine("|~| To change the cost of the farewell message, change the number below. Only use numbers! |~|");
               write.WriteLine("150");
            }
         }
      }
      public override void Use(Player p, string message)
      {
         if (message.IndexOf(' ') == -1)
         {
            Help(p);
            return;
         }
         string split1 = message.Split(' ')[0];
         if (split1 == "buy")
         {
            string split2 = message.Split(' ')[1];
            if (split2 == "title")
            {
               foreach (string line in File.ReadAllLines(path + "/titlecost.txt"))
               {
                  if (!line.Contains("|~|"))
                  {
                     try
                     {
                        Convert.ToInt32(line);
                     }
                     catch
                     {
                        if (File.Exists(path + "/titlecost.txt"))
                        {
                           using (var write = new StreamWriter(path + "/titlecost.txt"))
                           {
                              write.WriteLine("|~| To change the cost of the title, change the number below. Only use numbers! |~|");
                              write.WriteLine("250");
                           }
                        }
                        Player.SendMessage(p, "&6Price was not a number, reverting back to default, please try again.");
                     }
                     if (p.money < Convert.ToInt32(line))
                     {
                        Player.SendMessage(p, "&6You do not have enough &d" + Server.moneys + " &6to buy this item.");
                        Player.SendMessage(p, "&6Type &4/money &6to see how many &d" + Server.moneys + " &6you have.");
                        return;
                     }
                     if (p.boughtTitle)
                     {
                        Player.SendMessage(p, "&6You have already bought a &2title&6.");
                        Player.SendMessage(p, "&6Type &4/fshop &3set &2title &6[&1title&6] to set your &2title&6.");
                        return;
                     }
                     if (!p.boughtTitle)
                     {
                        p.money -= Convert.ToInt32(line);
                        p.boughtTitle = true;
                        Player.SendMessage(p, "&6You have bought a &2title&6.");
                        Player.SendMessage(p, "&6Type &4/fshop &3set &2title &6[&1title&6] to set your &2title&6.");
                     }
                  }
               }
            }
            if (split2 == "color")
            {
               foreach (string line in File.ReadAllLines(path + "/colorcost.txt"))
               {
                  if (!line.Contains("|~|"))
                  {
                     try
                     {
                        Convert.ToInt32(line);
                     }
                     catch
                     {
                        if (File.Exists(path + "/colorcost.txt"))
                        {
                           using (var write = new StreamWriter(path + "/colorcost.txt"))
                           {
                              write.WriteLine("|~| To change the cost of the color, change the number below. Only use numbers! |~|");
                              write.WriteLine("200");
                           }
                        }
                        Player.SendMessage(p, "&6Price was not a number, reverting back to default, please try again.");
                     }
                     if (p.money < Convert.ToInt32(line))
                     {
                        Player.SendMessage(p, "&6You do not have enough &d" + Server.moneys + " &6to buy this item.");
                        Player.SendMessage(p, "&6Type &4/money &6to see how many &d" + Server.moneys + " &6you have.");
                        return;
                     }
                     if (p.boughtColor)
                     {
                        Player.SendMessage(p, "&6You have already bought a &2color&6.");
                        Player.SendMessage(p, "&6Type &4/fshop &3set &2color &6[&1color&6] to set your &2color&6.");
                        return;
                     }
                     if (!p.boughtColor)
                     {
                        p.money -= Convert.ToInt32(line);
                        p.boughtColor = true;
                        Player.SendMessage(p, "&6You have bought a &2color&6.");
                        Player.SendMessage(p, "&6Type &4/fshop &3set &2color &6[&1color&6] to set your &2color&6.");
                     }
                  }
               }
            }
            if (split2 == "welcome")
            {
               foreach (string line in File.ReadAllLines(path + "/welcomecost.txt"))
               {
                  if (!line.Contains("|~|"))
                  {
                     try
                     {
                        Convert.ToInt32(line);
                     }
                     catch
                     {
                        if (File.Exists(path + "/welcomecost.txt"))
                        {
                           using (var write = new StreamWriter(path + "/welcomecost.txt"))
                           {
                              write.WriteLine("|~| To change the cost of the welcome message, change the number below. Only use numbers! |~|");
                              write.WriteLine("150");
                           }
                        }
                        Player.SendMessage(p, "&6Price was not a number, reverting back to default, please try again.");
                     }
                     if (p.money < Convert.ToInt32(line))
                     {
                        Player.SendMessage(p, "&6You do not have enough &d" + Server.moneys + " &6to buy this item.");
                        Player.SendMessage(p, "&6Type &4/money &6to see how many &d" + Server.moneys + " &6you have.");
                        return;
                     }
                     if (p.boughtWelcome)
                     {
                        Player.SendMessage(p, "&6You have already bought a &2welcome message&6.");
                        Player.SendMessage(p, "&6Type &4/fshop &3set &2welcome &6[&1welcome message&6] to set your &2welcome message&6.");
                        return;
                     }
                     if (!p.boughtWelcome)
                     {
                        p.money -= Convert.ToInt32(line);
                        p.boughtWelcome = true;
                        Player.SendMessage(p, "&6You have bought a &2welcome message&6.");
                        Player.SendMessage(p, "&6Type &4/fshop &3set &2welcome &6[&1welcome message&6] to set your &2welcome message&6.");
                     }
                  }
               }
            }
            if (split2 == "farewell")
            {
               foreach (string line in File.ReadAllLines(path + "/farewellcost.txt"))
               {
                  if (!line.Contains("|~|"))
                  {
                     try
                     {
                        Convert.ToInt32(line);
                     }
                     catch
                     {
                        if (File.Exists(path + "/farewellcost.txt"))
                        {
                           using (var write = new StreamWriter(path + "/farewellcost.txt"))
                           {
                              write.WriteLine("|~| To change the cost of the farewell message, change the number below. Only use numbers! |~|");
                              write.WriteLine("150");
                           }
                        }
                        Player.SendMessage(p, "&6Price was not a number, reverting back to default, please try again.");
                     }
                     if (p.money < Convert.ToInt32(line))
                     {
                        Player.SendMessage(p, "&6You do not have enough &d" + Server.moneys + " &6to buy this item.");
                        Player.SendMessage(p, "&6Type &4/money &6to see how many &d" + Server.moneys + " &6you have.");
                        return;
                     }
                     if (p.boughtFarewell)
                     {
                        Player.SendMessage(p, "&6You have already bought a &2farewell message&6.");
                        Player.SendMessage(p, "&6Type &4/fshop &3set &2farewell &6[&1farewell message&6] to set your &2farewell message&6.");
                        return;
                     }
                     if (!p.boughtFarewell)
                     {
                        p.money -= Convert.ToInt32(line);
                        p.boughtFarewell = true;
                        Player.SendMessage(p, "&6You have bought a &2farewell message&6.");
                        Player.SendMessage(p, "&6Type &4/fshop &3set &2farewell &6[&1farewell message&6] to set your &2farewell message&6.");
                     }
                  }
               }
            }
         }
         if (split1 == "set")
         {
            string split2 = message.Split(' ')[1];
            if (split2 == "title")
            {
               if (!p.boughtTitle)
               {
                  Player.SendMessage(p, "&6You have not bought a &2title &6yet.");
                  Player.SendMessage(p, "&6To buy a &2title, type &4/fshop &3buy &2title&6.");
                  return;
               }
               int pos = message.IndexOf(' ');
               string newtitle = message.Substring(pos + 7);
               Command.all.Find("title").Use(p, newtitle);
               p.boughtTitle = false;
            }
            if (split2 == "color")
            {
               if (!p.boughtColor)
               {
                  Player.SendMessage(p, "&6You have not bought a &2color &6yet.");
                  Player.SendMessage(p, "&6To buy a &2color, type &4/fshop &3buy &2color&6.");
                  return;
               }
               int idk = message.IndexOf(' ');
               string newcolor = message.Substring(idk + 7);
               if (newcolor != "black" && newcolor != "navy" && newcolor != "green" && newcolor != "teal" && newcolor != "maroon" && newcolor != "purple" && newcolor != "gold" && newcolor != "silver" && newcolor != "gray" && newcolor != "blue" && newcolor != "lime" && newcolor != "aqua" && newcolor != "red" && newcolor != "pink" && newcolor != "yellow" && newcolor != "white")
               {
                  Player.SendMessage(p, "&2" + newcolor + " &6is not a valid color.");
                  return;
               }
               Command.all.Find("color").Use(p, newcolor);
               p.boughtColor = false;
            }
            if (split2 == "welcome")
            {
               if (!p.boughtWelcome)
               {
                  Player.SendMessage(p, "&6You have not bought a &2welcome message &6yet.");
                  Player.SendMessage(p, "&6To buy a &2welcome message, type &4/fshop &3buy &2welcome&6.");
                  return;
               }
               int pos = message.IndexOf(' ');
               string newwelcome = message.Substring(pos + 9);
               Command.all.Find("welcome").Use(p, newwelcome);
               p.boughtWelcome = false;
            }
            if (split2 == "farewell")
            {
               if (!p.boughtFarewell)
               {
                  Player.SendMessage(p, "&6You have not bought a &2farewell message &6yet.");
                  Player.SendMessage(p, "&6To buy a &2farewell message, type &4/fshop &3buy &2farewell&6.");
                  return;
               }
               int pos = message.IndexOf(' ');
               string newfarewell = message.Substring(pos + 10);
               Command.all.Find("farewell").Use(p, newfarewell);
               p.boughtFarewell = false;
            }
         }
      }
      public override void Help(Player p)
      {
         Player.SendMessage(p, "%0- &6A.K.A. - &4/fstore&6.");
         Player.SendMessage(p, "%0- &4/fshop &3buy &6(&2title&6/&2color&6/&2welcome&6/&2farewell&6)");
         Player.SendMessage(p, "%0- &4/fshop &3set &6(&2title&6/&2color&6/&2welcome&6/&2farewell&6) [&1title&6/&1color&6/&1welcome message&6/&1farewell message&6]");
         foreach (string linea in File.ReadAllLines(path + "/titlecost.txt"))
         {
            if (!linea.Contains("|~|"))
            {
               Player.SendMessage(p, "%0- &6The &2title &6costs: &d" + linea);
            }
         }
         foreach (string lineb in File.ReadAllLines(path + "/colorcost.txt"))
         {
            if (!lineb.Contains("|~|"))
            {
               Player.SendMessage(p, "%0- &6The &2color &6costs: &d" + lineb);
            }
         }
         foreach (string linec in File.ReadAllLines(path + "/welcomecost.txt"))
         {
            if (!linec.Contains("|~|"))
            {
               Player.SendMessage(p, "%0- &6The &2welcome message &6costs: &d" + linec);
            }
         }
         foreach (string lined in File.ReadAllLines(path + "/farewellcost.txt"))
         {
            if (!lined.Contains("|~|"))
            {
               Player.SendMessage(p, "%0- &6The &2farewell message &6costs: &d" + lined);
            }
         }
         Player.SendMessage(p, "%0- &6Type &4/money &6to see how many &d" + Server.moneys + " &6you have.");
      }
   }
}
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: /fshop (freebuild shop)

Postby ismellike » 24 Jun 2013, 03:34

Nice, but I'm not sure it will work since in the set area, it uses the command that can't be used (title/color etc).

If it really did not work you can just change the title, tcolor, and color to Command.all.Find("set----").Use(p, p.name+" "+new---);

As for the welcome and farewell.. you can change those with a variable. Idk what it was (not at home)
It's like p.welcomeMessage(string) etc.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /fshop (freebuild shop)

Postby Warren1001 » 24 Jun 2013, 05:00

if it forces you to use it, like /click is for lava too, but you can make it work for freebuild.
trust me, i tested it on freebuild and it works.. :3 i had settitle and setcolor, but it was just easier to do title and color.
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron