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!

Creating an ArrayList O_o

Vorspire

Knight
Creating an ArrayList :confused:

i want a deed, on double click to get all equiped ARMOR parts (helm, chest, gorget, arms, gloves, legs and shield) and put them in an arraylist so that later on they can be hued. Im not sure on ArrayLists, they confuse me, but here's my attempt anyway...

if someone could tell me how to search each individual part and add it to the ArrayList, i would be greatful, thanks in advance :>

Code:
				case (int)Buttons.Okay:
				{					
					
					TextRelay relay = info.GetTextEntry( 0 );
					string hueno = ( relay == null ? null : relay.Text.Trim() );

					if ( hueno.Length <= 4 )
					{
						
						ArrayList equipitems = new ArrayList( pm.BaseArmor );
						foreach (BaseArmor arpart in equipitems)

							if( pm != null )
							{
								if ((arpart.Layer != Layer.Helm) && (arpart.Layer != Layer.InnerTorso) && (arpart.Layer != Layer.Neck) && (arpart.Layer != Layer.Pants) && (arpart.Layer != Layer.Gloves) && (arpart.Layer != Layer.Arms))
								{			

									arpart.Hue = Utility.ToInt32( relay.Text );
							
									pm.SendMessage("Your Armor Set has been recolored.");
									FARD.Delete();
								}
							}
								else
								{
									pm.SendMessage("Unable to recolor your Armor Set at this time.");
								}
							}
							else
							{
								pm.SendMessage("Hue code too long. Must be a 4-digit number.");
							}
			
							break;
						}
 

Murzin

Knight
1) im not seeing any null checks... what if they dont have something equipped to that layer?

2) your best bet is to create the array list, then add each equipped item if something is equipped there, and then hue everything in the array list.

3) where is FARD defined?

4) your break; statement is defined in the wrong place without enough of them for rock solid code.
 

Vorspire

Knight
could you sort this script out a bit for me? im not sure about rock solid code :)

heres the whole script.. i dont know how to write an array list, and im not quite sure how to do the null checks. but heres the full script :)

i removed all traces of the ArrayList because i messed it up so badly :(

Code:
using System;
using Server;
using Server.Items;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
using System.IO;
using System.Collections;

namespace Server.Items
{
	public class FullArmorRecolorDeed : BaseItem
	{
		public FullArmorRecolorDeed deed;
		public int m_HueNumber = 2047;

		[Constructable]
		public FullArmorRecolorDeed() : base( 0x14F0 )
		{
			Name = "a Full Armor Recolor Deed";
			Hue = 0;
			Weight = 0.0;
			LootType = LootType.Regular;
		}
		
		public FullArmorRecolorDeed( Serial serial ) : base( serial )
		{
		}

		[CommandProperty(AccessLevel.GameMaster)]
		public int HueNumber 
		{
			get { return m_HueNumber; }
			set { m_HueNumber = value; InvalidateProperties(); }
		}

		public override void OnDoubleClick(Mobile from)
		{
			PlayerMobile pm = from as PlayerMobile;

					
			if(pm != null)
			{
				if(IsChildOf(from.Backpack))
				{
					from.SendGump(new FullArmorRecolorDeedGump( this, pm ));
				}
				else
				{
					from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
				}
			}
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
		}
	}
}

namespace Server.Items
{
	public class FullArmorRecolorDeedGump : Gump
	{
		private PlayerMobile pm;
		private FullArmorRecolorDeed FARD;
		private int hueno;

		public FullArmorRecolorDeedGump( FullArmorRecolorDeed deed, PlayerMobile p )
			: base( 100, 100 )
		{


			pm = p;
			FARD = deed;

			this.Closable=false;
			this.Disposable=false;
			this.Dragable=false;
			this.Resizable=false;

			this.AddPage(0);
			this.AddBackground(183, 168, 337, 151, 9270);
			this.AddLabel(204, 184, 52, @"Type a hue number to dye your Armor Set.");
			this.AddLabel(204, 203, 52, @"Typing words or letters will delete your deed!");
			this.AddImage(269, 233, 2440);
			this.AddTextEntry(306, 234, 93, 16, 32, (int)Buttons.TextEntry, deed.m_HueNumber.ToString());
			this.AddButton(421, 269, 247, 248, (int)Buttons.Okay, GumpButtonType.Reply, 0);
			this.AddButton(222, 269, 241, 242, (int)Buttons.Cancel, GumpButtonType.Reply, 0);
			this.AddLabel(313, 271, 52, @"Alternate-PK");

		}

		
		public enum Buttons
		{
			TextEntry,
			Okay,
			Cancel,
		}

		public override void OnResponse( NetState sender, RelayInfo info )
		{
			int button = info.ButtonID;
		{

			switch(button) 
			{
				case (int)Buttons.TextEntry:
				{	

				}
					break;


				case (int)Buttons.Okay:
				{					
					
					TextRelay relay = info.GetTextEntry( 0 );
					string hueno = ( relay == null ? null : relay.Text.Trim() );
					
					if ( hueno.Length <= 4 )
					{
						if( pm != null )
						{
							foreach(BaseArmor armor in equipitems)
							{
								armor.Hue = Utility.ToInt32( relay.Text );
							}	

							pm.SendMessage("Your Armor Set has been recolored.");
							FARD.Delete();
						}
						else
						{
							pm.SendMessage("Unable to recolor your Armor Set at this time.");
						}
					}
					else
					{
						pm.SendMessage("Hue code too long. Must be a 4-digit number.");
					}
			
					break;
				}

						case (int)Buttons.Cancel:
												{					
					

													if(pm != null)
													{
														pm.SendMessage("You cancelled the recoloring process.");
													}
													break;
												}
					}
				}
			}
		}
	}
 
Top