I have been trying to add Uses/charges to this item with no luck. I have looked a few scripts to get ideas, but the only one that works is baseaxe but the charges dont disappear. Please take a look and help? Thanks

Code:
using System;
using Server.Items;
using Server.Targeting;
using Server.Mobiles;
using Server.Gumps;
using System.Collections;

namespace Server.Items
{
  public class PortaPetRes : Item
  {
  
  [Constructable]
  public PortaPetRes() : base( 3985 )
  {
  Name = "a Portable Pet Res Stone";
  Movable = true;
  LootType = LootType.Blessed;
  
  }
  
  public PortaPetRes( 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 override void OnDoubleClick( Mobile m )
  {  
       if ( !IsChildOf (m.Backpack))
       {
       m.SendMessage( 77, "must be in your Backpack!" );
       }
       else
       {
         m.RevealingAction();

         m.SendMessage( "What pet would you like to resurrect?" );

         m.Target = new PetResTarget();
       }
     }

   private class PetResTarget : Target
   {

     public PetResTarget( ) : base( 1, false, TargetFlags.Beneficial )
     {
   }  
    
  protected override void OnTarget( Mobile m, object obj )
  {
      if(obj is Mobile)
        {
      Mobile mob = (Mobile)obj;    

        if ( mob.IsDeadBondedPet )
        {
         BaseCreature bc = mob as BaseCreature;
         {  
                 if(bc.ControlMaster == m)
                 {
                     m.CloseGump( typeof( PetResurrectGump ) );
                     m.SendGump( new PetResurrectGump( m, bc ) );
                 }
                 else
                 {
                   m.SendMessage( "that is not your pet." );
                 }
         }  
         }
                 else
                 {
                   m.SendMessage( "that pet is not dead." );
                 }
       }
     }
   }
}
}

Edit: Please use [code][/code] tags when posting source code. -Insanity
 
Last edited by a moderator:
On the :

Code:
  public class PortaPetRes : Item
  {

Modify to this :

Code:
  public class PortaPetRes : Item
  {
     private int Charges;

     [CommandProperty(AccessLevel.GameMaster)]
     public int Charges
     {
       get{return this.m_Charges;}
       set{this.m_Charges = value;
         this.InvalidateProperties();}
     }

Before on the :

Code:
    [Constructable]
     public PortaPetRes() : base( 3985 )
     {
       Name = "a Portable Pet Res Stone";
       Movable = true;
       LootType = LootType.Blessed;

     }

Add this :

Code:
       Charges = 5; // Or another value

And on the DoubleClick method make the charges decrease ( Charges--; ) everytime that he target a pet.

Also make a if statement( when the charges are <= 0 ), deletes the item( this.Delete(); ).
And of course don't forget to Serialize and Deserialize.

Hope it helps :D
 
Last edited:
I have been trying to add Uses/charges to this item with no luck. I have looked a few scripts to get ideas, but the only one that works is baseaxe but the charges dont disappear. Please take a look and help? Thanks

using System;
using Server.Items;
using Server.Targeting;
using Server.Mobiles;
using Server.Gumps;
using System.Collections;

namespace Server.Items
{
public class PortaPetRes : Item
{

[Constructable]
public PortaPetRes() : base( 3985 )
{
Name = "a Portable Pet Res Stone";
Movable = true;
LootType = LootType.Blessed;

}

public PortaPetRes( 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 override void OnDoubleClick( Mobile m )
{
if ( !IsChildOf (m.Backpack))
{
m.SendMessage( 77, "must be in your Backpack!" );
}
else
{
m.RevealingAction();

m.SendMessage( "What pet would you like to resurrect?" );

m.Target = new PetResTarget();
}
}

private class PetResTarget : Target
{

public PetResTarget( ) : base( 1, false, TargetFlags.Beneficial )
{
}

protected override void OnTarget( Mobile m, object obj )
{
if(obj is Mobile)
{
Mobile mob = (Mobile)obj;

if ( mob.IsDeadBondedPet )
{
BaseCreature bc = mob as BaseCreature;
{
if(bc.ControlMaster == m)
{
m.CloseGump( typeof( PetResurrectGump ) );
m.SendGump( new PetResurrectGump( m, bc ) );
}
else
{
m.SendMessage( "that is not your pet." );
}
}
}
else
{
m.SendMessage( "that pet is not dead." );
}
}
}
}
}
}
Could you please edit your post to include Code tags? It will get people to help you better and faster. In the future please use code tags. I don't even look at people's code if it's not in code tags.
 
Back