|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Novice
|
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 );
}
}
}
}
}
|
|
|
|
|
|
#2 (permalink) |
|
Forum Expert
|
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.
|
|
|
|
|
|
#3 (permalink) | |
|
Forum Novice
Join Date: Sep 2007
Posts: 367
|
Quote:
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;
}
|
|
|
|
|
|
|
#4 (permalink) | |
|
Forum Novice
Join Date: Sep 2007
Posts: 367
|
Quote:
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();
}
}
}
}
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();
}
}
}
}
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. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|