I have been working on this script for over a week and finally I have to say . . it has me beat.
The script compiles but it crashes the Server when I try to use it.
First . . a little about the script. This is an Addon script that includes:
1) PetStablingPostAddon : BaseAddon
2) PostPiece : AddonComponent (with OnDoubleClick that calls StableMyPetGump)
3) StableMyPetGump : Gump (with Response Buttons that call PetStablePostTarget or PetRetrievPostTarget)
In the Target sections (among other checks) I need a check to assure the Player has not run off across the shard before using the targeting cursor. So I need a Range check. The checks that I put in occur at line #276 and at #line #381 (I placed Comments just ahead of these lines so they stand out).
Here is the Crash Log:
After crashing the server (as indicated above) I tried many script variations but every one had the identical result.
So . . Finally I put a null check for the Post at line #242 and line #347. With these in place I discovered that the Post was not being recognized so it was null (I placed Comments just ahead of these lines so they stand out). Now the script does not crash the server because the new null check triggers giving me the message I embedded "The Post is null!".
I have identified the problem . . the OnTarget cannot see the PostPiece : AddonComponent. Many attempts to correct this have failed. I am stumped.
Here is the script and I apologize if any of my remaining hairs are stuck to it *smiles*
If anyone knows how I can get the OnTarget to see the m_Post (PostPiece : AddonComponent) I will forever be indebted.
Many Thanks
*bows*
The script compiles but it crashes the Server when I try to use it.
First . . a little about the script. This is an Addon script that includes:
1) PetStablingPostAddon : BaseAddon
2) PostPiece : AddonComponent (with OnDoubleClick that calls StableMyPetGump)
3) StableMyPetGump : Gump (with Response Buttons that call PetStablePostTarget or PetRetrievPostTarget)
In the Target sections (among other checks) I need a check to assure the Player has not run off across the shard before using the targeting cursor. So I need a Range check. The checks that I put in occur at line #276 and at #line #381 (I placed Comments just ahead of these lines so they stand out).
Here is the Crash Log:
Code:
Server Crash Report
===================
RunUO Version 2.1, Build 4511.11456
Operating System: Microsoft Windows NT 6.2.9200.0
.NET Framework: 4.0.30319.42000
Time: 2018-11-07 5:17:35 PM
Mobiles: 26366
Items: 897629
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.PostPiece.StableMyPetGump.PetStableStoneTarget.OnTarget(Mobile m, Object targeted)
at Server.Targeting.Target.Invoke(Mobile from, Object targeted)
at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)
After crashing the server (as indicated above) I tried many script variations but every one had the identical result.
So . . Finally I put a null check for the Post at line #242 and line #347. With these in place I discovered that the Post was not being recognized so it was null (I placed Comments just ahead of these lines so they stand out). Now the script does not crash the server because the new null check triggers giving me the message I embedded "The Post is null!".
I have identified the problem . . the OnTarget cannot see the PostPiece : AddonComponent. Many attempts to correct this have failed. I am stumped.
Here is the script and I apologize if any of my remaining hairs are stuck to it *smiles*
Code:
using Server;
using System;
using Xanthos.Evo;
using Server.Misc;
using Server.Gumps;
using Server.Items;
using Server.Multis;
using Server.Network;
using Server.Mobiles;
using Server.Targeting;
using System.Collections;
using Xanthos.Interfaces;
using Server.ContextMenus;
using Xanthos.ShrinkSystem;
using System.Collections.Generic;
namespace Server.Items
{
public class PetStablingPostAddon : BaseAddon
{
private PostPiece m_Post;
public override BaseAddonDeed Deed
{
get
{
return new PetStablingPostAddonDeed();
}
}
[Constructable]
public PetStablingPostAddon()
{
AddComponent( new PostPiece(this, 466 ), 0, 0, 5 ); //Post
AddComponent( new PostPiece(this, 2968 ), 0, 1, 3 ); // Sign Holder
AddComponent( new PostPiece(this, 3000 ), 0, 1, 2 ); // Stable Sign
}
public PetStablingPostAddon( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( 0 ); // Version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
public class PostPiece : AddonComponent
{
private PetStablingPostAddon m_Post;
private Mobile m_Owner;
public virtual bool ShareHue{ get{ return false; } }
public Mobile Owner
{
get { return m_Owner; }
set { m_Owner = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public PetStablingPostAddon post
{
get{ return m_Post; }
set{}
}
public PostPiece( PetStablingPostAddon post, int itemid ) : base( itemid )
{
m_Post = post;
}
public override void OnSingleClick( Mobile from )
{
Name = "Pet Stabling Post";
base.OnSingleClick( from );
LabelTo( from, Name );
}
public override void OnDoubleClick( Mobile from )
{
if ( this == null)
{
return;
}
if ( from == null)
{
return;
}
if ( from.Skills.AnimalTaming.Base <= 74.9 )
{
from.SendMessage( "Taming skill of 75 or higher is needed to become 'Owner' of this stable." );
return;
}
if( (Owner == null) && (from.Skills.AnimalTaming.Base >= 75.0) )
{
Owner = from;
from.SendMessage( "You now own this stable!" );
base.OnDoubleClick( from );
}
if ( from.AccessLevel >= AccessLevel.GameMaster )
{ if ( ! from.HasGump( typeof( StableMyPetGump ) ) )
{
from.SendGump(new StableMyPetGump());
}
}
if ( from != Owner )
{
from.SendMessage( "You do not own this stable!" );
return;
}
if ( !from.InRange( this.GetWorldLocation(), 4 ) )
{
from.SendMessage( "Get closer." );
return;
}
else
{
if ( ! from.HasGump( typeof( StableMyPetGump ) ) )
{
from.SendGump(new StableMyPetGump());
}
}
}
public PostPiece( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
writer.Write( m_Post );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch( version )
{
case 0: {
m_Post = reader.ReadItem() as PetStablingPostAddon;
break;
}
}
}
private class StableMyPetGump : Gump
{
private PostPiece m_Post;
public StableMyPetGump() : base( 20, 20 )
{
Closable = true;
Disposable = true;
Dragable = true;
Resizable = false;
AddPage(1);
AddBackground(2, 0, 277, 246, 9270);
AddLabel(75, 23, 1000, @"The Pet Home Stable");
AddItem(38, 60, 11676, 0x8AC);
AddItem(78, 60, 11670, 0x8AC);
AddItem(120, 60, 8406, 236);
AddItem(155, 64, 8479, 0x8AC);
AddItem(203, 67, 10090, 2845);
AddLabel(79, 120, 1000, @"Select a Pet to Stable");
AddLabel(79, 160, 1000, @"Select a Pet to Retrieve");
AddButton(60, 123, 9022, 9022, 2, GumpButtonType.Reply, 0);
AddButton(60, 163, 9022, 9022, 3, GumpButtonType.Reply, 0);
AddButton(110, 200, 242, 243, 1, GumpButtonType.Reply, 0); //CANCEL
}
public override void OnResponse(NetState state, RelayInfo info)
{
Mobile from = state.Mobile;
int tempHue = 0;
if (info.ButtonID == 1) //CANCEL
{
from.SendMessage("You decide to think about this later.");
from.CloseGump(typeof(StableMyPetGump));
return;
}
if (info.ButtonID == 2)
{
from.SendMessage("Target your pet to be stabled.");
from.Target = new PetStablePostTarget( m_Post );
return;
}
if (info.ButtonID == 3)
{
from.SendMessage("Target your pet to be retrieved.");
from.Target = new PetRetrievPostTarget( m_Post );
return;
}
}
private class PetStablePostTarget : Target
{
private PostPiece m_Post;
public PetStablePostTarget( PostPiece post ) : base( 10, false, TargetFlags.None )
{
m_Post = post;
}
protected override void OnTarget(Mobile m, object targeted)
{
if ( (m == null) || (targeted == null) )
{
return;
}
//Check for Stabling Post *******************
if (m_Post == null)
{
m.SendMessage ("The Post is null!");
return;
}
if ( m != null )
{
m.RevealingAction();
}
if ( !m.CheckAlive() )
{
m.SendMessage("You are dead and cannot do that.");
return;
}
if ( (targeted is PlayerMobile) || (targeted is Item) )
{
m.SendMessage("You can only stable pets.");
return;
}
if ( targeted is BaseEvo )
{
m.SendMessage("That pet cannot be stabled. You need to shrink it.");
return;
}
if ( targeted is BaseCreature )
{
BaseCreature creature = (BaseCreature)targeted;
if (creature == null)
{
m.SendMessage("You don't see any Creature.");
return;
}
//Check Range to Stabling Post **************
if ( !m.InRange( m_Post.GetWorldLocation(), 4 ) )
{
m.SendMessage (" Your are too far away from the Stabling Post!");
return;
}
if ( !creature.Alive )
{
m.SendMessage("That is dead and cannot be stabled.");
return;
}
if ( creature.IsDeadPet )
{
m.SendMessage ("That is dead and cannot be stabled.");
return;
}
if ( !creature.Tamable )
{
m.SendMessage("That is not your pet.");
return;
}
if ( !creature.Controlled || creature.ControlMaster != m )
{
m.SendMessage ("That is not your pet!");
return;
}
if ( creature.Summoned )
{
m.SendMessage ("You can not stable summoned creatures");
return;
}
if ( creature.Body.IsHuman )
{
m.SendMessage ("That creature cannot be stabled!");
return;
}
if ( creature.Combatant != null && creature.InRange( creature.Combatant, 12 ) && creature.Map == creature.Combatant.Map )
{
m.SendMessage (" Your pet seems to be busy at the moment, try agen when its not!");
return;
}
creature.ControlTarget = null;
creature.ControlMaster = m;
creature.ControlOrder = OrderType.Stay;
creature.Blessed = true;
m.Followers = (m.Followers - creature.ControlSlots);
if (m.Followers <=0)
{
m.Followers = 0;
}
m.SendMessage ("You stable your pet where he stands.");
}
}
}
private class PetRetrievPostTarget : Target
{
private PostPiece m_Post;
public PetRetrievPostTarget( PostPiece post ) : base( 10, false, TargetFlags.None )
{
m_Post = post;
}
protected override void OnTarget(Mobile m, object targeted)
{
if ( (m == null) || (targeted == null) )
{
return;
}
//Check for Stabling Post *******************
if (m_Post == null)
{
m.SendMessage ("The Post is null!");
return;
}
if ( m != null )
{
m.RevealingAction();
}
if ( !m.CheckAlive() )
{
m.SendMessage("You are dead and cannot do that.");
return;
}
if ( (targeted is PlayerMobile) || (targeted is Item) )
{
m.SendMessage("You can only stable pets.");
return;
}
if ( targeted is BaseEvo )
{
m.SendMessage("That pet cannot be stabled. You need to shrink it.");
return;
}
if ( targeted is BaseCreature )
{
BaseCreature creature = (BaseCreature)targeted;
if (creature == null)
{
m.SendMessage("You don't see any Creature.");
return;
}
//Check Range to Stabling Post **************
if ( !m.InRange( m_Post.GetWorldLocation(), 4 ) )
{
m.SendMessage (" Your are too far away from the Stabling Post!");
return;
}
if ( !creature.Alive )
{
m.SendMessage("That is dead and cannot be stabled.");
return;
}
if ( creature.IsDeadPet )
{
m.SendMessage ("That is dead and cannot be stabled.");
return;
}
if ( !creature.Tamable )
{
m.SendMessage("That is not your pet.");
return;
}
if ( !creature.Controlled || creature.ControlMaster != m )
{
m.SendMessage ("That is not your pet!");
return;
}
if ( creature.Summoned )
{
m.SendMessage ("You can not stable summoned creatures");
return;
}
if ( creature.Body.IsHuman )
{
m.SendMessage ("That is not a pet!");
return;
}
if ( creature.Combatant != null && creature.InRange( creature.Combatant, 12 ) && creature.Map == creature.Combatant.Map )
{
m.SendMessage ("Your pet seems to be busy at the moment, try agen when its not!");
return;
}
if ( creature.Blessed = false )
{
m.SendMessage ("That is not a stabled pet!");
}
if ( creature.Blessed = true )
{
if ( creature.ControlOrder == OrderType.Stay )
{
if (m.Followers <=0)
{
m.Followers = 0;
}
if ((m.Followers + creature.ControlSlots) > m.FollowersMax )
{
m.SendMessage ("You have too many Followers to retrieve that pet.");
return;
}
if ((m.Followers + creature.ControlSlots) <= m.FollowersMax )
{
creature.ControlOrder = OrderType.Come;
creature.ControlMaster = m;
creature.Blessed = false;
m.Followers = (m.Followers + creature.ControlSlots);
m.SendMessage ("You retrieve your pet.");
return;
}
}
}
}
}
}
}
}
public class PetStablingPostAddonDeed : BaseAddonDeed
{
public override BaseAddon Addon
{
get
{
return new PetStablingPostAddon();
}
}
[Constructable]
public PetStablingPostAddonDeed()
{
Name = "Dark Stone Pet Stabling Post";
}
public PetStablingPostAddonDeed( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( 0 ); // Version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}
If anyone knows how I can get the OnTarget to see the m_Post (PostPiece : AddonComponent) I will forever be indebted.
Many Thanks
*bows*