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!

Find item in player's backpack

Rox666

Sorceror
Hi all,

I've try to find in this forum some informations about the topic of my post, but I didn't find anything about it.

I need to find a way to search a specific item in player's backpack when I use a command because this item have some attributes that I need to recall.

I don't understend why I can have some function like Container pack = m_Player.Backpack; for targeting the player's backpack, but no one to find something except Item[] FindItemsByType( Type type ) but if I don't know the specific Type, I can't do nothing.

Who can help me? :confused:

tnx!!
 

Kouri

Squire
Not sure if this is exactly what your looking for but it might be a start.

You might try looking at Orc.cs, where it calls out for the OrcishKinMask.

Code:
public override bool IsEnemy( Mobile m )
{
if ( m.Player && m.FindItemOnLayer( Layer.Helm ) is OrcishKinMask )
return false;
 
return base.IsEnemy( m );
}

That one is looking for an item that is being worn, but I'm sure there is a work around to make it check someones pack.
 

zerodowned

Sorceror
fyi, a quick search easily finds your answer.

i prefer google because it's search results seem more accurate if you tell it to only search a specific site

search this: site:runuo.com/community find item in backpack

first result is this http://www.runuo.com/community/threads/find-item-in-backpack.27941/

hehe.
here, take a look at this code. It does what you want. It will even search recursively through other containers that are in the container you start with. If you only want to search the top level of the container, just cut out the recursive container test conditional.

Code:
public Item SearchPackForItem(Container pack, string targetName)
        {
          if(pack != null && !pack.Deleted && targetName != null && targetName.Length > 0){
            // go through all of the items in the pack
            ArrayList packlist = pack.Items;
 
            for ( int i = 0; i < packlist.Count; ++i )
            {
            Item item = (Item)packlist[i];
            if(item != null && !item.Deleted && item is Container){
                                    Item itemTarget = SearchPackForItem((Container)item, targetName);
                                    if(itemTarget != null) return itemTarget;
                            } else
            // test the item name against the string
            if(item != null && !item.Deleted && (item.Name != null) && (item.Name == targetName)){
                                //found it
                                return item;
            }
            }
                  }
                  return null;
        }
 

zerodowned

Sorceror
I need to find a way to search a specific item in player's backpack when I use a command because this item have some attributes that I need to recall.

wait, are you saying you want to search for an item in a player's backpack and return the value of the properties of that item?

like search a player's pack and see if they have an item that has an LRC property?
 

Rox666

Sorceror
wait, are you saying you want to search for an item in a player's backpack and return the value of the properties of that item?

like search a player's pack and see if they have an item that has an LRC property?
Hello!
Tnx to all for the replay! I'll use the google search method in the future!!

Anyway, yes it's my goal! But I don't know what is an LRC propriety XD but if is a propriety that I create for an item and that I can change in game like Mobile Str, yes, is what I need!
I've create an object that is in player'backpack and this item collect some informations about the character!
Using a special command I can show to the player some informations usefull for him!
I'll try the script of zerodowned!
Tnx all!
 

Rox666

Sorceror
fyi, a quick search easily finds your answer.

i prefer google because it's search results seem more accurate if you tell it to only search a specific site

search this: site:runuo.com/community find item in backpack

first result is this http://www.runuo.com/community/threads/find-item-in-backpack.27941/

Hi! I finaly try this script, but doesn't work! I think it doesn't work because I'm using "m_Player.Backpack" for "SearchPackForItem(Container pack, string targetName)".
To be more faster, I paste my code:

Code:
using System;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Multis;
using Server.Targeting;
 
namespace Server.Commands
{
    public class SuperHuman
    {
        private static Item m_PlayerBook;
        private static Mobile m_Player;
   
        public static void Initialize()
        {
            CommandSystem.Register( "Superhuman", AccessLevel.Player, new CommandEventHandler( SuperHuman_Command ) );
        }
 
        [Usage( "Superhuman" )]
        [Description( "Super-Uomo: aumenta il proprio potere per due minuti." )]
        private static void SuperHuman_Command( CommandEventArgs e )
        {
            m_Player = e.Mobile;
            string NamePB = "Player Book - Proprietario: "+ m_Player.Name;
            m_PlayerBook = SearchPackForItem( m_Player.Backpack, NamePB );
            if( m_PlayerBook != null )
            {
                m_Player.Emote( " SHU-OH-MAH! " );
                m_Player.SendMessage( "Super-Uomo: aumenta il proprio potere per due minuti." );
            }
        }
   
        private Item SearchPackForItem(Container pack, string targetName)
        {
            if(pack != null && !pack.Deleted && targetName != null && targetName.Length > 0)
            {
            // go through all of the items in the pack
                ArrayList packlist = pack.Items;
 
                for ( int i = 0; i < packlist.Count; ++i )
                {
                    Item item = (Item)packlist[i];
                    if(item != null && !item.Deleted && item is Container)
                    {
                        Item itemTarget = SearchPackForItem((Container)item, targetName);
                        if(itemTarget != null)
                            return itemTarget;
                    } else
                    {
                        // test the item name against the string
                        if(item != null && !item.Deleted && (item.Name != null) && (item.Name == targetName))
                        {
                            //found it
                            return item;
                        }
                    }
                }
            }
       
            return null;
        }   
    }
}

I'm sure there is an error here, but I'm not so good to find it!
 

Rox666

Sorceror
RESOLVED!!!

I used the Bittiez's library and next I chanded the code like this:

Code:
   m_Player = e.Mobile;
            List<Item> ItemsPack = Bittiez.Tools.List_Items_In_Container( (BaseContainer)m_Player.Backpack, true );
           
            if( ItemsPack.Count > 0 )
            {
                foreach (Item iteman in ItemsPack)
                {
                    if(iteman is PlayerBook)
                    {
                    m_Player.Emote( " SHU-OH-MAH! " );
                    m_Player.SendMessage( "Super-Uomo: aumenta il proprio potere per due minuti." );
                    }
                }
           
            }else { m_Player.SendMessage( "Nessun Oggetto Trovato." ); }

using a Foreach method and not for! More easy :p

tnx you all!!
 
Top