Welcome
Welcome to <strong>SunUO</strong>.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Challenge System and StatMods.clear() problem

Support for modifying scripts or writing your own

Challenge System and StatMods.clear() problem

Postby devilclaw on Fri Sep 14, 2007 4:04 am

Hi,

I'm trying to use a Challenge System (http://www.runuo.com/forums/custom-scri ... 1-1-a.html) with SunUO 0.5.0.
I have no error when the scripts are compiling, but when I challenge my friend (using two player accounts) the script ChallengeStone.cs crash around line 315:

c.StatMods.Clear();

Using runuo I get no errors. This is the exception generated by SunUO:

Code: Select all
2007-09-14 00:59:26,887 FATAL Exception disarmed in gump response of Server.Gumps.FinalGump
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Items.ChallengeStone.makeready(Mobile who) in c:\sunuo-0.5.0\Scripts\Misc\PVP\ChallengeStone.cs:line 315
   at Server.Gumps.FinalGump.OnResponse(NetState state, RelayInfo info) in c:\sunuo-0.5.0\Scripts\Misc\PVP\FinalGump.cs:line 120
   at Server.Network.PacketHandlers.DisplayGumpResponse(NetState state, PacketReader pvSrc) in i:\cygwin\home\max\svn\sunuo\src\Network\PacketHandlers.cs:line 1258


What's wrong?
devilclaw
 
Posts: 12
Joined: Mon Aug 20, 2007 6:32 pm

Postby Maik on Sat Sep 15, 2007 12:45 pm

May you should post some piece of code, the error tell you, that the accessed object is not a instance of any class, say its null. You have to check for that circumstance _before_ accessing any method or property of that class. Please post the code of the complete method, where the error occurs.
User avatar
Maik
 
Posts: 30
Joined: Wed Aug 15, 2007 3:30 pm

Postby devilclaw on Sat Sep 15, 2007 5:22 pm

Thanks Maik, this is the complete mothod:

Code: Select all
      public void makeready(Mobile who)   
      {   
         PlayerMobile c = (PlayerMobile) who;
         if( !who.Alive )
            who.Resurrect();
         
         Container bp = c.Backpack;
         Container bankbag = new Bag();
         bankbag.Hue = 63;
         BankBox bank = c.BankBox;
         Item oncurs = c.Holding;
                  
         if(oncurs != null)
            bp.DropItem(oncurs);
                  
         c.SendMessage( "You have 10 seconds until the duel begins" );
         c.SendMessage( 63, "After one of you dies, both of you will be teleported out" );
                  
         c.Criminal = true;
         c.CurePoison(c);
   
         c.Blessed = true;
         c.Frozen = true;

         c.Hits = c.HitsMax;
         c.Mana = c.ManaMax;
         c.Stam = c.StamMax;
         
         c.StatMods.Clear();
     
         if(bp != null)
         {
            Item toDisarm = c.FindItemOnLayer( Layer.OneHanded );
            
            if ( toDisarm == null || !toDisarm.Movable )
               toDisarm = c.FindItemOnLayer( Layer.TwoHanded );
            
            if (toDisarm != null)
               bp.DropItem(toDisarm);

            if ( c.Mount != null )
            {
               IMount mount = c.Mount;   
               mount.Rider = null;
               if( mount is BaseMount )
               {
                  BaseMount oldMount = (BaseMount)mount;   
                  oldMount.Map = Map.Internal;
                  c.TempMount = oldMount;
               }
            }
            
            while((BasePotion)bp.FindItemByType(typeof(BasePotion)) != null)
            {
               BasePotion potion = (BasePotion)bp.FindItemByType(typeof(BasePotion));
               bankbag.DropItem(potion);
            }
            while((EtherealMount)bp.FindItemByType(typeof(EtherealMount)) != null)
            {
               EtherealMount mount = (EtherealMount)bp.FindItemByType(typeof(EtherealMount));
               bankbag.DropItem(mount);
            }
            /*Item[] weps = bp.FindItemsByType( typeof( BaseWeapon ) );
            for ( int i = 0; i < weps.Length; ++i )
            {
               Item item = (Item)weps[i];
               BaseWeapon weapon = item as BaseWeapon;
               if( weapon.DamageLevel > WeaponDamageLevel.Regular )
                        bankbag.DropItem( item );
            }*/
            if( bankbag.Items.Count > 0 )
               bank.DropItem(bankbag);
            else
               bankbag.Delete();
         }
      }


I've attached the ChallengeStone.cs where this method is.
Attachments
ChallengeStone.rar
(3.54 KiB) Downloaded 5 times
devilclaw
 
Posts: 12
Joined: Mon Aug 20, 2007 6:32 pm

Postby Maik on Sat Sep 15, 2007 8:19 pm

Your try..catch statement is a nice hack, but no good programming art. You should replace arround 315 to look like:

Code: Select all
if ( c.StatMods != null ) {
    c.StatMods.Clear();
}


Thats it...
User avatar
Maik
 
Posts: 30
Joined: Wed Aug 15, 2007 3:30 pm

Postby devilclaw on Mon Sep 17, 2007 8:20 am

Thanks Maik, I'll try,
Can you explain what c.StatMods.Clear do?
devilclaw
 
Posts: 12
Joined: Mon Aug 20, 2007 6:32 pm

Postby Maik on Fri Sep 21, 2007 7:51 pm

StatMods is an object type of Array or ArrayList, dunno atm. Method Clear on a List (what type ever) will empty it by removing every item in that list.
User avatar
Maik
 
Posts: 30
Joined: Wed Aug 15, 2007 3:30 pm


Return to Script Support

Who is online

Users browsing this forum: No registered users and 0 guests

cron