HETAL wrote:@_Retaliate_ I can make 1 by today if you want
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");
}
}
}
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");
}
}
}
Users browsing this forum: No registered users and 16 guests