/buyrank - purchases the rank specified

/buyrank - purchases the rank specified

Postby dzienny » 22 Apr 2011, 11:41

"NOTE - in order to add or prevent ranks, you must edit the ranks.properties file. Added ranks should appear on a blank line in the form of "!newrank!price!". If you remove a rank from the sheet, It will no longer be purchasable, but it will still remain a rank, as this system in no way affects what ranks exist or do not exist.

If you have an older copy of the ranks.properties file, you will either have to delete it, and allow this to rebuild it in the new syntax, OR add the following line to it "!Skipable-ranks!false!". Change false to true if you want users to be able to skip ranks when purchasing."

Code: Select all
/*
* /////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
* \\\\\\\\                  Created by: SharpForge                   ////////
* ////////               Project Title: McLawl Economics             \\\\\\\\
* \\\\\\\\             Current Version: 3.1                          ////////
* ////////             Update Features: Added the ability to block   \\\\\\\\
* \\\\\\\\             skipping ranks. For any bugs and or comments  ////////
* ////////             message me in the mclawl forums :: shade2010  \\\\\\\\
* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////
*/

//Special thanks to TheMusiKid

using System;
using System.IO;

namespace MCDzienny
{
   public class CmdBuyrank : Command
   {

      public override string name { get { return "buyrank"; } }
      public override string shortcut { get { return "br"; } }
      public override string type { get { return "other"; } }
      public override bool museumUsable { get { return true; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }



        public override void Use(Player p, string message)
        {

            //Warning!! If files/directories required for the economy system to work
            //do not exist, the following script will automatically create the default
            //files!
            if (!Directory.Exists("text/Economy"))
            {
                p.SendMessage("%4Could not locate the 'text/Economy' folder, creating one now.");
                Directory.CreateDirectory("text/Economy");
                Directory.CreateDirectory("text/Economy/Jobs");
                Directory.CreateDirectory("text/Economy/Purchasables");
                p.SendMessage("%2Adding the 'Jobs' directory within 'text/Economy'!");
                p.SendMessage("%2Adding the 'Purchasables' directory within 'text/Economy'!");
                p.SendMessage("%2'text/Economy/Jobs' directories successfully created!");
            }

            if (!Directory.Exists("text/Economy/Purchasables"))
            {
                p.SendMessage("%4Could not locate the 'text/Economy/Purchasables' folder, creating one now.");
                Directory.CreateDirectory("text/Economy/Purchasables");
                p.SendMessage("%2Adding the 'Purchasables' directory within 'text/Economy'!");
                p.SendMessage("%2'text/Economy/Jobs' directory successfully created!");
            }

            if (!File.Exists("text/Economy/Purchasables/ranks.properties"))
            {
                p.SendMessage("%4The 'ranks.properties' file could not be located, generating default file now.");
                StreamWriter SW;
                SW = File.CreateText("text/Economy/Purchasables/ranks.properties");
                SW.WriteLine("!Skipable-ranks!False!");
                SW.WriteLine("!guest!0!");
                SW.WriteLine("!builder!10!");
                SW.WriteLine("!advbuilder!100!");
                SW.WriteLine("!operator!1000!");
                SW.Close();
                p.SendMessage("%2Adding the 'ranks.properties' file within ");
                p.SendMessage("%2'text/Economy/Purchasables'");
                p.SendMessage("%2'ranks.properties' file successfully created!");
            }

            if (message == "")
            {
                Help(p);
                return;
            }
            string rank = message;
            String[] strArray_rankFileDetails = File.ReadAllLines("text/Economy/Purchasables/ranks.properties");
            if (strArray_rankFileDetails[0].IndexOf("false") > 0)
            {
                for (int x = 1; x < strArray_rankFileDetails.Length; x++)
                {
                    String[] strArray_rankDetails = strArray_rankFileDetails[x].Split('!');
                    if (rank == strArray_rankDetails[1])
                    {
                        Group group = Group.Find(rank);
                        if (group.Permission > p.group.Permission)
                        {
                            int y = x - 1;
                            String[] strArray_currRankDetails = strArray_rankFileDetails[y].Split('!');
                            if (strArray_currRankDetails[1] == p.group.name)
                            {
                                if (p.money >= int.Parse(strArray_rankDetails[2]))
                                {

                                    p.money = p.money - int.Parse(strArray_rankDetails[2]);
                                    p.group.playerList.Remove(p.name);
                                    p.group.playerList.Save();
                                    group.playerList.Add(p.name);
                                    group.playerList.Save();
                                    p.SendMessage(strArray_rankDetails[2].ToString() + " " + Server.moneys + " have been removed from your savings!");
                                    p.SendMessage("%3Transaction complete! Thank you for your purchase.");
                                    p.group = group;
                                    p.color = group.color;
                                    Player.GlobalMessage(string.Concat((string[])new string[] { p.color, p.name, Server.DefaultColor, " %3just purchased the " + group.color + group.name + " %3rank!" }));
                                    Player.GlobalMessage(string.Concat((string[])new string[] { "%3Be sure to congradulate them!" }));
                                    return;
                                }
                                else
                                {
                                    p.SendMessage("%3Insufficient " + Server.moneys + " to buy rank :: " + strArray_rankDetails[1]);
                                    p.SendMessage("%3You lack, %2" + (int.Parse(strArray_rankDetails[2]) - p.money) + " %3" + Server.moneys + "!");
                                    return;
                                }
                            }
                            else
                            {

                                Group nextRank = Group.Find(strArray_rankDetails[1]);
                                p.SendMessage("%3You may not skip ranks!");
                                p.SendMessage("%3Your next buyable rank is " + nextRank.color + nextRank.name + " for :: &a" + strArray_rankDetails[2] + " %3" + Server.moneys + "!");
                                return;
                            }
                        }
                        else
                        {
                            p.SendMessage("%3You cannot buy a rank that is lower or equal to that of your current!");
                        }
                    }
                    else
                    {
                        if (x == (strArray_rankFileDetails.Length - 1) && rank != strArray_rankDetails[1])
                        {
                            p.SendMessage("The rank specified does not exist!");
                        }
                    }
                }
            }
            else
            {

                for (int x = 0; x < strArray_rankFileDetails.Length; x++)
                {
                    String[] strArray_rankDetails = strArray_rankFileDetails[x].Split('!');
                    if (rank == strArray_rankDetails[1])
                    {
                        Group group = Group.Find(rank);
                        if (group.Permission > p.group.Permission)
                        {
                            if (p.money >= int.Parse(strArray_rankDetails[2]))
                            {

                                p.money = p.money - int.Parse(strArray_rankDetails[2]);
                                p.group.playerList.Remove(p.name);
                                p.group.playerList.Save();
                                group.playerList.Add(p.name);
                                group.playerList.Save();
                                p.SendMessage(strArray_rankDetails[2].ToString() + " " + Server.moneys + " have been removed from your savings!");
                                p.SendMessage("%3Transaction complete! Thank you for your purchase.");
                                p.group = group;
                                p.color = group.color;
                                Player.GlobalMessage(string.Concat((string[])new string[] { p.color, p.name, Server.DefaultColor, " %3just purchased the " + group.color + group.name + " %3rank!" }));
                                Player.GlobalMessage(string.Concat((string[])new string[] { "%3Be sure to congradulate them!" }));
                                return;
                            }
                            else
                            {
                                p.SendMessage("%3Insufficient " + Server.moneys + " to buy rank :: " + strArray_rankDetails[1]);
                                p.SendMessage("%3You lack, %2" + (int.Parse(strArray_rankDetails[2]) - p.money) + " %3" + Server.moneys + "!");
                                return;
                            }
                        }
                        else
                        {
                            p.SendMessage("%3You cannot buy a rank that is lower or equal to that of your current!");
                        }
                    }
                    else
                    {
                        if (x == (strArray_rankFileDetails.Length - 1) && rank != strArray_rankDetails[1])
                        {
                            p.SendMessage("The rank specified does not exist!");
                        }
                    }
                }
            }
        }

      // This one controls what happens when you use /help [commandname].
      public override void Help(Player p)
      {
         Player.SendMessage(p, "/buyrank <rankname> - purchases the rank specified.");
      }
   }
}

/*
    Things to come :: Will implement the ability to add a time variable to the
    conditions for the buyrank command. This will mean that a person will need
    both the funds and the time spent on the server in order to buy the rank.
    If you wish for a person to not be able to buy the rank, remove it from the
    properties file!

    To view the properties file, just open it with notepad, wordpad, or any other
    generic text viewing software.
*/


full-post: http://forums.mclawl.tk/viewtopic.php?f ... 78&start=0
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Buy Rank

Postby mensch10 » 23 Apr 2011, 09:19

Must i make the economy folder too?
mensch10
 
Posts: 1
Joined: 18 Apr 2011, 17:35

Re: Buy Rank

Postby dzienny » 23 Apr 2011, 09:33

mensch10 wrote:Must i make the economy folder too?


I suppose the folder is created automatically. I have not tested this command, so i can't say for sure at the moment.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Buy Rank

Postby Herocane » 29 Apr 2011, 10:59

Haven't ever used one of these commands, they are usefull for servers were the admins dont give money away for free. This kind of command is for serious servers, new servers tend to be VERY kind with what the do in terms of Ranks and Money.
Herocane
 
Posts: 7
Joined: 11 Feb 2011, 02:08

Re: Buy Rank

Postby DragonMarx » 17 Jun 2011, 23:32

Can you post a tutorial on installing the custom commands? Thx
DragonMarx
 
Posts: 1
Joined: 17 Jun 2011, 23:20

Re: Buy Rank

Postby jkl139 » 20 Jun 2011, 12:19

McDzienny, i was pretty happy when you said bug would be fixed now. But now this error came a few times!

Error #CS0246
Message: Der Typ- oder Namespacename Command konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 17

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

Error #CS0246
Message: Der Typ- oder Namespacename LevelPermission konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 24

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

Error #CS0246
Message: Der Typ- oder Namespacename Player konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 28

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

Error #CS0246
Message: Der Typ- oder Namespacename Player konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 68

Means : The Art Or Namespacename player couldnt be found.
-.-
Image
Image
User avatar
jkl139
 
Posts: 444
Joined: 13 Jun 2011, 11:46
Location: MCDzienny Forum

Re: Buy Rank

Postby dzienny » 20 Jun 2011, 13:54

There was a bug in the custom command. I've updated it, copy new code and try to compile again, it compiled for me.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Buy Rank

Postby jkl139 » 20 Jun 2011, 16:42

dzienny wrote:There was a bug in the custom command. I've updated it, copy new code and try to compile again, it compiled for me.


Uff, i got a pretty long error.. not sure if i can fully post it :D

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

Error #CS0246
Message: Der Typ- oder Namespacename Command konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 17

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

Error #CS0246
Message: Der Typ- oder Namespacename LevelPermission konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 24

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

Error #CS0246
Message: Der Typ- oder Namespacename Player konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 28

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

Error #CS0246
Message: Der Typ- oder Namespacename Player konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 68

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 3

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 3

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 3

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 3

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 3

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 3

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 3

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 3

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 5

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 5

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 5

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 5

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 5

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 5

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 5

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 5

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 7

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 7

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 7

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 7

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 7

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 7

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 7

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 7

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS1056
Message: Unerwartetes Zeichen \.
Line: 9

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

Error #CS0116
Message: Member, wie z.B. Felder oder Methoden, sind nicht direkt im Namespace enthalten.
Line: 2

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

Error #CS0246
Message: Der Typ- oder Namespacename Command konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 16

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

Error #CS0246
Message: Der Typ- oder Namespacename LevelPermission konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 23

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

Error #CS0246
Message: Der Typ- oder Namespacename Player konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 27

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

Error #CS0246
Message: Der Typ- oder Namespacename Player konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)
Line: 334


But this is the error code for the three compiler..
Image
Image
User avatar
jkl139
 
Posts: 444
Joined: 13 Jun 2011, 11:46
Location: MCDzienny Forum

Re: Buy Rank

Postby dzienny » 20 Jun 2011, 22:27

Make sure you copy entire code, it's very important not to miss a single character. Click SELECT ALL and use ctrl+c, ctrl+v to copy code to notepad. The rest is here > viewtopic.php?f=11&t=450#p535 . Good luck :)
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Buy Rank

Postby jkl139 » 20 Jun 2011, 22:35

dzienny wrote:Make sure you copy entire code, it's very important not to miss a single character. Click SELECT ALL and use ctrl+c, ctrl+v to copy code to notepad. The rest is here > viewtopic.php?f=11&t=450#p535 . Good luck :)


Im sad, it still doesnt work.. Thanx anyway (same error code).. and i copied all before too.. D:
Image
Image
User avatar
jkl139
 
Posts: 444
Joined: 13 Jun 2011, 11:46
Location: MCDzienny Forum

Next

Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 2 guests

cron