Page 1 of 2

how can i add ranks?

PostPosted: 12 Oct 2013, 13:23
by Vvfj
How can i add ranks where u earn in a certain amout of time?

Re: how can i add ranks?

PostPosted: 12 Oct 2013, 21:16
by _Retaliate_
I do not believe there is a method to do that which is built into MCDzienny, I'll make a command for it though, should take a day or two.

Re: how can i add ranks?

PostPosted: 12 Oct 2013, 21:44
by HETAL
@_Retaliate_ I can make 1 by today if you want

Re: how can i add ranks?

PostPosted: 12 Oct 2013, 22:17
by _Retaliate_
HETAL wrote:@_Retaliate_ I can make 1 by today if you want

Nah, it's alright, I'm going to try to complete it in 45 mins as a challenge.

Re: how can i add ranks?

PostPosted: 12 Oct 2013, 23:07
by _Retaliate_
I failed the challenge, ah well, I'm still going to do it tomorrow, night.

Re: how can i add ranks?

PostPosted: 12 Oct 2013, 23:11
by ismellike
I'm about to finish it right now Hetal, but you can still make it and share it here :).

Re: how can i add ranks?

PostPosted: 12 Oct 2013, 23:39
by HETAL
Sure, I will be done soon.(I have to go out somewhere) I will post it tomorrow. I just need the variable for total time spent on the server.

Re: how can i add ranks?

PostPosted: 13 Oct 2013, 00:28
by ismellike
Here is what I have, just go to your extra/time_ranks.xml file and change the time values in there.

Code: Select all
using System.Xml;
using System;
namespace MCDzienny
{
    public static class StaticEx
    {
        public static string path = @"extra\time_ranks.xml";
        public static void CreateXMLDoc()
        {
            if (!System.IO.File.Exists(path))
                using (XmlWriter xw = XmlWriter.Create(path, new XmlWriterSettings() { Indent = true }))
                {
                    xw.WriteStartDocument();
                    xw.WriteComment("This is the format, rank - time; Time is in hours!");
                    xw.WriteStartElement("Ranks");
                    Group.groupList.ForEach(delegate(Group g)
                    {
                        if (g.Permission > LevelPermission.Guest && g.Permission < LevelPermission.Operator)
                        {
                            xw.WriteStartElement(g.name);
                            xw.WriteElementString("Time", g.promotionPrice.ToString());
                            xw.WriteEndElement();
                        }
                    });
                    xw.WriteEndElement();
                    xw.WriteEndDocument();
                }
        }
        public static void SendTimes(this Player p)
        {
            using (XmlReader xr = XmlReader.Create(path, new XmlReaderSettings() { IgnoreComments = true, IgnoreWhitespace = true }))
            {
                while (xr.Read())
                {
                    if (xr.IsStartElement())
                    {
                        if (xr.Name == "Ranks" || xr.Name == null)
                            continue;
                        string temp = xr.Name;
                        xr.Read();
                        p.SendMessage(Group.Find(temp).color + temp + " - " + "%e" + xr.ReadString() + " hours");
                    }
                }
            }
        }
        public static bool CheckRank(Player p, out int timeLeft)
        {
            timeLeft = 0;
            using (XmlReader xr = XmlReader.Create(path, new XmlReaderSettings() { IgnoreComments = true, IgnoreWhitespace = true }))
            {
                while (xr.Read())
                    if (xr.IsStartElement())
                        if (xr.Name == NextGroup(p.group).name)
                        {
                            xr.Read();
                            if (p.TotalMinutesPlayed / 60 >= (timeLeft = Convert.ToInt32(xr.ReadString())))
                                return true;
                        }
            }
            timeLeft -= (p.TotalMinutesPlayed / 60);
            return false;
        }
        public static Group NextGroup(Group g)
        {
            int i = Group.groupList.IndexOf(g);
            return Group.groupList[i + 1];
        }
        public static void RankUp(this Player p)
        {
            int i;
            if (StaticEx.CheckRank(p, out i))
            {
                Group rank = NextGroup(p.group);
                p.group.playerList.Remove(p.name);
                p.group.playerList.Save();
                rank.playerList.Add(p.name);
                rank.playerList.Save();
                p.group = rank;
                Player.GlobalMessage(p.color + p.name + Server.DefaultColor + " has ranked up to " + rank.color + rank.name);
                Player.SendMessage(p, "Congratz! Do /help for a list of your new commands.");
                if (p.color == Group.findPerm(LevelPermission.Guest).color)
                {
                    p.color = rank.color;
                }
            }
            else
            {
                p.SendMessage("You cannot buy any ranks");
                if (i > 0)
                    p.SendMessage("You still need about " + Math.Abs(i).ToString() + " hours");
            }
        }
    }
    public class CmdRankup : Command
    {
        public override string name { get { return "rankup"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Init()
        {
            StaticEx.CreateXMLDoc();
        }
        public override void Use(Player p, string message)
        {
            switch (message.ToLower())
            {
                case "times":
                    p.SendTimes();
                    break;
                default:
                    p.RankUp();
                    break;
            }
        }
        public override void Help(Player p)
        {
            p.SendMessage("/rankup (left) the more time, the more ranks");
        }
    }
}

Re: how can i add ranks?

PostPosted: 13 Oct 2013, 08:25
by Vvfj
ismellike wrote:Here is what I have, just go to your extra/time_ranks.xml file and change the time values in there.

Code: Select all
using System.Xml;
using System;
namespace MCDzienny
{
    public static class StaticEx
    {
        public static string path = @"extra\time_ranks.xml";
        public static void CreateXMLDoc()
        {
            if (!System.IO.File.Exists(path))
                using (XmlWriter xw = XmlWriter.Create(path, new XmlWriterSettings() { Indent = true }))
                {
                    xw.WriteStartDocument();
                    xw.WriteComment("This is the format, rank - time; Time is in hours!");
                    xw.WriteStartElement("Ranks");
                    Group.groupList.ForEach(delegate(Group g)
                    {
                        if (g.Permission > LevelPermission.Guest && g.Permission < LevelPermission.Operator)
                        {
                            xw.WriteStartElement(g.name);
                            xw.WriteElementString("Time", g.promotionPrice.ToString());
                            xw.WriteEndElement();
                        }
                    });
                    xw.WriteEndElement();
                    xw.WriteEndDocument();
                }
        }
        public static void SendTimes(this Player p)
        {
            using (XmlReader xr = XmlReader.Create(path, new XmlReaderSettings() { IgnoreComments = true, IgnoreWhitespace = true }))
            {
                while (xr.Read())
                {
                    if (xr.IsStartElement())
                    {
                        if (xr.Name == "Ranks" || xr.Name == null)
                            continue;
                        string temp = xr.Name;
                        xr.Read();
                        p.SendMessage(Group.Find(temp).color + temp + " - " + "%e" + xr.ReadString() + " hours");
                    }
                }
            }
        }
        public static bool CheckRank(Player p, out int timeLeft)
        {
            timeLeft = 0;
            using (XmlReader xr = XmlReader.Create(path, new XmlReaderSettings() { IgnoreComments = true, IgnoreWhitespace = true }))
            {
                while (xr.Read())
                    if (xr.IsStartElement())
                        if (xr.Name == NextGroup(p.group).name)
                        {
                            xr.Read();
                            if (p.TotalMinutesPlayed / 60 >= (timeLeft = Convert.ToInt32(xr.ReadString())))
                                return true;
                        }
            }
            timeLeft -= (p.TotalMinutesPlayed / 60);
            return false;
        }
        public static Group NextGroup(Group g)
        {
            int i = Group.groupList.IndexOf(g);
            return Group.groupList[i + 1];
        }
        public static void RankUp(this Player p)
        {
            int i;
            if (StaticEx.CheckRank(p, out i))
            {
                Group rank = NextGroup(p.group);
                p.group.playerList.Remove(p.name);
                p.group.playerList.Save();
                rank.playerList.Add(p.name);
                rank.playerList.Save();
                p.group = rank;
                Player.GlobalMessage(p.color + p.name + Server.DefaultColor + " has ranked up to " + rank.color + rank.name);
                Player.SendMessage(p, "Congratz! Do /help for a list of your new commands.");
                if (p.color == Group.findPerm(LevelPermission.Guest).color)
                {
                    p.color = rank.color;
                }
            }
            else
            {
                p.SendMessage("You cannot buy any ranks");
                if (i > 0)
                    p.SendMessage("You still need about " + Math.Abs(i).ToString() + " hours");
            }
        }
    }
    public class CmdRankup : Command
    {
        public override string name { get { return "rankup"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Init()
        {
            StaticEx.CreateXMLDoc();
        }
        public override void Use(Player p, string message)
        {
            switch (message.ToLower())
            {
                case "times":
                    p.SendTimes();
                    break;
                default:
                    p.RankUp();
                    break;
            }
        }
        public override void Help(Player p)
        {
            p.SendMessage("/rankup (left) the more time, the more ranks");
        }
    }
}

Change like add or delete it everything and put this one? btw. thx.

Re: how can i add ranks?

PostPosted: 13 Oct 2013, 08:30
by Vvfj
wheres the "extra/time_ranks.xml" file?

http://i.imgur.com/314IuLt.png