|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Novice
|
I have added charges to dyes and dye tubs. However, because I am consuming a charge on the dyes in the double click method, it is consumed even if the dyeing attempt is unsucessful (i.e. you are too far away). When I try to move this into the targeting methods, I can't find a way to do it and compile. Any suggestions?
Code:
using System;
using Server.Targeting;
using Server.HuePickers;
namespace Server.Items
{
public class Dyes : BaseItem // byron 3/13/09
{
// byron 3/13/09 - add dye charges***********************************************************
private int charges;
[CommandProperty (AccessLevel.GameMaster)]
public int Charges
{
get {return charges;}
set {charges = value;}
}
//*******************************************************************************************
[Constructable]
public Dyes() : base( 0xFA9 )
{
Weight = 3.0;
Charges = 50; // byron 3/13/09 - add charges
}
public Dyes( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write (charges); // byron 3/13/09 charges
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
int charges = reader.ReadInt (); // byron 3/13/09 charges
if ( Weight == 0.0 )
Weight = 3.0;
}
public override void OnDoubleClick( Mobile from )
{
from.SendLocalizedMessage( 500856 ); // Select the dye tub to use the dyes on.
from.Target = new InternalTarget();
// byron 3/13/09 - add charges ***************************************************************
Charges -= 1;
if (Charges < 1)
this.Delete ();
//********************************************************************************************
}
private class InternalTarget : Target
{
public InternalTarget() : base( 1, false, TargetFlags.None )
{
}
private class InternalPicker : HuePicker
{
private DyeTub m_Tub;
public InternalPicker( DyeTub tub ) : base( tub.ItemID )
{
m_Tub = tub;
}
public override void OnResponse( int hue )
{
m_Tub.DyedHue = hue;
m_Tub.Charges = 20; // byron 3/13/09 add charges
}
}
private static void SetTubHue( Mobile from, object state, int hue )
{
((DyeTub)state).DyedHue = hue;
}
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is DyeTub )
{
DyeTub tub = (DyeTub) targeted;
if ( tub.Redyable )
{
if ( tub.CustomHuePicker == null )
from.SendHuePicker( new InternalPicker( tub ) );
else
from.SendGump( new CustomHuePickerGump( from, tub.CustomHuePicker, new CustomHuePickerCallback( SetTubHue ), tub ) );
}
else if ( tub is BlackDyeTub )
{
from.SendLocalizedMessage( 1010092 ); // You can not use this on a black dye tub.
}
else
{
from.SendMessage( "That dye tub may not be redyed." );
}
}
else
{
from.SendLocalizedMessage( 500857 ); // Use this on a dye tub.
}
}
}
}
}
__________________
The valiant die but once. I have died many times. |
|
|
|
|
|
#2 (permalink) |
|
Master of the Internet
|
i will get you started on it, you will have to finish off the targeting part (where your red line will go into in the right spot and using "thedyes" instead of "this".
change from.Target = new InternalTarget(); to from.Target = new InternalTarget(this); then start of below: Code:
private class InternalTarget : Target
{
public InternalTarget() : base( 1, false, TargetFlags.None )
{
}
Code:
private class InternalTarget : Target
{
private Dyes thedyes;
public InternalTarget(Dyes dummy) : base( 1, false, TargetFlags.None )
{
thedyes = dummy;
}
![]()
__________________
http://www.AoAUO.com
:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :) |
|
|
|
|
|
#3 (permalink) |
|
Forum Novice
|
If I change
from.Target = new InternalTarget (); to from.Target = new InternalTarget (this); I then get the error that there is no overload method for InternalTarget that will take 1 argument. I am guessing I should modify the InternalTarget method to receive the variable?
__________________
The valiant die but once. I have died many times. |
|
|
|
|
|
#4 (permalink) |
|
Forum Novice
|
I got it working; thanks much Greywolf. Your posts are always helpful.
For those who may wonder, here is the working code: Code:
using System;
using Server.Targeting;
using Server.HuePickers;
namespace Server.Items
{
public class Dyes : BaseItem // byron 3/13/09
{
// byron 3/13/09 - add dye charges***********************************************************
private int charges;
[CommandProperty (AccessLevel.GameMaster)]
public int Charges
{
get {return charges;}
set {charges = value;}
}
//*******************************************************************************************
[Constructable]
public Dyes() : base( 0xFA9 )
{
Weight = 3.0;
Charges = 50; // byron 3/13/09 - add charges
}
public Dyes( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write (charges); // byron 3/13/09 charges
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
int charges = reader.ReadInt (); // byron 3/13/09 charges
if ( Weight == 0.0 )
Weight = 3.0;
}
public override void OnDoubleClick( Mobile from )
{
from.SendLocalizedMessage( 500856 ); // Select the dye tub to use the dyes on.
from.Target = new InternalTarget(this);
}
private class InternalTarget : Target
{
private Dyes dyes; // byron 3/16/09
public InternalTarget(Dyes m_dyes) : base( 1, false, TargetFlags.None )
{
dyes = m_dyes; // byron 3/16/09
}
private class InternalPicker : HuePicker
{
private DyeTub m_Tub;
public InternalPicker( DyeTub tub ) : base( tub.ItemID )
{
m_Tub = tub;
}
public override void OnResponse( int hue )
{
m_Tub.DyedHue = hue;
m_Tub.Charges = 20; // byron 3/16/09
}
}
private static void SetTubHue( Mobile from, object state, int hue )
{
((DyeTub)state).DyedHue = hue;
}
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is DyeTub )
{
DyeTub tub = (DyeTub) targeted;
if ( tub.Redyable )
{
if ( tub.CustomHuePicker == null )
from.SendHuePicker( new InternalPicker( tub ) );
else
from.SendGump( new CustomHuePickerGump( from, tub.CustomHuePicker, new CustomHuePickerCallback( SetTubHue ), tub ) );
// byron 3/16/09 add charges ***********************************************************
dyes.Charges -= 1;
if (dyes.Charges < 1)
dyes.Delete ();
//****************************************************************************
}
else if ( tub is BlackDyeTub )
{
from.SendLocalizedMessage( 1010092 ); // You can not use this on a black dye tub.
}
else
{
from.SendMessage( "That dye tub may not be redyed." );
}
}
else
{
from.SendLocalizedMessage( 500857 ); // Use this on a dye tub.
}
}
}
}
}
__________________
The valiant die but once. I have died many times. |
|
|
|
|
|
#6 (permalink) |
|
Lurker
Join Date: Jun 2007
Posts: 13
|
That's right. Because your deserialize method was wrong. You should also call InvalidateProperties() in property 'Charges'.
Valid code: Code:
using System;
using Server.Targeting;
using Server.HuePickers;
namespace Server.Items
{
public class Dyes : Item
{
private int m_Charges;
[CommandProperty( AccessLevel.GameMaster )]
public int Charges
{
get { return m_Charges; }
set { m_Charges = value; InvalidateProperties(); }
}
[Constructable]
public Dyes() : base( 0xFA9 )
{
Weight = 3.0;
Charges = 50;
}
public Dyes( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( ( int )1 ); // version
writer.Write( m_Charges );//V1
}
public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );
list.Add( 1060584, m_Charges.ToString() ); // uses remaining: ~1_val~
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch( version )
{
case 1:
{
m_Charges = reader.ReadInt();
goto case 0;
}
case 0:
break;
}
if( version == 0 && m_Charges == 0 )
m_Charges = 50;
if( Weight == 0.0 )
Weight = 3.0;
}
public override void OnDoubleClick( Mobile from )
{
from.SendLocalizedMessage( 500856 ); // Select the dye tub to use the dyes on.
from.Target = new InternalTarget( this );
}
private class InternalTarget : Target
{
private Dyes m_Dyes;
public InternalTarget( Dyes dyes ) : base( 1, false, TargetFlags.None )
{
m_Dyes = dyes;
}
private class InternalPicker : HuePicker
{
private DyeTub m_Tub;
public InternalPicker( DyeTub tub ) : base( tub.ItemID )
{
m_Tub = tub;
}
public override void OnResponse( int hue )
{
m_Tub.DyedHue = hue;
// m_Tub.Charges = 20; // byron 3/16/09 //??????
}
}
private static void SetTubHue( Mobile from, object state, int hue )
{
( ( DyeTub )state ).DyedHue = hue;
}
protected override void OnTarget( Mobile from, object targeted )
{
if( targeted is DyeTub )
{
DyeTub tub = ( DyeTub )targeted;
if( tub.Redyable )
{
if( tub.CustomHuePicker == null )
from.SendHuePicker( new InternalPicker( tub ) );
else
from.SendGump( new CustomHuePickerGump( from, tub.CustomHuePicker, new CustomHuePickerCallback( SetTubHue ), tub ) );
--m_Dyes.Charges;
if( m_Dyes.Charges < 1 )
m_Dyes.Delete();
}
else if( tub is BlackDyeTub )
{
from.SendLocalizedMessage( 1010092 ); // You can not use this on a black dye tub.
}
else
{
from.SendMessage( "That dye tub may not be redyed." );
}
}
else
{
from.SendLocalizedMessage( 500857 ); // Use this on a dye tub.
}
}
}
}
}
Remember Goury: when You post a piece of code you should also post all connected scripts. We don't have a class named BaseItem. ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|