RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Resource icon

[2.x] Shard Statistics 1.3

No permission to download

zolo888

Sorceror
May I ask how you get the "console" up?, may be a dumb question....

Just not sure how I get the information (Great idea by the way) to display.......

Can i add it to a web page some how?
 

zolo888

Sorceror
Ah I see it now on the server console!

How do I get that in game or from a remote?

Am I asking tooooo many questions?
 

Felladrin

Sorceror
No, feel free to ask any questions. It will help me to improve the script description.

Well, the console report works like a "debug" option, so you can see if the data is being collected correctly. To display it inside the game you need to create a custom command or gump for it, following the "For Developers" instructions, on the description.

I'll post here later an example command that shows all that data in-game, so you can do other scripts based on it.
 

Zake

Wanderer
I can use being a player, to know how many people are playing currently in the shard i play ?
 

Kingllama

Knight
I've gotten this error.

RunUO - [www.runuo.com] Version 2.2, Build 4782.3756
Core: Running on .NET Framework Version 2.0.50727
Core: Optimizing for 2 64-bit processors
Scripts: Compiling C# scripts...failed (1 errors, 1 warnings)
Warnings:
+ Custom/Statistics.cs:
CS1502: Line 227: The best overloaded method match for 'string.Join(string,
string[])' has some invalid arguments
CS1503: Line 227: Argument '2': cannot convert from 'System.Collections.Gene
ric.List<string>' to 'string[]'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
 

Felladrin

Sorceror
I see. It's because I tested it with Net Framework 4.0, and didn't notice that 2.0 wouldn't accept that Join. I'll fix that. Thanks for reporting, Kingllama.
 

zolo888

Sorceror
Hello - Love the script. So simple and easy.

How would I go about using this info and "grabbing" it to post on a Web Hosted server eg my web page for the shard, to show all this good info?
 

Felladrin

Sorceror
Hello - Love the script. So simple and easy.

How would I go about using this info and "grabbing" it to post on a Web Hosted server eg my web page for the shard, to show all this good info?

Well, let me show you my WebStatus.cs as an example. It generates a html with all the shard statistics and players online every 60 seconds. Maybe it helps you to understand how to use the Statistics on other scripts.

C#:
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Guilds;

namespace Server.Misc
{
    public class StatusPage : Timer
    {
        public static bool Enabled = true;

        public static void Initialize()
        {
            if (Enabled)
                new StatusPage().Start();
        }

        public StatusPage()
            : base(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(60.0))
        {
            Priority = TimerPriority.FiveSeconds;
        }

        private static string Encode(string input)
        {
            StringBuilder sb = new StringBuilder(input);

            sb.Replace("&", "&amp;");
            sb.Replace("<", "&lt;");
            sb.Replace(">", "&gt;");
            sb.Replace("\"", "&quot;");
            sb.Replace("'", "&apos;");

            return sb.ToString();
        }

        protected override void OnTick()
        {
            if (!Directory.Exists("web"))
                Directory.CreateDirectory("web");

            using (StreamWriter op = new StreamWriter("web/status.html"))
            {
                op.WriteLine("<html>");
                op.WriteLine("   <head>");
                op.WriteLine("      <title>Shard Status</title>");
                op.WriteLine("   </head>");
                op.WriteLine("   <body>");
                op.WriteLine("      <div style='float: right'><small>{0} UTC -07:00</small></div>", DateTime.Now);
                op.WriteLine("      <h3>List of Online Players</h3>");
                op.WriteLine("      <table width=\"100%\">");
                op.WriteLine("         <tr>");
                op.WriteLine("            <td bgcolor=\"black\"><font color=\"white\">Name</font></td><td bgcolor=\"black\"><font color=\"white\">Title</font></td><td bgcolor=\"black\"><font color=\"white\">Location</font></td>");
                op.WriteLine("         </tr>");

                foreach (NetState state in NetState.Instances)
                {
                    Mobile m = state.Mobile;

                    if (m != null)
                    {
                        Guild g = m.Guild as Guild;

                        op.Write("         <tr><td>");

                        if (g != null)
                        {
                            op.Write(Encode(m.Name));
                            op.Write(" [");

                            string title = m.GuildTitle;

                            if (title != null)
                                title = title.Trim();
                            else
                                title = "";

                            if (title.Length > 0)
                            {
                                op.Write(Encode(title));
                                op.Write(", ");
                            }

                            op.Write(Encode(g.Abbreviation));

                            op.Write(']');
                        }
                        else
                        {
                            op.Write(Encode(m.Name));
                        }

                        op.Write("</td><td>");
                        op.Write(Titles.GetSkillTitle(m));
                        op.WriteLine("</td><td>");
                        if (m.Region.Name != null)
                        {
                            op.Write(m.Region.Name);
                        }
                        else
                        {
                            op.Write(m.X);
                            op.Write(", ");
                            op.Write(m.Y);
                            op.Write(", ");
                            op.Write(m.Z);
                        }
                        op.Write(" (");
                        op.Write(m.Map);
                        op.Write(")</td></tr>");
                    }
                }

                op.WriteLine("         <tr>");
                op.WriteLine("      </table>");
                op.WriteLine("   <h3>Shard Statistics</h3>");
                op.WriteLine("   <b>Shard Age:</b> {0:n0} days, {1:n0} hours and {2:n0} minutes<br/>", Statistics.ShardAge.Days, Statistics.ShardAge.Hours, Statistics.ShardAge.Minutes);
                op.WriteLine("   <b>Total Game Time:</b> {0:n0} hours and {1:n0} minutes<br/>", Statistics.TotalGameTime.TotalHours, Statistics.TotalGameTime.Minutes);
                op.WriteLine("   <b>Last Restart:</b> {0}<br/>", Statistics.LastRestart);
                op.WriteLine("   <b>Uptime:</b> {0:n0} days, {1:n0} hours and {2:n0} minutes<br/>", Statistics.Uptime.Days, Statistics.Uptime.Hours, Statistics.Uptime.Minutes);
                op.WriteLine("   <b>Active Accounts:</b> {0:n0} [{1:n0} Players Online]<br/>", Statistics.ActiveAccounts, Statistics.PlayersOnline);
                op.WriteLine("   <b>Active Staff Members:</b> {0:n0} [{1:n0} Staff Online]<br/>", Statistics.ActiveStaffMembers, Statistics.StaffOnline);
                op.WriteLine("   <b>Active Parties:</b> {0:n0} [{1:n0} Players in Parties]<br/>", Statistics.ActiveParties, Statistics.PlayersInParty);
                op.WriteLine("   <b>Active Guilds:</b> {0:n0}<br/>", Statistics.ActiveGuilds);
                op.WriteLine("   <b>Player Houses:</b> {0:n0}<br/>", Statistics.PlayerHouses);
                op.WriteLine("   <b>Player Gold:</b> {0:n0}<br/>", Statistics.PlayerGold);
                op.WriteLine("   </body>");
                op.WriteLine("</html>");
            }
        }
    }
}
 

zolo888

Sorceror
Yes I see - Thats grand. I now can get my script to create a HTML in a folder called Web as per your script.

Really apprecate the help and you taking the time, may seem simple but i am such a noob, I will go and research how i am going to get my webhosted web page to display those stats.

Thanks.
 

jayates

Sorceror
I'm wanting to add a new statistic. It's our currency and it's called an EVDollar. How would I add it to the script to show Player EVDollars?
 

ShakaNV

Wanderer
I'm not completely sure, but I don't think it's counting bank checks. Either that or it's not counting checks inside containers.

Example:
New shard, Test Center enabled. I've added 1 user account and created a character which generates a Chest in the users bank with a 60k gold stack, bank checks totaling 1 million, and 1000 gold in the players backpack. The total of gold reported by the script is 61,000.
 

Felladrin

Sorceror
I'm not completely sure, but I don't think it's counting bank checks. Either that or it's not counting checks inside containers.

Example:
New shard, Test Center enabled. I've added 1 user account and created a character which generates a Chest in the users bank with a 60k gold stack, bank checks totaling 1 million, and 1000 gold in the players backpack. The total of gold reported by the script is 61,000.

Hm, I was not aware of that. I'll check it out. Thanks for reporting.



I'm wanting to add a new statistic. It's our currency and it's called an EVDollar. How would I add it to the script to show Player EVDollars?

You should add 5 lines to your script. Let me explaing using an example. In this example, the item I want to add is called MyCustomItem. So in your script you will replace all MyCustomItem for the name of your item. And do the same for each item you want to add in the future.

Find the line: public static int StaffOnline { get { return m_StaffOnline; } }
Add after that line: public static int MyCustomItem { get { return m_MyCustomItem; } } // Added for my custom item.

Find the line: private static int m_StaffOnline;
Add after that line: private static int m_MyCustomItem; // Added for my custom item.

Find the line: m_StaffOnline = 0;
Add after that line: m_MyCustomItem = 0; // Added for my custom item.

Find:
C#:
if (i is Multis.BaseHouse)
    m_PlayerHouses++;
Add after that:
C#:
if (i is MyCustomItem) // Added for my custom item.
{
    if (i.Amount == 1)
        m_MyCustomItem++;
    else
        m_MyCustomItem += i.Amount;
}


Find the line: StatsList.Add(String.Format("Player Gold: {0:n0}", m_PlayerGold));
Add after that line: StatsList.Add(String.Format("MyCustomItem: {0:n0}", m_MyCustomItem)); // Added for my custom item.
 

Eric T. Benoit

Wanderer
In webstatus.cs is it possible to use an absolute path? Like:

Code:
 if (!Directory.Exists("c:\blah"))
                Directory.CreateDirectory("c:\blah");

*EDIT*
Nevermind, found it. :)

Code:
 if (!Directory.Exists(@"c:\blah"))
                Directory.CreateDirectory(@"c:\blah");
 
Top