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 09-28-2008, 12:09 PM   #1 (permalink)
Forum Novice
 
Macil's Avatar
 
Join Date: Oct 2003
Location: Harper Woods, Michigan
Age: 21
Posts: 815
Send a message via ICQ to Macil Send a message via AIM to Macil
Default Recharge Crystal Overcharges Items

I'm trying to make a crystal that will recharge a glacial staff with 50 charges, but not allow the staff to ever go past 50 charges total. I used another script I had for a deed that added magic attributes to weapons/armor and modified it since it was similar in design.

At any rate, it works, but it over charges my Glacial Staffs past 50. How do I make it stop at 50?

Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Items;
using Server.Targeting;
using Server;

namespace Server.Items
{
	public class MagicIceCrystalTarget : Target
	{
		private MagicIceCrystal m_Deed;

		public MagicIceCrystalTarget( MagicIceCrystal deed ) : base( 1, false, TargetFlags.None )
		{
			m_Deed = deed;
		}

		protected override void OnTarget( Mobile from, object target )
		{
			if ( target is GlacialStaff )
			
						if(target is GlacialStaff)
			
			{
 			
				Item item = (Item)target;

				if ( ((GlacialStaff)item).Charges == 50 )
				{
					from.SendMessage( "That Glacial Staff has enough charges already!");
				}
				else
				{
					if( item.RootParent != from )
					{
						from.SendMessage( "That item must be in your pack to use this." );
					}
					else
					{
						((GlacialStaff)item).Charges += 50;
						from.SendMessage( "As you touch the ice crystal to the staff, it begins to melt, causing the Glacial Staff to glow with power!" );

						m_Deed.Delete();
					}
				}
			}
			
			
			}

	public class MagicIceCrystal : Item
	{
		[Constructable]
		public MagicIceCrystal() : base( 0x1F19 )
		{
			Weight = 1.0;
			Name = "a magic ice crystal";
			LootType = LootType.Blessed;
		}

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

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

			writer.Write( (int) 0 );
		}

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

			int version = reader.ReadInt();
		}

		public override bool DisplayLootType{ get{ return false; } }

		public override void OnDoubleClick( Mobile from )
		{
			if ( !IsChildOf( from.Backpack ) ) // Make sure its in their pack
			{
				 from.SendLocalizedMessage( 1042001 );
			}
			else
			{
				from.SendMessage("Select the Glacial Staff you wish to use this on."  );
				from.Target = new MagicIceCrystalTarget( this );
			 }
		}	
	}
}
}
Macil is offline   Reply With Quote
Old 09-28-2008, 01:16 PM   #2 (permalink)
Forum Expert
 
PerfectWing's Avatar
 
Join Date: Oct 2002
Location: USA, Ga.
Age: 24
Posts: 1,205
Send a message via ICQ to PerfectWing Send a message via AIM to PerfectWing Send a message via MSN to PerfectWing Send a message via Yahoo to PerfectWing
Default

Evaluate the number of charges on the glacial staff. Subtract that number of charges from the 50 you want to give the glacial staff. Instead of adding 50 to the glacial staff, just add whatever number remains. This would work best if you want the recharge to have multiple uses. If using the recharge crystal at all should render it worthless, then you would only need to set the charges on the staff to 50, without the += operator, but rather the = operator.
PerfectWing is offline   Reply With Quote
Old 09-28-2008, 02:37 PM   #3 (permalink)
Forum Novice
 
Tassyon T's Avatar
 
Join Date: Sep 2007
Posts: 367
Default

Quote:
Originally Posted by PerfectWing View Post
Evaluate the number of charges on the glacial staff. Subtract that number of charges from the 50 you want to give the glacial staff. Instead of adding 50 to the glacial staff, just add whatever number remains. This would work best if you want the recharge to have multiple uses. If using the recharge crystal at all should render it worthless, then you would only need to set the charges on the staff to 50, without the += operator, but rather the = operator.
Code:
GlacialStaff myStaff; // this is an incorrect, but symbolic way to represent your staff in question.
int ToRecharge = 10; // recharge amount 

if( (myStaff.Charges + ToRecharge) > 50)
   {
   myStaff.Charges = 50;
   }
else
   {
   myStaff.Charges += ToRecharge;
   }
Tassyon T is offline   Reply With Quote
Old 09-28-2008, 06:00 PM   #4 (permalink)
Forum Novice
 
Tassyon T's Avatar
 
Join Date: Sep 2007
Posts: 367
Default

Quote:
Originally Posted by MACIL
I'm not sure I understand what changes you want me to make so that this script works properly. Could you explain a little more, please?
Change

Code:
		protected override void OnTarget( Mobile from, object target )
		{
			if ( target is GlacialStaff )
			
						if(target is GlacialStaff)
			
			{
 			
				Item item = (Item)target;

				if ( ((GlacialStaff)item).Charges == 50 )
				{
					from.SendMessage( "That Glacial Staff has enough charges already!");
				}
				else
				{
					if( item.RootParent != from )
					{
						from.SendMessage( "That item must be in your pack to use this." );
					}
					else
					{
						((GlacialStaff)item).Charges += 50;
						from.SendMessage( "As you touch the ice crystal to the staff, it begins to melt, causing the Glacial Staff to glow with power!" );

						m_Deed.Delete();
					}
				}
			}
			
			
		}
to

Code:
		protected override void OnTarget( Mobile from, object target )
		{
			if ( target is GlacialStaff )
			
						if(target is GlacialStaff)
			
			{
 			
				Item item = (Item)target;

				if ( ((GlacialStaff)item).Charges == 50 )
				{
					from.SendMessage( "That Glacial Staff can not hold any more charges!"); 
				}
				else
				{
					if( item.RootParent != from )
					{
						from.SendMessage( "That item must be in your pack to use this." );
					}
					else
					{
						((GlacialStaff)item).Charges = 50;
						from.SendMessage( "As you touch the ice crystal to the staff, it begins to melt, causing the Glacial Staff to glow with power!" );

						m_Deed.Delete();
					}
				}
			}
			
			
		}
This will fully recharge your staff each time you use a magic ice crystal.

And this... will let you add 25 charges to the staff every time you recharge it (with a cap of 50 charges):

Code:
		protected override void OnTarget( Mobile from, object target )
		{
			if ( target is GlacialStaff )
			
						if(target is GlacialStaff)
			
			{
 			
				Item item = (Item)target;

				if ( ((GlacialStaff)item).Charges == 50 )
				{
					from.SendMessage( "That Glacial Staff can not hold any more charges!"); 
				}
				else
				{
					if( item.RootParent != from )
					{
						from.SendMessage( "That item must be in your pack to use this." );
					}
					else if( (GlacialStaff)item).Charges + 25 > 50 )
					{
						((GlacialStaff)item).Charges = 50;
						from.SendMessage( "As you touch the ice crystal to the staff, it begins to melt, causing the Glacial Staff to glow brilliantly with power!" );
						m_Deed.Delete();
					}
					else
					{
						((GlacialStaff)item).Charges += 25;
						from.SendMessage( "As you touch the ice crystal to the staff, it begins to melt, causing the Glacial Staff to glow with power!" );
						m_Deed.Delete();
					}
				}
			}
			
			
		}

Last edited by Tassyon T; 09-28-2008 at 06:07 PM.
Tassyon T is offline   Reply With Quote
Old 09-29-2008, 09:44 AM   #5 (permalink)
Forum Novice
 
Macil's Avatar
 
Join Date: Oct 2003
Location: Harper Woods, Michigan
Age: 21
Posts: 815
Send a message via ICQ to Macil Send a message via AIM to Macil
Default

Ahh, I got it working the way I want it. Perfect Wing was able to help me yesterday, thank you though. =)
Macil 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 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5