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!

webstatus.cs display vendor and what vendor is selling- Error.

AlphaDragon

Sorceror
With this code I was able to at least show 1 of the items that were in the container
But its not listing all of the different items in the container.
Still trying to get it to show all the items in all of the containers of the vendor.


Code:
                            if ( item is Container )
                            {
                                foreach ( Item subItem in item.Items )
                               
                                {
                                    op.Write( "<tr><td>");
                                    op.WriteLine(subItem.Name);
                                    op.Write("</td></tr>" );
                                }
                            }
 

AlphaDragon

Sorceror
Capture.PNG
:mad: There is got to be a better way of going threw all the containers of a vendor to check and see if items are for sale!
I got it to show items if in a container, but wont go threw the container thats inside the container.

And the way I have it setup atm it is having issues showing the price and description.

I am at a lost on this.

Attached is also an immage of what it is displaying atm.

This is what I have so far. But I definatly know it is not correct.
Code:
using System;
using System.IO;
using System.Text;
using Server;
using Server.Network;
using Server.Guilds;
 
//
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
//
 
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()
        {
//            World.Broadcast( 0x35, true, "STARTING STATUS" );
            if ( !Directory.Exists( "web" ) )
                Directory.CreateDirectory( "web" );
 
            using ( StreamWriter op = new StreamWriter( "web/status.html" ) )
            {
                op.WriteLine( "<html>" );
 
 
 
                op.WriteLine( "  <head>" );
                op.WriteLine( "      <title>DragonKnights UO Server Status</title>");
                op.WriteLine( "  </head>" );
                op.WriteLine( "  <body bgcolor=\"black\">" );
                op.WriteLine( "<img src= http://aaaservices.homeip.net/UO/DragonKnights%20-%20logo.jpg <br> " );
                op.WriteLine( "      <h3><font color =\"gold\">UltimaOnline Server Status</font></h3>" );
                op.WriteLine( "<b><font color =\"gold\">Current Server Version # :</font></b><font color=\"green\"> 7.0.12.0</font><br>");
                op.WriteLine( "<b><font color =\"gold\">Status Page Last Updated:</font></b><font color=\"green\"> "+DateTime.Now.ToString() + "</font><br>");
                op.WriteLine( "<b><font color =\"gold\">Total World Items:</font></b><font color=\"green\"> "+World.Items.Count.ToString()+"</font><br>");
                op.WriteLine( "<b><font color =\"gold\">Total World Mobiles:</font></b><font color=\"green\"> " + World.Mobiles.Count.ToString() + "</font><br>");
                op.WriteLine( "<b><font color =\"gold\">Total Online:</font></b><font color=\"green\"> " + NetState.Instances.Count.ToString() + "</font><br>");
                op.WriteLine( "<br>" );
//                op.WriteLine( "<br>" );
//                op.WriteLine( "<b><font color =\"gold\">END OF TOP  - START OF ONLINE CLIENT TABLE</font></b><br>" );
     
     
     
#region online client table
                op.WriteLine( "<font color=\"green\">      <table width=\"100%\">" );
                op.WriteLine( "        <tr></font>" );
                op.WriteLine( "            <td bgcolor=\"white\"><font color =\"black\"><b><img src= http://aaaservices.homeip.net/UO/OLW.png align=\"absmiddle\"> ONLINE PLAYERS:</b></font></td>" );
                op.WriteLine( "        </tr>" );
                op.WriteLine( "      </table>" );
 
     
                op.WriteLine( "<font color=\"green\">      <table width=\"100%\">" );
                op.WriteLine( "        <tr></font>" );
                op.WriteLine( "            <td bgcolor=\"white\"><font color=\"black\"><img src= http://aaaservices.homeip.net/UO/OLW.png align=\"absmiddle\"> Name</font></td><td bgcolor=\"white\"><font color=\"black\">Location</font></td><td bgcolor=\"white\"><font color=\"black\">Kills</font></td><td bgcolor=\"white\"><font color=\"black\">Karma / Fame</font></td>" );
                op.WriteLine( "        </tr>" );
     
                if (NetState.Instances.Count > 0)
                {
                #region list online players     
                foreach ( NetState state in NetState.Instances )
                {
                    Mobile m = state.Mobile;
         
         
         
 
                    if ( m != null )
                    {
                        Guild g = m.Guild as Guild;
 
                        op.Write( "        <tr><td><img src= http://aaaservices.homeip.net/UO/OLB.png align=\"absmiddle\"> " );
 
 
                        switch (m.AccessLevel)
                        {
                        case AccessLevel.Player:
                        op.Write( "<font color = FFFFFF><b>Player</b> - " );
                        break;
                        case AccessLevel.Counselor:
                        op.Write( "<font color = 008000><b>Counselor</b> - " );
                        break;
                        case AccessLevel.GameMaster:
                        op.Write( "<font color = FF0000><b>GameMaster</b> - " );
                        break;
                        case AccessLevel.Seer:
                        op.Write( "<font color = FF0000><b>Seer</b> - " );
                        break;
                        case AccessLevel.Administrator:
                        op.Write( "<font color = FF0000><b>Administrator</b> - " );
                        break;
                        case AccessLevel.Developer:
                        op.Write( "<font color = FF0000><b>Developer</b> - " );
                        break;
                        case AccessLevel.Owner:
                        op.Write( "<font color = 0000FF><b>Owner</b> - " );
                        break;
                        }
 
 
 
 
                        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><font color = 008000>" );
                        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><td><font color = FF0000>" );
                        op.Write( m.Kills );
                        op.Write( "</td><td><font color = 800080>" );
                        op.Write( m.Karma );
                        op.Write( " / " );
                        op.Write( m.Fame );
                        op.WriteLine( "</td></tr>" );
                    }
 
         
         
                }
                #endregion list online players
                }
     
                else
                {
                    op.WriteLine( "<td><b><font color =\"red\">Nobody but us chickens! =P</font></b></td></tr>" );
                }
     
//                op.WriteLine( "        <tr></tr>" );//added /tr
                op.WriteLine( "      </table>" );
#endregion online client table
     
     
#region player vendors table
//                op.WriteLine( "<br>" );
                op.WriteLine( "<br>" );
                op.WriteLine( "<font color=\"green\">      <table width=\"100%\">" );
                op.WriteLine( "        <tr></font>" );
                op.WriteLine( "            <td bgcolor=\"white\"><font color =\"black\"><b><img src= http://aaaservices.homeip.net/UO/COEW.png align=\"absmiddle\"> PLAYER VENDOR SHOPS:</b></font></td>" );
                op.WriteLine( "        </tr>" );
                op.WriteLine( "      </table>" );
 
 
     
                op.WriteLine( "<font color=\"green\">      <table width=\"100%\">" );
                op.WriteLine( "        <tr></font>" );
                op.WriteLine( "            <td bgcolor=\"white\"><font color=\"black\"><img src= http://aaaservices.homeip.net/UO/COEW.png align=\"absmiddle\"> Owners Name</font></td><td bgcolor=\"white\"><font color=\"black\">Shops Name</font></td><td bgcolor=\"white\"><font color=\"black\">Vendors Name</font></td><td bgcolor=\"white\"><font color=\"black\">Location</font></td>" );
                op.WriteLine( "        </tr>" );
 
 
                foreach ( Mobile mob in World.Mobiles.Values )
                {
                    if ( mob is PlayerVendor )
                    {
                        PlayerVendor pv = mob as PlayerVendor;
                        op.Write( "        <tr><td bgcolor=\"red\"><font color = \"black\"><img src= http://aaaservices.homeip.net/UO/COER.png align=\"absmiddle\"> " );
             
                        op.WriteLine( pv.Owner.Name );
                        op.Write( "</td><td bgcolor=\"red\"><font color = \"black\">" );
             
                        op.WriteLine( pv.ShopName );
                        op.Write( "</td><td bgcolor=\"red\"><font color = \"black\">" );
             
                        op.WriteLine( pv.Name );
                        op.Write( "</td><td bgcolor=\"red\"><font color = \"black\">" );
//                        op.WriteLine( pv.Map );
//                        op.WriteLine( pv.Backpack );
//                        op.WriteLine( pv.AccessLevel );
                        op.WriteLine( pv.Map + " - " + pv.Location );
                        op.Write( "</td></tr>" );
//                        op.WriteLine( pv.X );
//                        op.WriteLine( pv.Y );
//                        op.WriteLine( pv.Z );
//                        op.WriteLine( pv.RawName );
//                        op.WriteLine( "---------------");
//                        op.WriteLine( "</td></tr>" );
             
             
             
             
             
                op.WriteLine( "<tr><td bgcolor=\"yellow\"><font color=\"black\"><img src= http://aaaservices.homeip.net/UO/COEY.png align=\"absmiddle\">Amount</td><td bgcolor=\"yellow\"><font color=\"black\">Item</td><td bgcolor=\"yellow\"><font color=\"black\">Price for the Amount<t/d><td bgcolor=\"yellow\"><font color=\"black\">Description</td></tr>" );
 
                        foreach (Item item in pv.GetItems())
                {
                            VendorItem vi = pv.GetVendorItem(item);
                       
                       
                       
 
 
                            if ( item is Container )
                            {
                                foreach ( Item subItem in item.Items )
                         
                                {
                                    string siname = subItem.Name;
                                    if (string.IsNullOrEmpty(siname))
                                    {
                                        siname = subItem.GetType().ToString();
                                        if (siname.LastIndexOf('.') >= 0)
                                            siname = siname.Substring(siname.LastIndexOf('.') + 1);
                                    }
                                    if ( siname.Length > 25 )
                                        siname = siname.Substring(0, 25);
                               
                                    string sides = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
 
                                    op.Write( "<tr><td bgcolor=\"orange\"><font color = \"black\">");
                                    op.WriteLine(subItem.Amount);
                                    op.Write("</td>" );
                                    op.Write( "<td bgcolor=\"orange\"><font color = \"black\">");
                                    op.WriteLine(siname);
                                    op.Write("</td>" );
                                    op.Write( "<td bgcolor=\"orange\"><font color = \"black\">");
                                    op.WriteLine(vi.Price.ToString() );// SHOWS -1 instead of the price
                                    op.Write("</td>" );
                                    op.Write( "<td bgcolor=\"orange\"><font color = \"black\">");
                                    op.WriteLine(sides);// NOT SHOWING DESCRIPTION
                                    op.Write("</td></tr>" );
                                }
                            }
 
 
                       
//                            if ( item is Container && item.Items.Count >0)
//                            {
//                                items = new ItemInfo[ item.Items.Count ];
//                         
//                                for ( int i = 0; i < items.Length; i++ )
//                                {
//                                    items[ i ] = new ItemInfo( item.Items[ i ] as Item );
//                                }
//                            }
//                            else
//                            {
//                                items = new ItemInfo[ 1 ];
//                                items[ 0 ] = new ItemInfo( item );
//                            }
 
 
// SELF TRYING
//                            if ( item is Container && ( (Container)item ).Items.Count != 0 )
//                            {
//                                if ( ( (Container)item ).Items != null && ( (Container)item ).Items.IsForSale )
//                                {
//                                    string ownername = (pv.Name != pv.Owner.Name ? pv.Owner.Name : " ");
//                                    string name = ( (Container)item ).Items.Name;
//                         
//                                    if (string.IsNullOrEmpty(name))
//                                    {
//                                        name = item.GetType().ToString();
//                                        if (name.LastIndexOf('.') >= 0)
//                                            name = name.Substring(name.LastIndexOf('.') + 1);
//                                    }
//                         
//                                    if ( name.Length > 25 )
//                                    name = name.Substring(0, 25);
//                         
//                                    string des = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
//                         
//                                    op.WriteLine( "<tr><td bgcolor=\"green\"><font color = \"black\"><img src= http://aaaservices.homeip.net/UO/COEG.png align=\"absmiddle\"> {0} </td> <td bgcolor=\"green\"><font color = \"black\"> {1,-25} </td> <td bgcolor=\"green\"><font color = \"black\"> {2,7} </td> <td bgcolor=\"green\"><font color = \"black\"> {3} </td></tr>", item.Amount, name, vi.Price.ToString(), des );//Added </tr
//                         
//
//                                }
//                            }
                     
 
 
                       
                       
                 
                 
                            if ( vi != null && vi.IsForSale )
                            {
                                if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
                                    continue;
                                string ownername = (pv.Name != pv.Owner.Name ? pv.Owner.Name : " ");
                                string name = item.Name;
                                if (string.IsNullOrEmpty(name))
                                {
                                    name = item.GetType().ToString();
                                    if (name.LastIndexOf('.') >= 0)
                                        name = name.Substring(name.LastIndexOf('.') + 1);
                                }
                                    if ( name.Length > 25 )
                                    name = name.Substring(0, 25);
 
                                string des = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
 
 
                                    op.WriteLine( "<tr><td bgcolor=\"green\"><font color = \"black\"><img src= http://aaaservices.homeip.net/UO/COEG.png align=\"absmiddle\"> {0} </td> <td bgcolor=\"green\"><font color = \"black\"> {1,-25} </td> <td bgcolor=\"green\"><font color = \"black\"> {2,7} </td> <td bgcolor=\"green\"><font color = \"black\"> {3} </td></tr>", item.Amount, name, vi.Price.ToString(), des );//Added </tr
                                }
                            }
                    }
                    }
 
 
//I ADDED END
//                op.WriteLine( "        <tr></tr>" );
                op.WriteLine( "      </table>" );
     
     
     
 
 
#endregion player vendors table
     
     
//                op.WriteLine( "<b><font color =\"gold\">END OF LINE</font></b><br>" );
 
     
     
     
                op.WriteLine( "  </body>" );
                op.WriteLine( "</html>" );
//                Console.WriteLine( "WEBSTATUS UPDATE COMPLETE");
            }
        }
    }
}
 

daat99

Moderator
Staff member
Are you using visual C# express?

If so than what you need to do is highlight the entire section inside the "foreach" you just added, right click on it and select: "refactor -> extract method".

If you don't than you need to create a method that does exactly the same thing and call it yourself.

In that method you need to do the check if the item is a container again and if so you call the method again.

This is called "recursion", you can google it up.
 

daat99

Moderator
Staff member
I understand what you are trying to do.

I also explained what you need to do in order to make it happen.
 

AlphaDragon

Sorceror
I cleaned up the code and brought it down to the basics. Hopefully it will make it easier, for you, to help me in makeing it so that it will check all the containers in the vendors backpack, and list those items with the amount, name, price and description.:(
Thanks
Code:
using System;
using System.IO;
using System.Text;
using Server;
using Server.Network;
using Server.Guilds;
 
//
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
//
 
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>" );
             
             
             
             
             
#region player vendors table
             
             
             
             
             
                op.WriteLine( "PLAYER VENDORS:<br>" );
                op.WriteLine( "***************************************************************************************<br>" );
 
                foreach ( Mobile mob in World.Mobiles.Values )
                {
                    if ( mob is PlayerVendor )
                    {
                        PlayerVendor pv = mob as PlayerVendor;
                        op.WriteLine( "Owners Name , Shops Name, Vendors Name, Location <br>" );
                        op.WriteLine( pv.Owner.Name + "," + pv.ShopName + "," + pv.Name + "," + pv.Map + " - " + pv.Location + "<br>" );
                     
                     
                        op.WriteLine("Amount,Item,Price for the Amount,Description<br>");
                     
                        foreach (Item item in pv.GetItems())
                        {
                            VendorItem vi = pv.GetVendorItem(item);
                            if (vi != null && vi.IsForSale)
                            {
                                if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
                                    continue;
                                string ownername = (pv.Name != pv.Owner.Name ? pv.Owner.Name : " ");
                                string name = item.Name;
                                if (string.IsNullOrEmpty(name))
                                {
                                    name = item.GetType().ToString();
                                    if (name.LastIndexOf('.') >= 0)
                                        name = name.Substring(name.LastIndexOf('.') + 1);
                                }                             
                                if (name.Length > 25)
                                    name = name.Substring(0, 25);
                             
                                string des = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
                                op.WriteLine( "{0} {1,-25} {2,7}  {3} <br>", item.Amount, name, vi.Price.ToString(), des );
                            }
                        }
                        op.WriteLine( "---------------------------------------------------------------------------------------<br>" );
 
                    }
                    if(mob is PlayerVendor == null)
                        op.WriteLine( "There are no player vendors in the world at the moment.<br>" );
                }
                op.WriteLine( "***************************************************************************************<br>" );
             
             
             
             
             
#endregion player vendors table
         
         
         
         
         
            op.WriteLine( "  </body>" );
            op.WriteLine( "</html>" );
            }
        }
    }
}
 

daat99

Moderator
Staff member
I appreciate the effort but did you try what I suggested here:

Are you using visual C# express?

If so than what you need to do is highlight the entire section inside the "foreach" you just added, right click on it and select: "refactor -> extract method".

If you don't than you need to create a method that does exactly the same thing and call it yourself.

In that method you need to do the check if the item is a container again and if so you call the method again.

This is called "recursion", you can google it up.
 

AlphaDragon

Sorceror
I have not downloaded C# express.

Googleing and tring to figure out "recursion" Seems like banging my head against a wall.
this is that
if that.isforsale
print that
if that is a bag
bag = bagthis
if bagthis !=null && isforsale
Idontknow is now-this
go back to begining return; is the return what I am missing? I DONT KNOW! LMAO:confused:Going nuts!
Code:
using System;
class Program
{
    static void RecuriveFunction(int x)
    {
 
        if (x > 10)  //Condition to stop recursion
            return;  //Exit out of function
        else
        {
            Console.WriteLine(x);
            RecuriveFunction(x + 1);  //Call myself
        }
    }
 
    static void Main()
    {
        RecuriveFunction(1);
        Console.Read();
    }
}
 

daat99

Moderator
Staff member
Download C# express (it's free from microsoft) and do the refactor thingy then.

First you need to get the method working, after that you need to make it recursive.
 

AlphaDragon

Sorceror
I downloaded c# express 2010, it does not come with the recursive (right click) aparently they took it out.
Since you know what I am trying to do, if you can help me with fixing the script, please do.
I am uninstalling the 2010 along with all the other unneeded stuff it installed into my system.
 

daat99

Moderator
Staff member
Here's a step by step:

1. Highlight the entire section inside the "foreach" you just added.
2. Right click on it and select: "refactor -> extract method"

3. Post the new code with the new method here for further assistance.


I'm very willing to help you but I won't do it for you.
 

daat99

Moderator
Staff member
too bad, you should really start to use Visual C# express, it'll make your life a lot easier when coding.

In any case let's do it step by step.

1. Create a new method that returns "void".

2. Call the method "GetVendorItemsDisplay" or something to that effect.

3. You new method needs to accept the following arguments:
3.1. "StreamWriter" you can call it "op".
3.2. "PlayerVendor" you can call it "pv".
3.3. "Item" you can call it "item".

After you created this new method:

4. Copy all the code inside the foreach loop that runs on the pv.GetItems() list into the new method, this is your actual code.

5. Write inside the foreach loop the following line
Code:
GetVendorItemsDisplay( op, pv, item);

so it'll look like this:
Code:
... bla bla ...
op.WriteLine("Amount,Item,Price for the Amount,Description<br>");
foreach (Item item in pv.GetItems())
{
    GetVendorItemsDisplay( op, pv, item);
}
op.WriteLine( "---------------------------------------------------------------------------------------<br>" );
... bla bla ...

All the above steps is just the "extract method" part.

When you get this ready and working exactly like it is working now (meaning no contained items yet) post it here and I'll help you understand the recursive part.
 

AlphaDragon

Sorceror
I thought this is what you ment but I guess not.
Still trying to figure it out :oops::( :
Code:
Errors:
+ Misc/ws-last working on - Copy.cs:
    CS1519: Line 168: Invalid token '(' in class, struct, or interface member de
claration
    CS1519: Line 169: Invalid token '(' in class, struct, or interface member de
claration
Code:
using System;
using System.IO;
using System.Text;
using Server;
using Server.Network;
using Server.Guilds;
 
//
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
//
 
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>" );
               
               
               
               
               
#region player vendors table
               
               
               
               
               
//                op.WriteLine( "PLAYER VENDORS:<br>" );
//                op.WriteLine( "***************************************************************************************<br>" );
//
//                foreach ( Mobile mob in World.Mobiles.Values )
//                {
//                    if ( mob is PlayerVendor )
//                    {
//                        PlayerVendor pv = mob as PlayerVendor;
//                        op.WriteLine( "Owners Name , Shops Name, Vendors Name, Location <br>" );
//                        op.WriteLine( pv.Owner.Name + "," + pv.ShopName + "," + pv.Name + "," + pv.Map + " - " + pv.Location + "<br>" );
//                       
//                       
//                        op.WriteLine("Amount,Item,Price for the Amount,Description<br>");
//                       
//                        foreach (Item item in pv.GetItems())
//                        {
//                            VendorItem vi = pv.GetVendorItem(item);
//                            if (vi != null && vi.IsForSale)
//                            {
//                                if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
//                                    continue;
//                                string ownername = (pv.Name != pv.Owner.Name ? pv.Owner.Name : " ");
//                                string name = item.Name;
//                                if (string.IsNullOrEmpty(name))
//                                {
//                                    name = item.GetType().ToString();
//                                    if (name.LastIndexOf('.') >= 0)
//                                        name = name.Substring(name.LastIndexOf('.') + 1);
//                                }                               
//                                if (name.Length > 25)
//                                    name = name.Substring(0, 25);
//                               
//                                string des = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
//                                op.WriteLine( "{0} {1,-25} {2,7}  {3} <br>", item.Amount, name, vi.Price.ToString(), des );
//                            }
//                        }
//                        op.WriteLine( "---------------------------------------------------------------------------------------<br>" );
//
//                    }
//                    if(mob is PlayerVendor == null)
//                        op.WriteLine( "There are no player vendors in the world at the moment.<br>" );
//                }
//                op.WriteLine( "***************************************************************************************<br>" );
               
               
               
               
               
#endregion player vendors table
           
           
           
           
           
            }
        }
        private void GetVendorItemsDisplay(StreamWriter op, PlayerVendor pv, Item item)
        {
            foreach ( Mobile mob in World.Mobiles.Values )
            {
                if ( mob is PlayerVendor )
                {
                    PlayerVendor pv = mob as PlayerVendor;
                    op.WriteLine( "Owners Name , Shops Name, Vendors Name, Location <br>" );
                    op.WriteLine( pv.Owner.Name + "," + pv.ShopName + "," + pv.Name + "," + pv.Map + " - " + pv.Location + "<br>" );
                   
                   
                    op.WriteLine("Amount,Item,Price for the Amount,Description<br>");
                   
                    foreach (Item item in pv.GetItems())
                    {
                        VendorItem vi = pv.GetVendorItem(item);
                        if (vi != null && vi.IsForSale)
                        {
                            if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
                                continue;
                            string ownername = (pv.Name != pv.Owner.Name ? pv.Owner.Name : " ");
                            string name = item.Name;
                            if (string.IsNullOrEmpty(name))
                            {
                                name = item.GetType().ToString();
                                if (name.LastIndexOf('.') >= 0)
                                    name = name.Substring(name.LastIndexOf('.') + 1);
                            }
                            if (name.Length > 25)
                                name = name.Substring(0, 25);
                           
                            string des = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
                            op.WriteLine( "{0} {1,-25} {2,7}  {3} <br>", item.Amount, name, vi.Price.ToString(), des );
                           
                            {
                            GetVendorItemsDisplay( op, pv, item);
                            }
 
                        }
                    }
                    op.WriteLine( "---------------------------------------------------------------------------------------<br>" );
                }
                if(mob is PlayerVendor == null)
                    op.WriteLine( "There are no player vendors in the world at the moment.<br>" );
                {
                    GetVendorItemsDisplay( op, pv, item);
                }
            }
        }
        op.WriteLine( "  </body>" );
        op.WriteLine( "</html>" );
    }
}
 

daat99

Moderator
Staff member
1. This is exactly why you need Visual C# Express.
It'll tell you exactly what's wrong with it by marking it with a nice little red line under it.

2. see step 4:
4. Copy all the code inside the foreach loop that runs on the pv.GetItems() list into the new method, this is your actual code.
You copied the code in the other foreach loop.

Also, don't forget step 5.
 

AlphaDragon

Sorceror
Code:
Errors:
+ Misc/ws-last working on - Copy.cs:
    CS0136: Line 125: A local variable named 'pv' cannot be declared in this sco
pe because it would give a different meaning to 'pv', which is already used in a
'parent or current' scope to denote something else
Code:
using System;
using System.IO;
using System.Text;
using Server;
using Server.Network;
using Server.Guilds;
 
//
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
//
 
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>" );
               
               
               
               
               
#region player vendors table
               
               
               
               
               
//                op.WriteLine( "PLAYER VENDORS:<br>" );
//                op.WriteLine( "***************************************************************************************<br>" );
//
//                foreach ( Mobile mob in World.Mobiles.Values )
//                {
//                    if ( mob is PlayerVendor )
//                    {
//                        PlayerVendor pv = mob as PlayerVendor;
//                        op.WriteLine( "Owners Name , Shops Name, Vendors Name, Location <br>" );
//                        op.WriteLine( pv.Owner.Name + "," + pv.ShopName + "," + pv.Name + "," + pv.Map + " - " + pv.Location + "<br>" );
//                       
//                       
//                        op.WriteLine("Amount,Item,Price for the Amount,Description<br>");
//                       
//                        foreach (Item item in pv.GetItems())
//                        {
//                            VendorItem vi = pv.GetVendorItem(item);
//                            if (vi != null && vi.IsForSale)
//                            {
//                                if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
//                                    continue;
//                                string ownername = (pv.Name != pv.Owner.Name ? pv.Owner.Name : " ");
//                                string name = item.Name;
//                                if (string.IsNullOrEmpty(name))
//                                {
//                                    name = item.GetType().ToString();
//                                    if (name.LastIndexOf('.') >= 0)
//                                        name = name.Substring(name.LastIndexOf('.') + 1);
//                                }                               
//                                if (name.Length > 25)
//                                    name = name.Substring(0, 25);
//                               
//                                string des = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
//                                op.WriteLine( "{0} {1,-25} {2,7}  {3} <br>", item.Amount, name, vi.Price.ToString(), des );
//                            }
//                        }
//                        op.WriteLine( "---------------------------------------------------------------------------------------<br>" );
//
//                    }
//                    if(mob is PlayerVendor == null)
//                        op.WriteLine( "There are no player vendors in the world at the moment.<br>" );
//                }
//                op.WriteLine( "***************************************************************************************<br>" );
               
               
               
               
               
#endregion player vendors table
           
           
           
           
           
            }
        }
        private void GetVendorItemsDisplay(StreamWriter op, PlayerVendor pv, Item item)
        {
            foreach ( Mobile mob in World.Mobiles.Values )
            {
                if ( mob is PlayerVendor )
                {
                    PlayerVendor pv = mob as PlayerVendor;
                    op.WriteLine( "Owners Name , Shops Name, Vendors Name, Location <br>" );
                    op.WriteLine( pv.Owner.Name + "," + pv.ShopName + "," + pv.Name + "," + pv.Map + " - " + pv.Location + "<br>" );
                   
                   
                    op.WriteLine("Amount,Item,Price for the Amount,Description<br>");
                   
                    op.WriteLine( "---------------------------------------------------------------------------------------<br>" );
                }
                if(mob is PlayerVendor == null)
                    op.WriteLine( "There are no player vendors in the world at the moment.<br>" );
                GetVendorItemsDisplay( op, pv, item);
        op.WriteLine( "  </body>" );
        op.WriteLine( "</html>" );               
            }
        }
    }
}
 

daat99

Moderator
Staff member
You really should start reading what I'm saying.

4. Copy all the code inside the foreach loop that runs on the pv.GetItems() list into the new method, this is your actual code.
Copy only what is INSIDE the foreach loot that RUNS ON pv.GetITems().

The rest of the code should remain exactly as it was before (as in NOT commented out).

Please go back to the code you had before you attempted to follow my 5 steps instructions and follow them to the letter.
What you have now doesn't even come close to what you need to have after following those 5 steps.

Make sure you got your code to look like the example I gave you in that post because if it doesn't than you did something wrong and you need to try again.


If for some reason you think you don't fully understand my instructions than don't be shy and ask for clarifications.
 

AlphaDragon

Sorceror
Not to sure of this cause missing all the other info.
But in the last thing you said, "The rest of the code should remain exactly as it was before (as in NOT commented out)."
I marked it with //HERE?? to see if that is what you mean?
5. Write inside the foreach loop the following line
Code:
GetVendorItemsDisplay( op, pv, item);
so it'll look like this:
Code:
... bla bla ...
op.WriteLine("Amount,Item,Price for the Amount,Description<br>");
foreach (Item item in pv.GetItems())
{
GetVendorItemsDisplay( op, pv, item);
}
op.WriteLine( "---------------------------------------------------------------------------------------<br>" );
... bla bla ...
Code:
using System;
using System.IO;
using System.Text;
using Server;
using Server.Network;
using Server.Guilds;
 
//
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
//
 
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>" );
             
             
             
             
             
#region player vendors table
             
             
             
             
             
                op.WriteLine( "PLAYER VENDORS:<br>" );
                op.WriteLine( "***************************************************************************************<br>" );
 
                foreach ( Mobile mob in World.Mobiles.Values )
                {
                    if ( mob is PlayerVendor )
                    {
                        PlayerVendor pv = mob as PlayerVendor;
                        op.WriteLine( "Owners Name , Shops Name, Vendors Name, Location <br>" );
                        op.WriteLine( pv.Owner.Name + "," + pv.ShopName + "," + pv.Name + "," + pv.Map + " - " + pv.Location + "<br>" );
                     
                     
                        op.WriteLine("Amount,Item,Price for the Amount,Description<br>");
                     
                        foreach (Item item in pv.GetItems())
                        {
                            VendorItem vi = pv.GetVendorItem(item);
                            if (vi != null && vi.IsForSale)
                            {
                                if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
                                    continue;
                                string ownername = (pv.Name != pv.Owner.Name ? pv.Owner.Name : " ");
                                string name = item.Name;
                                if (string.IsNullOrEmpty(name))
                                {
                                    name = item.GetType().ToString();
                                    if (name.LastIndexOf('.') >= 0)
                                        name = name.Substring(name.LastIndexOf('.') + 1);
                                }                             
                                if (name.Length > 25)
                                    name = name.Substring(0, 25);
                             
                                string des = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
                                op.WriteLine( "{0} {1,-25} {2,7}  {3} <br>", item.Amount, name, vi.Price.ToString(), des );
                            }
                            GetVendorItemsDisplay( op, pv, item);//HERE????
                        }

                        op.WriteLine( "---------------------------------------------------------------------------------------<br>" );
 
                    }
                    if(mob is PlayerVendor == null)
                        op.WriteLine( "There are no player vendors in the world at the moment.<br>" );
                }
                op.WriteLine( "***************************************************************************************<br>" );
             
             
             
             
             
#endregion player vendors table
         
         
         
         
         
            op.WriteLine( "  </body>" );
            op.WriteLine( "</html>" );
            }
        }
        
        private void GetVendorItemsDisplay(StreamWriter op, PlayerVendor pv, Item item)
        {
            VendorItem vi = pv.GetVendorItem(item);
            if (vi != null && vi.IsForSale)
            {
                if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
                    continue;
                string ownername = (pv.Name != pv.Owner.Name ? pv.Owner.Name : " ");
                string name = item.Name;
                if (string.IsNullOrEmpty(name))
                {
                    name = item.GetType().ToString();
                    if (name.LastIndexOf('.') >= 0)
                        name = name.Substring(name.LastIndexOf('.') + 1);
                }
                if (name.Length > 25)
                    name = name.Substring(0, 25);
                
                string des = (string.IsNullOrEmpty(vi.Description) ? " " : vi.Description);
                op.WriteLine( "{0} {1,-25} {2,7}  {3} <br>", item.Amount, name, vi.Price.ToString(), des );
            }
        }
    }
}
 
Top