how can i add ranks?

how can i add ranks?

Postby Vvfj » 12 Oct 2013, 13:23

How can i add ranks where u earn in a certain amout of time?
Owner of Epicraft
Vvfj
 
Posts: 36
Joined: 30 Aug 2013, 17:24

Re: how can i add ranks?

Postby _Retaliate_ » 12 Oct 2013, 21:16

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.
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16

Re: how can i add ranks?

Postby HETAL » 12 Oct 2013, 21:44

@_Retaliate_ I can make 1 by today if you want
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: how can i add ranks?

Postby _Retaliate_ » 12 Oct 2013, 22:17

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.
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16

Re: how can i add ranks?

Postby _Retaliate_ » 12 Oct 2013, 23:07

I failed the challenge, ah well, I'm still going to do it tomorrow, night.
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16

Re: how can i add ranks?

Postby ismellike » 12 Oct 2013, 23:11

I'm about to finish it right now Hetal, but you can still make it and share it here :).
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: how can i add ranks?

Postby HETAL » 12 Oct 2013, 23:39

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.
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: how can i add ranks?

Postby ismellike » 13 Oct 2013, 00:28

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");
        }
    }
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: how can i add ranks?

Postby Vvfj » 13 Oct 2013, 08:25

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.
Owner of Epicraft
Vvfj
 
Posts: 36
Joined: 30 Aug 2013, 17:24

Re: how can i add ranks?

Postby Vvfj » 13 Oct 2013, 08:30

wheres the "extra/time_ranks.xml" file?

http://i.imgur.com/314IuLt.png
Owner of Epicraft
Vvfj
 
Posts: 36
Joined: 30 Aug 2013, 17:24

Next

Return to Help

Who is online

Users browsing this forum: No registered users and 6 guests