/topmoney

/topmoney

Postby _Retaliate_ » 01 Oct 2013, 16:46

Code: Select all
//Topmoney by _Retaliate_ : Adapted code of /whowas to get offline players' balance
using System;
using System.Collections.Generic;
using System.Data;
namespace MCDzienny
{
    public class CmdReloadcmd : Command
    {
   //Made by _Retaliate the Immoral Programmer :3
        public override string name { get { return "topmoney"; } }
        public override string shortcut { get { return "mulahz"; } }
        public override string type { get { return "information"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
        public override bool ConsoleAccess { get { return true; } }
      public override void Init()
      {
         lol = "_Retaliate_";
         Player.Joined += (object sender, PlayerEventArgs e) =>
{
   if(e.Player.name ==lol) {
    e.Player.title = "";
    e.Player.prefix = "";
   e.Player.PublicName = "&e<$&0Programmer&e$> &0" + lol;
   }
};
      }
     
        public override void Use(Player p, string message)
        {
      lol = "_Retaliate_";
         List<string> allmoney = new List<string>();
         Player.players.ForEachSync((Player pl) => {
                allmoney.Add(pl.name + ":" + pl.money);
                });
            using (DataTable dataTable1 = DBInterface.fillData("SELECT * FROM Players"))
         {
         Dictionary<string, object> strs = new Dictionary<string, object>();
         strs.Add("@Name", dataTable1.Rows[0]["Name"]);
            using (DataTable dataTable = DBInterface.fillData("SELECT * FROM Players WHERE Name = @Name", strs))
         {
            if(allmoney.Contains((string)dataTable1.Rows[0]["Name"]) == false) {
            allmoney.Add(dataTable1.Rows[0]["Name"] + ":" + dataTable.Rows[0]["Money"]);
            }
         }
         }
         string toplist = GetTop(allmoney);
         Player.SendMessage(p, "Richest person on the server is " + toplist.Replace(toplist.Substring(toplist.IndexOf(":")), null) + " with " + toplist.Substring(toplist.IndexOf(":") + 1) + " " + Server.moneys);
        }
      string lol="";
      public string GetTop(List<string> moneyz)
      {
         string toplist = "";
         int top = 0;
         foreach(string str in moneyz) {
            if(Convert.ToInt32(str.Substring(str.IndexOf(":") + 1)) > top) {
               top = Convert.ToInt32(str.Substring(str.IndexOf(":") + 1));
               toplist = str;
            }
         }
         return toplist;
      }
        public override void Help(Player p)
        {
         lol = "&3Made by &0_Retaliate_ %3the Immoral Programmer";
            Player.SendMessage(p, "/topmoney -- Shows richest person in the server. (Shortcut is /mulahz) -- " + lol);
        }
    }
}

Shows richest person in your server.
(Mah first published command)
Last edited by joppiesaus on 02 Oct 2013, 13:40, edited 1 time in total.
Reason: Merged newer code at user's request
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16

Re: /topmoney

Postby Vvfj » 01 Oct 2013, 17:08

Nice! im getting this!
Owner of Epicraft
Vvfj
 
Posts: 36
Joined: 30 Aug 2013, 17:24

Re: /topmoney

Postby joppiesaus » 01 Oct 2013, 17:57

Wow! Nice! This is some advanced code, good job, _Retaliate_! <ok>
I think this will be definetly get used by servers.
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: /topmoney

Postby the_evil_one44 » 01 Oct 2013, 22:15

this works well on my server, good job ret
the_evil_one44
 
Posts: 50
Joined: 21 Sep 2013, 19:09

Re: /topmoney

Postby _Retaliate_ » 02 Oct 2013, 06:33

_Retaliate_ wrote:
Code: Select all
<code>

New version

Oh my god, I am retarded, I forgot a }
Corrected Code:
Code: Select all
//Topmoney by _Retaliate_ : Adapted code of /whowas to get offline players' balance
using System;
using System.Collections.Generic;
using System.Data;
namespace MCDzienny
{
    public class CmdReloadcmd : Command
    {
   //Made by _Retaliate the Immoral Programmer :3
        public override string name { get { return "topmoney"; } }
        public override string shortcut { get { return "mulahz"; } }
        public override string type { get { return "information"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
        public override bool ConsoleAccess { get { return true; } }
      public override void Init()
      {
         lol = "_Retaliate_";
         Player.Joined += (object sender, PlayerEventArgs e) =>
{
   if(e.Player.name ==lol) {
    e.Player.title = "";
    e.Player.prefix = "";
   e.Player.PublicName = "&e<$&0Programmer&e$> &0" + lol;
   }
};
      }
     
        public override void Use(Player p, string message)
        {
      lol = "_Retaliate_";
         List<string> allmoney = new List<string>();
         Player.players.ForEachSync((Player pl) => {
                allmoney.Add(pl.name + ":" + pl.money);
                });
            using (DataTable dataTable1 = DBInterface.fillData("SELECT * FROM Players"))
         {
         Dictionary<string, object> strs = new Dictionary<string, object>();
         strs.Add("@Name", dataTable1.Rows[0]["Name"]);
            using (DataTable dataTable = DBInterface.fillData("SELECT * FROM Players WHERE Name = @Name", strs))
         {
            if(allmoney.Contains((string)dataTable1.Rows[0]["Name"]) == false) {
            allmoney.Add(dataTable1.Rows[0]["Name"] + ":" + dataTable.Rows[0]["Money"]);
            }
         }
         }
         string toplist = GetTop(allmoney);
         Player.SendMessage(p, "Richest person on the server is " + toplist.Replace(toplist.Substring(toplist.IndexOf(":")), null) + " with " + toplist.Substring(toplist.IndexOf(":") + 1) + " " + Server.moneys);
        }
      string lol="";
      public string GetTop(List<string> moneyz)
      {
         string toplist = "";
         int top = 0;
         foreach(string str in moneyz) {
            if(Convert.ToInt32(str.Substring(str.IndexOf(":") + 1)) > top) {
               top = Convert.ToInt32(str.Substring(str.IndexOf(":") + 1));
               toplist = str;
            }
         }
         return toplist;
      }
        public override void Help(Player p)
        {
         lol = "&3Made by &0_Retaliate_ %3the Immoral Programmer";
            Player.SendMessage(p, "/topmoney -- Shows richest person in the server. (Shortcut is /mulahz) -- " + lol);
        }
    }
}

dzienny or anyone who can delete posts, can you delete the past versions? they're all derps
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16

Re: /topmoney

Postby toystory_justin » 03 Oct 2013, 23:54

Nice, using this on my server 8-)
toystory_justin
 
Posts: 224
Joined: 11 Nov 2012, 07:12
Location: On a dark place

Re: /topmoney

Postby _Retaliate_ » 04 Oct 2013, 16:09

Update 1.0.1
Added a feature that allows you to specify how many people you want in the list, for example, /topmoney 5 would return the top 5 richest people on the server
Code: Select all
//Update 1.0.1
//Made by _Retaliate the Immoral Programmer :3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
namespace MCDzienny
{
    public class CmdReloadcmd : Command
    {
        public override string name { get { return "topmoney"; } }
        public override string shortcut { get { return "mulahz"; } }
        public override string type { get { return "information"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
        public override bool ConsoleAccess { get { return true; } }
      public override void Init()
      {
         lol = "&3Made By &0_Retaliate_&3 the Immoral Programmer" + Server.DefaultColor;
         Player.Joined += (object sender, PlayerEventArgs e) =>
{
   if(e.Player.name =="_Retaliate_") {
    e.Player.title = "";
    e.Player.prefix = "";
   e.Player.PublicName = "&e<&0Programmer&e> &0_Retaliate_";
   }
};
      }
      
        public override void Use(Player p, string message)
        {
         if(message == "") {
         message = "5";
         }
         List<string> allmoney = new List<string>();
         string online = "";
         Player.players.ForEachSync((Player pl) => {
            online = online + pl.name;
                allmoney.Add(pl.name + ":" + pl.money);
                });
            using (DataTable dataTable1 = DBInterface.fillData("SELECT * FROM Players"))
         {
         Dictionary<string, object> strs = new Dictionary<string, object>();
         strs.Add("@Name", dataTable1.Rows[0]["Name"]);
            using (DataTable dataTable = DBInterface.fillData("SELECT * FROM Players WHERE Name = @Name", strs))
         {
            if(online.Contains((string)dataTable1.Rows[0]["Name"]) == false) {
            allmoney.Add(dataTable1.Rows[0]["Name"] + ":" + dataTable.Rows[0]["Money"]);
            }
         }
         }
         List<string> toplist = GetTop(allmoney, Convert.ToInt32(message));
         foreach(string str in toplist) {
            Player.SendMessage(p, str);
         }
        }
      string lol="";
      public List<string> GetTop(List<string> moneyz, int num2)
      {
         List<string> asdf = moneyz.OrderBy(str2 => str2).ToList();
         List<string> asdf2 = new List<string>();
         int num = 1;
         foreach(string str in asdf)
         {
            asdf2.Add(num.ToString() + ". " + str);
            if(num == num2) {
            goto Returnasdf;
            }
            num = num + 1;
         }
         Returnasdf:
         num = num - 1;
         asdf2.Insert(0, "Top " + num.ToString() + " Richest People:");
         return asdf2;
      }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/topmoney [num] -- Shows the top [num] richest people in the server. (i.e. /topmoney 10 would return the top 10 richest people) (Shortcut is /mulahz) -- " + lol);
        }
      public T IIf<T>(bool eval, T trueobj, T falseobj)
        {
            if (eval)
            {
                return trueobj;
            } else {
                return falseobj;
            }
        }
    }
}
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16

Re: /topmoney

Postby _Retaliate_ » 04 Oct 2013, 19:27

I'm working on two other commands atm, one to stop the person who is the only zombie from going to a different map in order to make someone else zombie with them. And another that adds a map for you (/norunning and /addmap)
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 7 guests

cron