Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 02-08-2010, 09:00 PM   #1 (permalink)
Newbie
 
Join Date: Mar 2008
Age: 20
Posts: 58
Default life time on cloths here my script i need help making it show on cloths

life time on cloths here my script i need help making it show on cloths




HTML Code:
using System;
using Server;

namespace Server.Items
{
	public class apron : Item
	{
		public virtual int Lifespan{ get{ return 0; } }
		
		private int m_Lifespan;
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int TimeLeft
		{
			get{ return m_Lifespan; }
			set{ m_Lifespan = value; InvalidateProperties(); }
		}
	
		[Constructable]
		public apron( ) : base( 0x153b )
		{
			LootType = LootType.Blessed;
		
			if ( Lifespan > 0 )
			{
				m_Lifespan = Lifespan;
				StartTimer();
			}
		}
	
		public apron( Serial serial ) : base( serial )
		{
		}		
		
		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );
			
			if ( Lifespan > 0 )
				list.Add( 1072517, m_Lifespan.ToString() ); // Lifespan: ~1_val~ seconds
		}
		
		private Timer m_Timer;		
		
		public virtual void StartTimer()
		{
			if ( m_Timer != null )
				return;
				
			m_Timer = Timer.DelayCall( TimeSpan.FromSeconds( 10 ), TimeSpan.FromSeconds( 10 ), new TimerCallback( Slice ) );
			m_Timer.Priority = TimerPriority.OneSecond;
		}
		
		public virtual void StopTimer()
		{
			if ( m_Timer != null )
				m_Timer.Stop();

			m_Timer = null;
		}
		
		public virtual void Slice()
		{
			m_Lifespan -= 10;
			
			InvalidateProperties();
			
			if ( m_Lifespan <= 0 )
				Decay();
		}
		
		public virtual void Decay()
		{
			if ( RootParent is Mobile )
			{
				Mobile parent = (Mobile) RootParent;
				
				if ( Name == null )
					parent.SendLocalizedMessage( 1072515, "#" + LabelNumber ); // The ~1_name~ expired...
				else
					parent.SendLocalizedMessage( 1072515, Name ); // The ~1_name~ expired...
					
				Effects.SendLocationParticles( EffectItem.Create( parent.Location, parent.Map, EffectItem.DefaultDuration ), 0x3728, 8, 20, 5042 );
				Effects.PlaySound( parent.Location, parent.Map, 0x201 );
			}
			else
			{
				Effects.SendLocationParticles( EffectItem.Create( Location, Map, EffectItem.DefaultDuration ), 0x3728, 8, 20, 5042 );
				Effects.PlaySound( Location, Map, 0x201 );
			}			
			
			StopTimer();
			Delete();
		}
		
		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
			
			writer.Write( (int) m_Lifespan );
		}
		
		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
			
			m_Lifespan = reader.ReadInt();
			
			StartTimer();
		}
	}
}
crimson420 is offline   Reply With Quote
Old 02-08-2010, 11:22 PM   #2 (permalink)
Master of the Internet
 
Lord_Greywolf's Avatar
 
Join Date: Dec 2005
Posts: 12,196
Send a message via Yahoo to Lord_Greywolf
Default

you all ready have it in there for displaying it:

Code:
		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );
			
			if ( Lifespan > 0 )
				list.Add( 1072517, m_Lifespan.ToString() ); // Lifespan: ~1_val~ seconds
		}
but from what i see in there - it will not be wearable, because it is an "item" and not clothing or armor or the bases of either

you should make it a Apron (full or half based on itemid) and then just remove this part: " : base( 0x153b )
"
that way it can be worn

also using a time for it is not a good idea, get lots of these out there and get lots of timers causing system lag
might want to consider basing it on world saves, or an other timer all ready in use in game
or having checks for it also in basearmor for damage or in the onecraft if used for crafting, etc to wear it out
__________________
http://www.AoAUO.com

:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :)
Lord_Greywolf is offline   Reply With Quote
Old 02-12-2010, 08:39 AM   #3 (permalink)
Newbie
 
Join Date: Mar 2008
Age: 20
Posts: 58
Default

What would a good way to make soo cloths will have time limte to how long some one can have it then it gose away like affter a week
crimson420 is offline   Reply With Quote
Old 02-12-2010, 12:31 PM   #4 (permalink)
Master of the Internet
 
Lord_Greywolf's Avatar
 
Join Date: Dec 2005
Posts: 12,196
Send a message via Yahoo to Lord_Greywolf
Default

just have a creation date for it

add in 2 new variable of
public DateTime creationtime = DateTime.Now;
public double wearabletime = 7.0;
make sure to serialize/deserialize them

then at the end of the reader section add in
if(creationtime + TimeSpan.Days(wearabletime) > DateTime.Now) Delete(); (or something like that - may not be exact)

this way you can also set individual items to have longer/shorter time spans by setting the wearabletime in their constructions to something other than the default

of course you need daily restarts fro this to be any good (and they are smart to have for clearing out memory, unusable items, etc)
__________________
http://www.AoAUO.com

:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :)
Lord_Greywolf is offline   Reply With Quote
Reply

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 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5