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!

Is There A Complete PlayerVendor Search Command Available?

tiffanynation

Wanderer
Looking to make a custom script that will let players search for items that other players
are selling... A script like this would be very usefull... Players would no longer have to
visit all of the PlayerVendors in the world and look in each bag, just to see what's available...


So far I've been able to CallFor & Return values for all the PlayerVendors in the world...
How would I CallFor & Return values for all of the VendorItems that they are holding?
Example: (VendorItem) (VendorItemPrice) (VendorItemDescription) ect...

This is the working code that I have so far:

Code:
///////////////////
//Write Search Results To File
///////////////////
StreamWriter PlayerVendorFile = new StreamWriter("c:\\PlayerVendorFile.txt");
ArrayList list = new ArrayList();
foreach ( Mobile mob in World.Mobiles.Values )
{
    if ( mob is PlayerVendor )
    {
        PlayerVendor pv = mob as PlayerVendor;
        list.Add( pv );
        PlayerVendorFile.WriteLine( pv );
        PlayerVendorFile.WriteLine( pv.ShopName );
        PlayerVendorFile.WriteLine( pv.Name );
        PlayerVendorFile.WriteLine( pv.Owner.Name );
        PlayerVendorFile.WriteLine( pv.Map );
        PlayerVendorFile.WriteLine( pv.Backpack );
        PlayerVendorFile.WriteLine( pv.AccessLevel );
        PlayerVendorFile.WriteLine( pv.Location );
        PlayerVendorFile.WriteLine( pv.X );
        PlayerVendorFile.WriteLine( pv.Y );
        PlayerVendorFile.WriteLine( pv.Z );
        PlayerVendorFile.WriteLine( pv.RawName );
        PlayerVendorFile.WriteLine( "---------------"
    }
}
PlayerVendorFile.Close();
 

Paradyme

Page
This is the one I use. Took awhile to get working, had this for 3-4 years now so im not too sure who the original author is. First part is the gump and the second script searches all vendors and makes a database for the gump. All you have to do is trigger the database on a worldsave or on a timer, whatever you think is appropriate. Should give you a starting point to make a better version.

PHP:
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using System.IO;
using Server.Commands;
using Server.Items;
using Server.Network;
using Server.Prompts;
using Server.Multis;
using Server.Targeting;
using Server.Accounting;
using Server.Gumps;
using Server.Mobiles;

namespace Server.Gumps
{

    public class SearchVendorGump : Gump
    {

        public static void Initialize()
        {
            CommandSystem.Register( "SV", AccessLevel.Player, new CommandEventHandler( SearchVendor_OnCommand ) );
        }

        [Usage( "SV <string>" )]
        [Description( "Finds vendor items." )]
        public static void SearchVendor_OnCommand( CommandEventArgs e )
        {
            if ( e.Length != 1 )
            {
                e.Mobile.SendMessage( "Format: SV <min 3 character string>" );
                return;
            }
            Mobile from = e.Mobile;
            ArrayList list = new ArrayList();
            string searchValue = "";
            string str = "";

            for ( int i = 0; i < e.Length; i++ )
            {
                str = e.GetString( i ).ToLower();
            }
            searchValue = str;
            if ( searchValue.Length < 3 )
            {
                e.Mobile.SendMessage( "Format: SV <min 3 character string>" );
                return;
            }

            string cfg = Path.Combine( Core.BaseDirectory, "PVI.log" );

            if ( !File.Exists( cfg ) )
            {
                from.SendMessage( "Vendor Inventory file not available." );
                return;
            }
            else
            {
                from.SendMessage( "Searching Vendors, please wait." );

                using ( StreamReader ip = new StreamReader( cfg ) )
                {
                    string line;

                    while ( (line = ip.ReadLine()) != null )
                    {
                        if ( line.ToLower().IndexOf( searchValue ) >= 0 )
                        {
                            list.Add( line );
                        }
                    }
                }
            }
            e.Mobile.SendGump( new SearchVendorGump( e.Mobile, list, 1 ) );
        }

        private ArrayList m_List;
        private int m_DefaultIndex;
        private int m_Page;
        private Mobile m_From;

        public SearchVendorGump( Mobile from, ArrayList list, int page ) : base( 50, 40 )
        {
            from.CloseGump( typeof( SearchVendorGump ) );
            int itemsfound = 0;
            m_Page = page;
            m_From = from;
            int pageCount = 0;
            m_List = list;

            AddPage( 0 );

            AddBackground( 0, 0, 740, 315, 9270 );
            AddBackground( 10, 10, 720, 280, 3000 );

            if ( m_List == null )
            {
                return;
            }
            else
            {
                itemsfound = list.Count;

                if ( list.Count % 12 == 0 )
                {
                    pageCount = (list.Count / 12);
                }
                else
                {
                    pageCount = (list.Count / 12) + 1;
                }
            }

            AddLabelCropped( 32, 16, 120, 20, 1152, "Vendor" );
            AddLabelCropped( 150,16, 120, 20, 1152, "House");
            AddLabelCropped( 268,16, 120, 20, 1152, "Item");
            AddLabelCropped( 440, 16, 120, 20, 1152, "Price" );
            AddLabelCropped( 490, 16, 120, 20, 1152, "Description" );
            AddLabel( 80, 287, 93, String.Format(  "Vendor Search              {0} items found", itemsfound ));

            if ( page > 1 )
                AddButton( 570, 18, 0x15E3, 0x15E7, 1, GumpButtonType.Reply, 0 );
            else
                AddImage( 570, 18, 0x25EA );

            if ( pageCount > page )
                AddButton( 587, 18, 0x15E1, 0x15E5, 2, GumpButtonType.Reply, 0 );
            else
                AddImage( 587, 18, 0x25E6 );

            if ( m_List.Count == 0 )
                AddLabel( 135, 80, 1152, "Nothing found to match your request." );

            if ( page == pageCount )
            {
                for ( int i = (page * 12) -12; i < itemsfound; ++i )
                    AddDetails( i, from );
            }
            else
            {
                for ( int i = (page * 12) -12; i < page * 12; ++ i )
                    AddDetails( i, from );
            }
        }

        private void AddDetails( int index, Mobile from )
        {
            string owner;
            if ( index < m_List.Count )
            {
                try
                {

                int row;
                string line = m_List[index].ToString();
                int linelength = line.Length;
                int desclength = linelength - 67;
                if ( desclength > 35 )
                    desclength = 35;

                row = index % 12;
                string ssvendor = line.Substring( 0, 16 );
                string ssowner = line.Substring (17, 16 );
                string ssitem = line.Substring( 34, 25 );
                string ssprice = line.Substring( 60, 7 );
                string ssdesc = line.Substring( 67, desclength );

                AddLabel(32, 40 +(row * 20), 395, String.Format( "{0}", ssvendor ));
                AddLabel(150, 40 +(row * 20), 395, String.Format( "{0}", ssowner ));
                AddLabel(268, 40 +(row * 20), 395, String.Format( "{0}", ssitem ));
                AddLabel(423, 40 +(row * 20), 395, String.Format( "{0}", ssprice ));
                AddLabel(483, 40 +(row * 20), 395, String.Format( "{0}", ssdesc ));

                }
                catch {}
            }
        }

        public override void OnResponse( NetState state, RelayInfo info )
        {
            Mobile from = state.Mobile;

            int buttonID = info.ButtonID;
            if ( buttonID == 2 )
            {
                m_Page ++;
                from.CloseGump( typeof( SearchVendorGump ) );
                from.SendGump( new SearchVendorGump( from, m_List, m_Page ) );
            }
            if ( buttonID == 1 )
            {
                m_Page --;
                from.CloseGump( typeof( SearchVendorGump ) );
                from.SendGump( new SearchVendorGump( from, m_List, m_Page ) );
            }
        }
    }
}

PHP:
using System;
using System.IO;
using System.Collections;
using Server;
using Server.Commands;
using Server.Network;
using Server.Guilds;
using Server.Multis;
using Server.Items;
using Server.Mobiles;
using Server.Accounting;

namespace Server.Misc
{
    public class PVI
    {
        public static void Initialize()
        {
            CommandSystem.Register( "PVI", AccessLevel.Administrator, new CommandEventHandler( PVI_OnCommand ) );
        }

        private static void PVI_OnCommand( CommandEventArgs args )
        {
            using ( StreamWriter op = new StreamWriter( "PVI.log" ) )
            {
                op.WriteLine( "Vendor          Owner            Item                        Price  Description" );

                foreach( Item item in World.Items.Values )
                {
                    Type type = item.GetType();
                    string typ = type.ToString();
                    string des = null;
                    //string name = null; // vi name

            try{

                    string[] words = typ.Split('.');

                    if ( item.RootParent is PlayerVendor )
                    {

                        PlayerVendor vendor = (PlayerVendor)item.RootParent;

                        VendorItem vi = vendor.GetVendorItem( item );

                        if ( vi != null && vi.IsForSale )
                        {
                        if ( vendor.Owner.Name != "Bob" )
                        {
                            string ownername = " ";
                            string name = null; //item.Name.ToString();
                        //    string lname = " ";
                            string nam = words[words.Length - 1];
                            if ( item.Name == null )
                            {
                                name = nam;
                            }
                            else
                            {
                                name = item.Name.ToString();
                            }

                            if ( vi.Description != null && vi.Description != "" )
                                des = vi.Description;
                            else
                                des = " ";

                            if ( name.Length > 25 )
                            {
                            //    lname = name;
                                name = name.Substring( 0, 25 );
                            }
                            if ( vendor.Name != vendor.Owner.Name )
                                ownername = vendor.Owner.Name;

                            op.WriteLine( "{0,-16} {1,-16} {2,-25} {3,7} {4}", vendor.Name, ownername, name, vi.Price.ToString(), des );
                        }
                        }
                    }
            } catch{op.WriteLine("error {0}", typ);}
                }

        args.Mobile.SendMessage( "Report done <runuo root>/PVI.log" );
            }
        }
    }
}

Players use the command [sv "string" so can search for keywords in the database.
 

daat99

Moderator
Staff member
Won't it be better to create the database by looping on the world mobiles (and check for vendors) and get their items instead of looping on the items, check if they are on a vendor, get the VendorItem....?

There are a lot less mobiles in the world than items.
 

Acronis

Sorceror
What I would do is modify the vendor script itself so that when an item is added to a vendor, an entry is also added to a dictionary. Make a new class called VendorItemEntry or something and it would contain the item as well as other info such as the vendor, location etc. Then you just need to loop through that dictionary.
 
Top