Dustyn

Initiate
I've created an item "dungeon coin".

Everytime we leave a dungeon, these coins burn because you can't bring them outside dungeons.

So I've had this scripted in DungeonRegion :

Code:
		public override void OnExit( Mobile from )
		{
			if ( from != null && from is PlayerMobile && from.Alive )
			{
				Container pack = from.Backpack;

				if ( pack != null )
				{
					Item[] dungeoncoins = pack.FindItemsByType( typeof( DungeonCoin ) );
					bool hadcoins = false;

					foreach ( Item dcoins in dungeoncoins )
					{
						hadcoins = true;
						dcoins.Consume( dcoins.Amount );
					}

					if ( hadcoins )
						from.LocalOverheadMessage( MessageType.Regular, 906, true, "*Your dungeon coins burned on your way out!*" );			
				}
			}
		}

The problem is yes, it works, but it doesn't at the same time. Lemme explain through images :

First, I am adding the coins... and I am inside a dungeon.

ai.imgur.com_iw03mVS.png

I put it in my backpack...

ai.imgur.com_6KKNZ97.png

And now I am leaving the dungeon!

ai.imgur.com_6RvEgMK.png

It still appears in backpack... but it's not existant! So if I click it, it appears no amount, and if I move it then it will disappear... so it's kinda leaving a ghost there in my pack! It's very irritating, and I don't understand why it's doing this when I can easily consume that item easily with other scripts... It's only when it comes to deleting it OnExit of the dungeonregion that it's doing this... And I'm doing the SAME THING, which is CONSUME the item with it's total amount........

I've tried everything : movetoworld then delete, change hue then delete, adding a function so it deletes from the dungeoncoin script itself, I went through all scripts that contain finditembytype... and more. I'm out of ideas, because NOTHING of what I tried works.

Thx for help!
 
This is basically an issue because the client is busy reloading the data (at least thats what I think it is)

So for that I tested it and it works fine if you let the coins delete with a little delay:
Code:
        public override void OnExit( Mobile from )
        {
            if ( from != null && from is PlayerMobile && from.Alive && from.Backpack != null)
            {
                Item[] dungeoncoins = from.Backpack.FindItemsByType(typeof(DungeonCoin));
                if (dungeoncoins.Length > 0)
                {
                    foreach (Item coins in dungeoncoins)
                        coins.Movable = false;
                    new InternalDeletionTimer(from, dungeoncoins).Start();
                }
            }
        }

        class InternalDeletionTimer : Timer
        {
            Mobile from;
            Item[] items;
            public InternalDeletionTimer(Mobile from, Item[] items)
                : base(TimeSpan.FromMilliseconds(100))
            {
                this.from = from;
                this.items = items;
            }
            protected override void OnTick()
            {
                Container pack = from.Backpack;

                if (pack != null)
                {
                    foreach (Item dcoins in items)
                        dcoins.Consume(dcoins.Amount);
                    from.LocalOverheadMessage(MessageType.Regular, 906, true, "*Your dungeon coins burned on your way out!*");
                }
            }
        }
 
Mhmm I didn't know the existance of milliseconds! And that's an interesting strategy :) Thanks a lot IT WORKSSS!
 
You are welcome :) but I mean it worked befor too, it was just not updating the client graphics properly ;) the item count went down as it should though
 
There are always several ways to skin a cat. However, I'm not a fan of using timers when there is another solution. Timers tend to use more CPU and memory than straight code. In this case, I think you would be better off just re-opening their backpack right after deletion. Just change the end of your code to:

Code:
  if (hadcoins)
  {
  	from.Use(from.Backpack);
	from.LocalOverheadMessage(MessageType.Regular, 906, true, "*Your dungeon coins burned on your way out!*");
  }

This way you wont need a timer and when you force the backpack to re-open, the coins will be gone.
 
Yes, it would. Guess that could be a downside - judgement call.

I guess to me that's not a big deal, several things close containers such as moving thru a moongate.
 
Last edited:
I like the idea but I just prefer something that would be invisible to the player's eyes, so I don't want to mess up their backpack, especially if they are on the run from Pkers and it's what make them leave the dungeon, I wouldn't want them to lose their opened packs where they could have important supplies, or things like this ! ie : trapped pouches inside a bag
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back