Go Back   RunUO - Ultima Online Emulation > RunUO > Custom Script Release Archive

Custom Script Release Archive This is a pre-script database archive of what our users had released.

 
 
Thread Tools Display Modes
Old 05-24-2005, 05:24 PM   #1 (permalink)
Forum Expert
 
Greystar's Avatar
 
Join Date: Mar 2004
Location: NorthCentral IL, USA
Age: 35
Posts: 3,848
Default Adding DoubleClick to Addons and Making OnChop virtual

Just like the title says...

AddonComponent.cs
Code:
using System;
using Server;

namespace Server.Items
{
	[Server.Engines.Craft.Anvil]
	public class AnvilComponent : AddonComponent
	{
		[Constructable]
		public AnvilComponent( int itemID ) : base( itemID )
		{
		}

		public AnvilComponent( Serial serial ) : base( serial )
		{
		}

		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();
		}
	}

	[Server.Engines.Craft.Forge]
	public class ForgeComponent : AddonComponent
	{
		[Constructable]
		public ForgeComponent( int itemID ) : base( itemID )
		{
		}

		public ForgeComponent( Serial serial ) : base( serial )
		{
		}

		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();
		}
	}

	public class LocalizedAddonComponent : AddonComponent
	{
		private int m_LabelNumber;

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

		public override int LabelNumber{ get{ return m_LabelNumber; } }

		[Constructable]
		public LocalizedAddonComponent( int itemID, int labelNumber ) : base( itemID )
		{
			m_LabelNumber = labelNumber;
		}

		public LocalizedAddonComponent( Serial serial ) : base( serial )
		{
		}

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

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

			writer.Write( (int) m_LabelNumber );
		}

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

			int version = reader.ReadInt();

			switch ( version )
			{
				case 0:
				{
					m_LabelNumber = reader.ReadInt();
					break;
				}
			}
		}
	}

	public class AddonComponent : Item, IChopable
	{
		private Point3D m_Offset;
		private BaseAddon m_Addon;

		[CommandProperty( AccessLevel.GameMaster )]
		public BaseAddon Addon
		{
			get
			{
				return m_Addon;
			}
			set
			{
				m_Addon = value;
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public Point3D Offset
		{
			get
			{
				return m_Offset;
			}
			set
			{
				m_Offset = value;
			}
		}

		[Hue, CommandProperty( AccessLevel.GameMaster )]
		public override int Hue
		{
			get
			{
				return base.Hue;
			}
			set
			{
				base.Hue = value;

				if ( m_Addon != null && m_Addon.ShareHue )
					m_Addon.Hue = value;
			}
		}

		public virtual bool NeedsWall{ get{ return false; } }
		public virtual Point3D WallPosition{ get{ return Point3D.Zero; } }

		[Constructable]
		public AddonComponent( int itemID ) : base( itemID )
		{
			Movable = false;
			ApplyLightTo( this );
		}

		public AddonComponent( Serial serial ) : base( serial )
		{
		}

		public virtual void OnChop( Mobile from )
		{
			if ( m_Addon != null && from.InRange( GetWorldLocation(), 3 ) )
				m_Addon.OnChop( from );
			else
				from.SendLocalizedMessage( 500446 ); // That is too far away.
		}

		public override void OnLocationChange( Point3D old )
		{
			if ( m_Addon != null )
				m_Addon.Location = new Point3D( X - m_Offset.X, Y - m_Offset.Y, Z - m_Offset.Z );
		}

		public override void OnMapChange()
		{
			if ( m_Addon != null )
				m_Addon.Map = Map;
		}

		public override void OnAfterDelete()
		{
			base.OnAfterDelete();

			if ( m_Addon != null )
				m_Addon.Delete();
		}

		public override void OnDoubleClick( Mobile from )
		{
			if ( m_Addon != null )
				m_Addon.OnDoubleClick(from);
			base.OnDoubleClick(from);
		}

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

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

			writer.Write( m_Addon );
			writer.Write( m_Offset );
		}

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

			int version = reader.ReadInt();

			switch ( version )
			{
				case 0:
				{
					m_Addon = reader.ReadItem() as BaseAddon;
					m_Offset = reader.ReadPoint3D();

					if ( m_Addon != null )
						m_Addon.OnComponentLoaded( this );

					ApplyLightTo( this );

					break;
				}
			}
		}

		public static void ApplyLightTo( Item item )
		{
			if ( (item.ItemData.Flags & TileFlag.LightSource) == 0 )
				return; // not a light source

			int itemID = item.ItemID;

			for ( int i = 0; i < m_Entries.Length; ++i )
			{
				LightEntry entry = m_Entries[i];
				int[] toMatch = entry.m_ItemIDs;
				bool contains = false;

				for ( int j = 0; !contains && j < toMatch.Length; ++j )
					contains = ( itemID == toMatch[j] );

				if ( contains )
				{
					item.Light = entry.m_Light;
					return;
				}
			}
		}

		private static LightEntry[] m_Entries = new LightEntry[]
			{
				new LightEntry( LightType.WestSmall, 1122, 1123, 1124, 1141, 1142, 1143, 1144, 1145, 1146, 2347, 2359, 2360, 2361, 2362, 2363, 2364, 2387, 2388, 2389, 2390, 2391, 2392 ),
				new LightEntry( LightType.NorthSmall, 1131, 1133, 1134, 1147, 1148, 1149, 1150, 1151, 1152, 2352, 2373, 2374, 2375, 2376, 2377, 2378, 2401, 2402, 2403, 2404, 2405, 2406 ),
				new LightEntry( LightType.Circle300, 6526, 6538 )
			};

		private class LightEntry
		{
			public LightType m_Light;
			public int[] m_ItemIDs;

			public LightEntry( LightType light, params int[] itemIDs )
			{
				m_Light = light;
				m_ItemIDs = itemIDs;
			}
		}
	}
}
BaseAddon.cs
Code:
using System;
using System.Collections;
using Server;
using Server.Multis;
using Server.Regions;

namespace Server.Items
{
	public enum AddonFitResult
	{
		Valid,
		Blocked,
		NotInHouse,
		DoorsNotClosed,
		DoorTooClose,
		NoWall
	}

	public interface IAddon
	{
		Item Deed{ get; }

		bool CouldFit( IPoint3D p, Map map );
	}

	public abstract class BaseAddon : Item, IChopable, IAddon
	{
		private ArrayList m_Components;

		public void AddComponent( AddonComponent c, int x, int y, int z )
		{
			if ( Deleted )
				return;

			m_Components.Add( c );

			c.Addon = this;
			c.Offset = new Point3D( x, y, z );
			c.MoveToWorld( new Point3D( X + x, Y + y, Z + z ), Map );
		}

		public BaseAddon() : base( 1 )
		{
			Movable = false;
			Visible = false;

			m_Components = new ArrayList();
		}

		public virtual bool RetainDeedHue{ get{ return false; } }

		public virtual void OnChop( Mobile from )
		{
			BaseHouse house = BaseHouse.FindHouseAt( this );

			if ( house != null && house.IsOwner( from ) && house.Addons.Contains( this ) )
			{
				Effects.PlaySound( GetWorldLocation(), Map, 0x3B3 );
				from.SendLocalizedMessage( 500461 ); // You destroy the item.

				int hue = 0;

				if ( RetainDeedHue )
				{
					for ( int i = 0; hue == 0 && i < m_Components.Count; ++i )
					{
						AddonComponent c = (AddonComponent)m_Components[i];

						if ( c.Hue != 0 )
							hue = c.Hue;
					}
				}

				Delete();

				house.Addons.Remove( this );

				BaseAddonDeed deed = Deed;

				if ( deed != null )
				{
					if ( RetainDeedHue )
						deed.Hue = hue;

					from.AddToBackpack( deed );
				}
			}
		}

		public virtual BaseAddonDeed Deed{ get{ return null; } }

		Item IAddon.Deed
		{
			get{ return this.Deed; }
		}

		public ArrayList Components
		{
			get
			{
				return m_Components;
			}
		}

		public BaseAddon( Serial serial ) : base( serial )
		{
		}

		public bool CouldFit( IPoint3D p, Map map )
		{
			ArrayList houses = null;

			return ( CouldFit( p, map, null, ref houses ) == AddonFitResult.Valid );
		}

		public AddonFitResult CouldFit( IPoint3D p, Map map, Mobile from, ref ArrayList houseList )
		{
			if ( Deleted )
				return AddonFitResult.Blocked;

			ArrayList houses = new ArrayList();

			foreach ( AddonComponent c in m_Components )
			{
				Point3D p3D = new Point3D( p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z );

				if ( !map.CanFit( p3D.X, p3D.Y, p3D.Z, c.ItemData.Height, false, true, ( c.Z == 0 ) ) )
					return AddonFitResult.Blocked;
				else if ( !CheckHouse( from, p3D, map, c.ItemData.Height, houses ) )
					return AddonFitResult.NotInHouse;

				if ( c.NeedsWall )
				{
					Point3D wall = c.WallPosition;

					if ( !IsWall( p3D.X + wall.X, p3D.Y + wall.Y, p3D.Z + wall.Z, map ) )
						return AddonFitResult.NoWall;
				}
			}

			foreach ( BaseHouse house in houses )
			{
				ArrayList doors = house.Doors;

				for ( int i = 0; i < doors.Count; ++i )
				{
					BaseDoor door = doors[i] as BaseDoor;

					if ( door != null && door.Open )
						return AddonFitResult.DoorsNotClosed;

					Point3D doorLoc = door.GetWorldLocation();
					int doorHeight = door.ItemData.CalcHeight;

					foreach ( AddonComponent c in m_Components )
					{
						Point3D addonLoc = new Point3D( p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z );
						int addonHeight = c.ItemData.CalcHeight;

						if ( Utility.InRange( doorLoc, addonLoc, 1 ) && (addonLoc.Z == doorLoc.Z || ((addonLoc.Z + addonHeight) > doorLoc.Z && (doorLoc.Z + doorHeight) > addonLoc.Z)) )
							return AddonFitResult.DoorTooClose;
					}
				}
			}

			houseList = houses;
			return AddonFitResult.Valid;
		}

		public bool CheckHouse( Mobile from, Point3D p, Map map, int height, ArrayList list )
		{
			if ( from == null || from.AccessLevel >= AccessLevel.GameMaster )
				return true;

			BaseHouse house = BaseHouse.FindHouseAt( p, map, height );

			if ( house == null || !house.IsOwner( from ) )
				return false;

			if ( !list.Contains( house ) )
				list.Add( house );

			return true;
		}

		public static bool IsWall( int x, int y, int z, Map map )
		{
			if ( map == null )
				return false;

			Tile[] tiles = map.Tiles.GetStaticTiles( x, y, true );

			for ( int i = 0; i < tiles.Length; ++i )
			{
				Tile t = tiles[i];
				ItemData id = TileData.ItemTable[t.ID & 0x3FFF];

				if ( (id.Flags & TileFlag.Wall) != 0 && (z + 16) > t.Z && (t.Z + t.Height) > z )
					return true;
			}

			return false;
		}

		public virtual void OnComponentLoaded( AddonComponent c )
		{
		}

		public override void OnLocationChange( Point3D oldLoc )
		{
			if ( Deleted )
				return;

			foreach ( AddonComponent c in m_Components )
				c.Location = new Point3D( X + c.Offset.X, Y + c.Offset.Y, Z + c.Offset.Z );
		}

		public override void OnMapChange()
		{
			if ( Deleted )
				return;

			foreach ( AddonComponent c in m_Components )
				c.Map = Map;
		}

		public override void OnAfterDelete()
		{
			base.OnAfterDelete();

			foreach ( AddonComponent c in m_Components )
				c.Delete();
		}

		public override void OnDoubleClick( Mobile from )
		{
			base.OnDoubleClick(from);
		}

		public virtual bool ShareHue{ get{ return true; } }

		[Hue, CommandProperty( AccessLevel.GameMaster )]
		public override int Hue
		{
			get
			{
				return base.Hue;
			}
			set
			{
				if ( base.Hue != value )
				{
					base.Hue = value;

					if ( !Deleted && this.ShareHue && m_Components != null )
					{
						foreach ( AddonComponent c in m_Components )
							c.Hue = value;
					}
				}
			}
		}

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

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

			writer.WriteItemList( m_Components );
		}

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

			int version = reader.ReadInt();

			switch ( version )
			{
				case 0:
				{
					m_Components = reader.ReadItemList();
					break;
				}
			}
		}
	}
}
makes it much easier to make custom Addons redeedable also attaching a sample of why I did it like this. These modded files are also attached.
Attached Files
File Type: cs BaseAddon.cs (6.1 KB, 77 views)
File Type: cs AddonComponent.cs (5.7 KB, 79 views)
File Type: cs FancyLamp.cs (24.3 KB, 79 views)
__________________
Quote:
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.
Killable Guards (GS Version)
Just a Simple Staff Tool
You can leave me messages.
Ernest Gary Gygax - Quote "I would like the world to remember me as the guy who really enjoyed playing games and sharing his knowledge and his fun pastimes with everybody else."
Greystar is offline  
Old 05-24-2005, 11:00 PM   #2 (permalink)
 
Join Date: Oct 2002
Age: 23
Posts: 4,689
Default

Oh ya... I think I did that once but lost it. Man, see this is something that needs to be in the RunUO distro. This may be a stupid question, but I haven't taken a look at this part of RunUO for a while. Would putting this in nuke addons that you already have made without this system? Doesn't apply to me... but its a good question to answer for the newbs

Nice job greystar. I would give you +rep because its distro-usable, but I have to spread my love around first.
XxSP1DERxX is offline  
Old 05-25-2005, 02:32 AM   #3 (permalink)
Forum Expert
 
Marak's Avatar
 
Join Date: Mar 2005
Location: Firmly Seated Infront of the Computer.
Age: 25
Posts: 429
Default

Nice one buddy - we have a heap of cust deeds and this will help

Quote:
but I have to spread my love around first.
shudders....
Marak is offline  
Old 05-25-2005, 01:38 PM   #4 (permalink)
Forum Expert
 
Greystar's Avatar
 
Join Date: Mar 2004
Location: NorthCentral IL, USA
Age: 35
Posts: 3,848
Default

Quote:
Originally Posted by XxSP1DERxX
Oh ya... I think I did that once but lost it. Man, see this is something that needs to be in the RunUO distro. This may be a stupid question, but I haven't taken a look at this part of RunUO for a while. Would putting this in nuke addons that you already have made without this system? Doesn't apply to me... but its a good question to answer for the newbs

Nice job greystar. I would give you +rep because its distro-usable, but I have to spread my love around first.

No it will not nuke already existing addons, no affect on them to my knowledge.. after all it really shouldnt since OnChop now being virtual doesnt really change it it just makes it overridable and adding DClick method to it doesnt really change anything either so it shouldnt have any affect... no new props for ser/deser and no other changes to affect any other Addons.

after messing with this though it gave me a whole bunch of ideas for other things since modding this file is so easy and doesnt kill existing addons, especially if you know how to poperly ser/deser... the next thing I might do is incoroporate the light stuff directly into the addon stuff so you can more fluidly make custom lights that work like normal lights. Especially with the Addon someone made for the Gargoyle Light and heatsource, etc...
__________________
Quote:
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.
Killable Guards (GS Version)
Just a Simple Staff Tool
You can leave me messages.
Ernest Gary Gygax - Quote "I would like the world to remember me as the guy who really enjoyed playing games and sharing his knowledge and his fun pastimes with everybody else."
Greystar is offline  
Old 08-13-2005, 07:54 PM   #5 (permalink)
Forum Novice
 
Join Date: Jun 2005
Age: 30
Posts: 111
Default This Script doesnt work for me at all

This Script doesnt work for me at all. I copy and pasted your 2 files over mine and when i use an axe on deeds nothing happens. i even tried clicking the addons and nothing
Dave1969 is offline  
Old 08-13-2005, 08:14 PM   #6 (permalink)
Forum Expert
 
Tannis's Avatar
 
Join Date: Feb 2004
Age: 27
Posts: 2,047
Default

The title says adding DoubleClick, so having not tested these out, try just double clicking the addon to tear it down.
Tannis is offline  
Old 08-13-2005, 11:37 PM   #7 (permalink)
Forum Novice
 
Join Date: Jun 2005
Age: 30
Posts: 111
Default Ive done double click and still nothing

Ive done double click and still nothing
Dave1969 is offline  
Old 08-14-2005, 01:02 AM   #8 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 27
Posts: 1,834
Default

1st off be sure to have AccessLevel = AccessLevel.Player on yourself... being staffie kinda messes up placing addons. :P
You still need to chop with an axe to redeed something. I didnt really look at the script... Addons give me creeps since I tried to make a ContainerAddonComponent... hehe
Kamuflaro is offline  
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5