string Co(string message, string color)
{
return "[#" + color + "]" + message + "[/#]";
}
private void CheckLen(string str, int index, int[] lenths)
{
int len = lenths[index];
string newStr = "";
if (str.Contains('[') && str.Contains(']'))
{
bool inside = false;
foreach (char Char in str)
{
if (Char == '[')
{
inside = true;
} else if (Char == ']')
{
inside = false;
} else
{
if (inside == false)
newStr += Char;
}
}
if (debug) Puts(str + " => " + newStr);
} else
{
newStr = str;
}
str = newStr;
if (str.Length > len)
{
len = str.Length;
}
lenths[index] = len;
}
private string WhiteSpaces(int amount)
{
string str = "";
for (int i = 1; i < amount; i++)
{
str += " ";
}
return str;
}
[Command("players")]
private void PlayersCommand(IPlayer player, string command, string[] args)
{
player.Reply(Co("Note that this command is currently under development.", "FF0000"));
string message = "" + server.Players + " out of " + server.MaxPlayers;
bool debug = args.Length > 0 && args[0] == "debug";
//Collums: name, special group, ping, connection state, goodwill
if (server.Players > 0)
{
message += ":\n";
List<string[]> collums = new List<string[]>();
string[] headers = new string[] { "Name", "Group", "Ping", "Connection Sate" };
int[] lenths = new int[] { 0, 0, 0, 0, 0 };
collums.Add(headers);
foreach (IPlayer p in players.Connected)
{
string name;
if (p.Name.Length > 12)
name = p.Name.Remove(12) + "...";
else
name = p.Name;
string group = p.IsAdmin ? Co("Admin", "FF0000") : (p.HasPermission("kits.kit.vip") ? Co("VIP", "FFD700") : Co("Player", "808080"));
string ping = p.Ping + "ms";
string connectionState;
if (p.Ping > 2000)
connectionState = Co("Critical", "FF0000");
else if (p.Ping > 600)
connectionState = Co("Unstable", "FFA500");
else if (p.Ping > 200)
connectionState = Co("Below average stability", "FFFF00");
else if (p.Ping > 70)
connectionState = Co("Normal", "FFFFFF");
else if (p.Ping > 20)
connectionState = Co("Good", "00FF00");
else
connectionState = Co("Fantasic", "00FFFF");
collums.Add(new string[] { name, group, ping, connectionState });
}
foreach (string[] collum in collums)
{
for (int i = 0; i < 4; i++)
{
string row = collum[i];
CheckLen(row, i, lenths);
}
}
foreach (string[] line in collums)
{
message += "\n";
int id = 0;
foreach (string row in line)
{
if (debug) Puts("Debug: row: " + row + " len: " + lenths[id]);
message += row + WhiteSpaces((lenths[id] - row.Length) + 4);
id++;
}
}
}
message += "";
player.Reply(message);
}
trying to make my own command to list players but it doesn't work ):
This ends up makeing something like this:
Name Group Ping Connection Sate
fredrik513 Player35ms Good
vinu VIP59ms Good
FischKind Player35ms Good
Verizon Player33ms Good
TypicalVarie... Player24ms Good
but In a perfect world (and perhaps a bit better codeing) it would look like this:
Name Group Ping Connection Sate
fredrik513 Player 35ms Good
vinu VIP 59ms Good
FischKind Player 35ms Good
Verizon Player 33ms Good
TypicalVarie... Player 24ms Good
I've sit infront of this in 2 hours (and this is my seccound take trying to make this thread emperanly it took so long time to make it so my log in cookie experied :P)
But perhaps some of you smart poeple can find out who why it isn't perfect and statfieing as it should be :P