jayates

Member
ServUO Version
Publish 57
Ultima Expansion
Time Of Legends
I have this item that turns 10 fish into Fish Lard. Only, thing is I want it to "require" 50 tokens to use it. I added a bit of code that excepts the tokens (OnDoubleClick), although if not present in backpack it'll still operate. Can someone please help me fix the code?
C#:
namespace Server.Items
{
    public class FishOilProcessorX : Item
    {
        public override string DefaultName { get { return "an Unhygienix... covered in fish oil"; }}

        [Constructable]
        public FishOilProcessorX() : base(11001) //music box
        {
            Movable = false;            
            Hue = 2231;
        }

        public override void OnSingleClick( Mobile from )
        {
            base.OnSingleClick( from );

            LabelTo( from, "This Unhygienix requires 1 stack of 10 fish to produce a block of Fish Lard!" );
        }
        public override void GetProperties( ObjectPropertyList list )
        {
            base.GetProperties( list );

            list.Add( "This Unhygienix requires 1 stack of 10 fish to produce a block of Fish Lard!" );
        }

        public FishOilProcessorX(Serial serial) : base(serial)
        { }

        private int CheckGrouping(Item a, Item b)
        {
            return b.Hue.CompareTo(a.Hue);
        }

        public override void OnDoubleClick(Mobile p)
        {    
         ////added code////
          /*Container pack = p.Backpack;

            Item[] items = pack.FindItemsByType( typeof( Daat99Tokens ) );
            if( p.Backpack.ConsumeTotal( typeof( Daat99Tokens ), 50 ) )
            if (items != null && items.Length > 0)
            {
            foreach (Item item in items)        
            item.Consume();
            }*/
         //// added code end////    
         
            var success = false;
             ////ShoreFish////
            if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Fish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(PumpkinSeedSunfish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(BrookTrout), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(RedbellyBream), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(GreenCatfish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(YellowPerch), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(RainbowTrout), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(SmallmouthBass), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Walleye), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(PikeFish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(BluegillSunfish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(UncommonShiner), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(KokaneeSalmon), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            ////DeepWaterFish////
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Haddock), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Tarpon), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Cobia), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Shad), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(BlueFish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Bonefish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(CapeCod), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(RedSnook), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(MahiMahi), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(YellowfinTuna), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(RedGrouper), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(RedDrum), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(BlackSeabass), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(GraySnapper), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Amberjack), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(Bonito), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(CaptainSnook), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(BlueGrouper), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            ////DungeonFish////
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(DungeonChub), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(CutThroatTrout), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(OrcBass), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(InfernalTuna), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(DemonTrout), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(GrimCisco), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(DarkFish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(TormentedPike), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(SnaggletoothBass), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(DrakeFish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(CragSnapper), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }    
            else if ((success = p.Backpack.ConsumeTotalGrouped(typeof(LurkerFish), 10, true, null, CheckGrouping)))
            {
                p.AddToBackpack(new FlaskOfFishOil());
            }
                        
            if (success)
            {
                p.SendMessage( 89, "The machine squeezed your stack of fish into a itty, bitty block of Fish Lard!" );
                p.Say ("Wow... a few gold coins fell out! Those fish must have swallowed em'!");            
                p.AddToBackpack( new FlaskOfFishOil()); // ( Utility.Random( 1, 2 )));
                p.AddToBackpack( new Gold( Utility.Random( 100, 200 )));    
                //Delete();
            }
            else
            {
                p.SendMessage("The Unhygienix requires 10 Fish to produce a block of Fish Lard!");
            }
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write(0);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }

    }
}
 
First off, thank you for the response!!! Right, I forgot to say that it's currently commented out due to it operating even if the tokens ain't present in your backpack. That's what I was needing help with.
 
I believe you forgot to give an exit in case the tokens are not 50. Try changing the backpack code to the following:

Backpack requirement:
Item[] items = p.Backpack.FindItemsByType( typeof( Daat99Tokens ) );

if( items.Count() >= 50 ){
     for (int i = 0; i < 50; i++)
          item[i].Consume();
} else {
     p.SendMessage("You need 50 tokens to do it!");
     return;
}

It would be wise to actually split the methods of "checking that he has 50 tokens" and "consuming the 50 tokens", so you consume them only if there is success. But this depends by the logic you wanna use (waste or not 50 even if it fails).

I don't really like the loop for consume them, they should be consumed in block but I don't have servuo in mind at the moment so I don't know if you have that function or not. You can simplify it from there.
 
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back