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
ok, That helped, I still dont understand it much but kinda figured it out:confused:. I think.
Code:
        private void GetVendorItemsDisplay(StreamWriter op, PlayerVendor pv, Item item)
        {
            VendorItem vi = pv.GetVendorItem(item);
            if ( vi == null )
                return;
         
            if ( vi.IsForSale )
            {
                if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
                    return;
                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 );
            }
            else if ( item is Container)
            {
                foreach ( Item containerItem in pv.Items)
                {
                    op.WriteLine("This is a container item<br>");
                }
            }
        }
Code:
PLAYER VENDORS:
***************************************************************************************
Owners Name , Shops Name, Vendors Name, Location
TESTER,3,fdsfd,Trammel - (3499, 2572, 21)
Amount,Item,Price for the Amount,Description
3 Carrot 3 c
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
fdsfd,2,Beta,Trammel - (3496, 2572, 21)
Amount,Item,Price for the Amount,Description
2 Banana 2 b
2 SulfurousAsh 999
2 GraveDust 999
2 DragonKnight Token 999
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,1,alphas,Trammel - (3494, 2572, 21)
Amount,Item,Price for the Amount,Description
1 Apple 1 a
1 BlackPearl 1
1 RecallRune 2
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,Shop Not Yet Named,Selby,Trammel - (3496, 2570, 21)
Amount,Item,Price for the Amount,Description
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,shopnameBAGER,VENDORNAMEBAGMAN,Trammel - (3497, 2568, 21)
Amount,Item,Price for the Amount,Description
This is a container item
This is a container item
This is a container item
This is a container item
This is a container item
This is a container item
1 DragonKnight Token 120
This is a container item
This is a container item
This is a container item
This is a container item
This is a container item
This is a container item
1 Boots 100 botiesDISCRIPTION
---------------------------------------------------------------------------------------
***************************************************************************************
 

daat99

Moderator
Staff member
Getting close but not yet:
Code:
foreach ( Item containerItem in pv.Items)
You are looping on the items in the player vendor items, not on the items that are in our container which is called "item".
 

AlphaDragon

Sorceror
Code:
foreach ( Item containerItem in item.Items)

Code:
PLAYER VENDORS:
***************************************************************************************
Owners Name , Shops Name, Vendors Name, Location
TESTER,3,fdsfd,Trammel - (3499, 2572, 21)
Amount,Item,Price for the Amount,Description
3 Carrot 3 c
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
fdsfd,2,Beta,Trammel - (3496, 2572, 21)
Amount,Item,Price for the Amount,Description
2 Banana 2 b
2 SulfurousAsh 999
2 GraveDust 999
2 DragonKnight Token 999
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,1,alphas,Trammel - (3494, 2572, 21)
Amount,Item,Price for the Amount,Description
1 Apple 1 a
1 BlackPearl 1
1 RecallRune 2
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,Shop Not Yet Named,Selby,Trammel - (3496, 2570, 21)
Amount,Item,Price for the Amount,Description
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,shopnameBAGER,VENDORNAMEBAGMAN,Trammel - (3497, 2568, 21)
Amount,Item,Price for the Amount,Description
1 DragonKnight Token 120
This is a container item
This is a container item
This is a container item
This is a container item
1 Boots 100 botiesDISCRIPTION
---------------------------------------------------------------------------------------
***************************************************************************************
 

daat99

Moderator
Staff member
Great, now the recursion "magic" begins :)

Recursion is basically "calling ourselves to do part of the work we didn't finish".

What we're going to do is replace the line that prints "This is a container item" with a line that calls us.

In our situation the first parameters (the writer and the vendor) are the same but the item is the new item we're looping on inside the container ("containerItem").
 

daat99

Moderator
Staff member
You remember how you added the call to the method we created in the original loop?

You need to do the same inside the new loop, just with a different item parameter.

Instead of the item parameter you already used, you need to use the "new" item that is inside the container.

Try something, run it, post the code here and the output (if it doesn't freeze).
 

AlphaDragon

Sorceror
:eek: Seems everytime I try to do something, It would seem to start fine, but then the windows would tell me the server core stoped working.
I tried this but got an error:
Code:
GetVendorItemsDisplay( item );//HERE????

Code:
Errors:
+ Misc/ws-last working on - Copy.cs:
    CS1501: Line 133: No overload for method 'GetVendorItemsDisplay' takes '1' a
rguments
 

daat99

Moderator
Staff member
Like the error says, the method doesn't accept a single argument.

Do you remember how many arguments you send the method before?

You still need to send all of them, you just want to replace one with something new.

Please try to understand what you're doing instead of just "making it work".

If you don't understand than ask (specific questions) about what you didn't understand.
 

AlphaDragon

Sorceror
GetVendorItemsDisplay( op, pv, item);

Sending the argument back, did the data have to be sent in reverse?
exz: GetVendorItemsDisplay( item,op, pv);


Am I sending it back to vendoritemsdisplay?

Do I have to make the (containerItem = item) then send it back?

Looked into the CharacterCreation to see but didnt see anything same except for it saying
bla=bla
return item;



Which make me think I need to:
containerItem = item;
return item;


Doing trial and error testing cause I am not sure.
 

AlphaDragon

Sorceror
Code:
            else if ( item is Container)
            {
                foreach ( Item containerItem in item.Items)  containerItem is now the container that is in the original list of items
                {
                    GetVendorItemsDisplay( op, pv, containerItem);   **** How do we know whats in the container? And what to send back?***
//                    op.WriteLine("This is a container item<br>");
                }
            }
 

daat99

Moderator
Staff member
Lets look back:
private void GetVendorItemsDisplay(StreamWriter op, PlayerVendor pv, Item item)

This is the method "signature" (or "declaration") which states what the method return and what it expects to get from the caller.
In this case we have the following:

private: that means the method is known only in our current context (the curly brackets block it's located in) so we can call it only from here.

void: that means the method returns "void" - also known as "nothing" - basically, it doesn't return an answer at all but only do stuff.

StreamWriter, PlayerVendor, Item: these are the types of the arguments the method expects to get in that particular order.
Basically it means that the method expects the first parameter to be an instance of StreamWriter, the 2nd to be PlayerVendor and the 3rd to be an Item​



op, pv, item: these are the names of the parameters that we'll use inside our method.
the name "op" will represent the first argument which is an instance of StreamWriter, the name "pv" will represent the PlayerVendor and the name "item" will represent the Item we work on.​
Now to the recursive call we added:
GetVendorItemsDisplay( op, pv, containerItem);
We want to work with the same StreamWriter we received from our caller so we use the "op" name as the first parameter in our call.
The 2nd parameter needs to be PlayerVendor and we want to work with the same one so we send the same "pv" that we received from our caller.
The last parameter needs to be an Item but if we'll send the same "item" that we got from our caller than we'll do exactly the same thing as before.
Doing that will mean endless loop and shard freezes until it crashes, not good.

So let's think about our code a bit:
foreach ( Item containerItem in item.Items)
We're inside this loop.
What this loop does is running on all the Item's that are inside our container "item".
If we look at the method signature we saw above then we'll see that this is exactly the item we got from our caller.
This item is a container so it has items inside it.

This loop executes the code inside it for every single item in our container items.
In order to have easy access to that item the "foreach" syntax allows us to name the item it currently uses.
In our case we named the item: containerItem.


After understanding that we execute our code on an Item that is called containerItem we can now understand what we need to send as our 3rd parameter.



Now all there is left to do is remove the line that prints the string "this is a container item" and we should be done.

If this still doesn't work than post the entire code again along with the output for further assistance.


And please ask questions if you didn't understand something.
 

AlphaDragon

Sorceror
If you can just check over it, just to make sure. With this code seems things are working.
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())
                        {
                            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 )
                return;
           
            if ( vi.IsForSale )
            {
                if (pv.Owner == null || pv.Owner.Name == "1k5g6se84f895s854f884s6a") //If name same as this it will not show items in list.
                    return;
                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 );
            }
            else if ( item is Container)
            {
                foreach ( Item containerItem in item.Items)
                {
//                    op.WriteLine("This is a container item<br>");
//                    ontick( op, pv, containerItem);//
                    GetVendorItemsDisplay( op, pv, containerItem);//
                }
            }
        }
    }
}

This is what the output file looks like atm:
Output file:
Code:
PLAYER VENDORS:
***************************************************************************************
Owners Name , Shops Name, Vendors Name, Location
TESTER,3,fdsfd,Trammel - (3499, 2572, 21)
Amount,Item,Price for the Amount,Description
3 Carrot 3 c
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
fdsfd,2,Beta,Trammel - (3496, 2572, 21)
Amount,Item,Price for the Amount,Description
2 Banana 2 b
2 SulfurousAsh 999
2 GraveDust 999
2 DragonKnight Token 999
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,1,alphas,Trammel - (3494, 2572, 21)
Amount,Item,Price for the Amount,Description
1 Apple 1 a
1 BlackPearl 1
1 RecallRune 2
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,Shop Not Yet Named,Selby,Trammel - (3496, 2570, 21)
Amount,Item,Price for the Amount,Description
---------------------------------------------------------------------------------------
Owners Name , Shops Name, Vendors Name, Location
AlphaDragon,shopnameBAGER,VENDORNAMEBAGMAN,Trammel - (3497, 2568, 21)
Amount,Item,Price for the Amount,Description
1 DragonKnight Token 120
1 Tinker Contract 121
1 GraveDust 1 Dust in the bag
1 LongPants 305 miami
1 Flying Carpet Magic Lamp 305 carpet
1 Boots 100 botiesDISCRIPTION
1 DragonKnight Token 6 in sixth bag
1 DragonKnight Token 5 in fith bag
1 DragonKnight Token 4 in forth bag
1 DragonKnight Token 3 in thurd bag
1 DragonKnight Token 2 in secondbag
1 DragonKnight Token 1 in main bag
---------------------------------------------------------------------------------------
***************************************************************************************
 

daat99

Moderator
Staff member
Code:
 if(mob is PlayerVendor == null)
op.WriteLine( "There are no player vendors in the world at the moment.<br>" );
You know that this will never happen, right?
Try deleting all the vendors from your world and generate the log.
 

AlphaDragon

Sorceror
I have not got that far in the testing phase :oops:, as soon as I am able I will. Maybe later on this morning, lol I spent another late night messing with programming. Its like 5:30 in the morning now. We will see if I get to that point of checking the (no player vendors) later on this morning.;) IF I DONT PASS OUT FIRST! :p
 

AlphaDragon

Sorceror
Didnt crash, but didnt work either. tried it in a few different places to see what would happen and no go, I think I will end up having to pull it out of there and figure something out. 3 in the afternoon and havnt gone to sleep yet. Seish... But I still feel like I wana pass out. :p
 

Mortis

Knight
A container is the parent item of the items inside it.
An example can be found in PlayerVendor.cs

From PlayerVendor.cs
Code:
        private bool CanBeVendorItem( Item item )
        {
            Item parent = item.Parent as Item;
 
            if ( parent == this.Backpack )
                return true;
 
            if ( parent is Container )
            {
                VendorItem parentVI = GetVendorItem( parent );
 
                if ( parentVI != null )
                    return !parentVI.IsForSale;
            }
 
            return false;
        }
By looking here I was able to get this with a few edits.
Output file:
Code:
PLAYER VENDORS:
***************************************************************************************
Owners Name , Shops Name, Vendors Name, Location
meto,hell,Amabel,Trammel - (3514, 2570, 7)
Amount,Item,Price for the Amount,Description
1 RedSoulstone 10000 soulstone
1 Scissors 15 sissors
3 Bandage 10 bandage
1 BagOfAllReagents -1
This is a container item
50 SpidersSilk 100
1 BagOfAllReagents -1
This is a container item
50 BatWing 30
1 BagOfAllReagents -1
This is a container item
50 Bandage 110
1 MetalChest 500 Chest of Regents
---------------------------------------------------------------------------------------
***************************************************************************************
 
Top