Have all my trees in 13 new ones other than the 3 in treehelper the only issue im having is the trees when chopped are all growing back as apple trees....

trying to figure out how to change the on Chop method to allow more trees the issue is the trees are using the same Item ID's as those 3 trees So I get the error that there are multiple cases with the label value "3478" etc .. any work around ?
 
oops forgot to show the script.

C#:
using System;
using Server;
using System.Collections;
using Server.Network;
using Server.Gumps;
using Server.Items;

namespace Server.Items.Crops
{
    public enum TreeType
    {
        AppleTree,
        PearTree,
        PeachTree,
        ApricotTree,
        AvocadoTree,
        BananaTree,
        CherryTree,
        CoconutPalm,
        GrapefruitTree,
        KiwiTree,
        LemonTree,
        LimeTree,
        MangoTree,
        OrangeTree,
        PomegranateTree,
        WalnutTree
    }

    public class TreeHelper
    {
        public static bool CanPickMounted{ get{ return true; } }
        public static bool TreeOrdinance{ get{ return false; } }

        public static TimeSpan SaplingTime = TimeSpan.FromMinutes( 5 );
        public static TimeSpan StumpTime = TimeSpan.FromMinutes( 5 );

        public class ChopAction : Timer
        {
            private Mobile m_chopper;
            private int cnt;

            public ChopAction( Mobile from ) : base( TimeSpan.FromMilliseconds( 900 ), TimeSpan.FromMilliseconds( 900 ) )
            {
                Priority = TimerPriority.TenMS;
                m_chopper = from;
                from.CantWalk = true;
                cnt = 1;
            }

            protected override void OnTick()
            {
                switch( cnt++ )
                {
                    case 1: case 3: case 5:
                    {
                        m_chopper.Animate( 13, 7, 1, true, false, 0 );
                        break;
                    }
                    case 2: case 4:
                    {
                        Effects.PlaySound( m_chopper.Location, m_chopper.Map, 0x13E );
                        break;
                    }
                    case 6:
                    {
                        Effects.PlaySound( m_chopper.Location, m_chopper.Map, 0x13E );
                        m_chopper.CantWalk = false;
                        this.Stop();
                        break;
                    }
                }
            }
        }

        public class TreeTimer : Timer
        {
            private Item i_sapling;
            private Type t_crop;

            public TreeTimer( Item sapling, Type croptype, TimeSpan delay ) : base( delay )
            {
                Priority = TimerPriority.OneMinute;

                i_sapling = sapling;
                t_crop = croptype;
            }

            protected override void OnTick()
            {
                if (( i_sapling != null ) && ( !i_sapling.Deleted ))
                {
                    object[] args = { i_sapling.Location, i_sapling.Map };
                    Item newitem = Activator.CreateInstance( t_crop, args ) as Item;

                    i_sapling.Delete();
                }
            }
        }

        public class GrowTimer : Timer
        {
            private Item i_stump;
            private Type t_tree;
            private DateTime d_timerstart;
            private Item i_newtree;

            public GrowTimer( Item stump, Type treetype, TimeSpan delay ) : base( delay )
            {
                Priority = TimerPriority.OneMinute;

                i_stump = stump;
                t_tree = treetype;

                d_timerstart = DateTime.Now;
            }

            protected override void OnTick()
            {
                Point3D pnt = i_stump.Location;
                Map map = i_stump.Map;

                if ( t_tree == typeof(PeachTree) )
                    i_newtree = new PeachSapling();
                else if ( t_tree == typeof(PearTree) )
                    i_newtree = new PearSapling();
                else
                    i_newtree = new AppleSapling();

                i_stump.Delete();
                i_newtree.MoveToWorld( pnt, map );
            }
        }
    }

    public class BaseTree : Item, IChopable
    {
        public BaseTree( int itemID ) : base( itemID ){}

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

        public virtual void OnChop( Mobile from ){}

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

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

    public class TreeTrunk : Item, IChopable   // Tried editing this area here.... to add more  didnt work.
    {
        private Item i_leaves;

        public Item Leaves{ get{ return i_leaves; } }

        public TreeTrunk( int itemID, Item TreeLeaves ) : base( itemID )
        {
            Movable = false;
            i_leaves = TreeLeaves;
        }

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

        public override void OnAfterDelete()
        {
            if (( i_leaves != null ) && ( !i_leaves.Deleted ))
                i_leaves.Delete();

            base.OnAfterDelete();
        }

        public void OnChop( Mobile from )
        {
            int testID = ((Item)i_leaves).ItemID;

            switch (testID)
            {
                case 0xD96:
                case 0xD9A:
                {
                    AppleTree thistree = i_leaves as AppleTree;
                    if ( thistree != null )
                        thistree.Chop( from );
                    break;
                }
                case 0xDAA:
                case 0xDA6:
                {
                    PearTree thistree = i_leaves as PearTree;
                    if ( thistree != null )
                        thistree.Chop( from );
                    break;
                }
                case 0xD9E:
                case 0xDA2:
                {
                    PeachTree thistree = i_leaves as PeachTree;
                    if ( thistree != null )
                        thistree.Chop( from );
                    break;
                }

            }
        }

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

            writer.Write( (Item)i_leaves );
        }

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

            Item item = reader.ReadItem();
            if ( item != null )
                i_leaves = item;
        }
    }

    public class FruitTreeStump : Item
    {
        private Type t_treeType;
        private int e_tree;
        public Timer thisTimer;
        public DateTime treeTime;

        [CommandProperty( AccessLevel.GameMaster )]
        public String Sapling{ get{ return treeTime.ToString( "T" ); } }

        [CommandProperty( AccessLevel.GameMaster )]
        public String Type
        { get
            {
                switch( e_tree )
                {
                    case (int)TreeType.AppleTree:        return "Apple Tree";
                    case (int)TreeType.PearTree:        return "Pear Tree";
                    case (int)TreeType.PeachTree:        return "Peach Tree";
                    case (int)TreeType.ApricotTree:        return "Apricot Tree";
                    case (int)TreeType.AvocadoTree:        return "Avocado Tree";
                    case (int)TreeType.BananaTree:        return "Banana Tree";
                    case (int)TreeType.CoconutPalm:        return "Coconut Palm";
                    case (int)TreeType.GrapefruitTree:        return "Grapefruit Tree";
                    case (int)TreeType.KiwiTree:        return "Kiwi Tree";
                    case (int)TreeType.LemonTree:        return "Lemon Tree";
                    case (int)TreeType.LimeTree:        return "Lime Tree";
                    case (int)TreeType.MangoTree:        return "Mango Tree";
                    case (int)TreeType.OrangeTree:        return "Orange Tree";
                    case (int)TreeType.PomegranateTree:        return "Pomegranate Tree";
                    case (int)TreeType.WalnutTree:        return "Walnut Tree";
                    default:    return "Error Bad Treetype";
                }
            }
        }

        [Constructable]
        public FruitTreeStump( Type FruitTree ) : base( 0x1B5 )
        {
            Movable = false;
            Hue = 0x74E;
            Name = "a fruit tree stump";

            t_treeType = FruitTree;

            if ( FruitTree == typeof( PearTree ) )
                e_tree = (int)TreeType.PearTree;
            else if ( FruitTree == typeof( PeachTree ) )
                e_tree = (int)TreeType.PeachTree;
            else if ( FruitTree == typeof( ApricotTree ) )
                e_tree = (int)TreeType.ApricotTree;
            else if ( FruitTree == typeof( AvocadoTree ) )
                e_tree = (int)TreeType.AvocadoTree;
            else if ( FruitTree == typeof( BananaTree ) )
                e_tree = (int)TreeType.BananaTree;
            else if ( FruitTree == typeof( CoconutPalm ) )
                e_tree = (int)TreeType.CoconutPalm;
            else if ( FruitTree == typeof( GrapefruitTree ) )
                e_tree = (int)TreeType.GrapefruitTree;
            else if ( FruitTree == typeof( KiwiTree ) )
                e_tree = (int)TreeType.KiwiTree;
            else if ( FruitTree == typeof( LemonTree ) )
                e_tree = (int)TreeType.LemonTree;
            else if ( FruitTree == typeof( LimeTree ) )
                e_tree = (int)TreeType.LimeTree;
            else if ( FruitTree == typeof( MangoTree ) )
                e_tree = (int)TreeType.MangoTree;
            else if ( FruitTree == typeof( OrangeTree ) )
                e_tree = (int)TreeType.OrangeTree;
            else if ( FruitTree == typeof( PomegranateTree ) )
                e_tree = (int)TreeType.PomegranateTree;
            else if ( FruitTree == typeof( WalnutTree ) )
                e_tree = (int)TreeType.WalnutTree;
            else
                e_tree = (int)TreeType.AppleTree;

            init( this );
        }

        public static void init( FruitTreeStump plant )
        {
            TimeSpan delay = TreeHelper.StumpTime;
            plant.treeTime = DateTime.Now + delay;

            plant.thisTimer = new TreeHelper.GrowTimer( plant, plant.t_treeType, delay );
            plant.thisTimer.Start();
        }

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

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

            writer.Write( e_tree );
        }

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

            switch( version )
            {
                case 0:
                {
                    e_tree = reader.ReadInt();
                    break;
                }
            }

            switch( e_tree )
            {
                case (int)TreeType.AppleTree:        t_treeType = typeof(AppleTree);    break;
                case (int)TreeType.PearTree:        t_treeType = typeof(PearTree);    break;
                case (int)TreeType.PeachTree:        t_treeType = typeof(PeachTree);    break;
                case (int)TreeType.ApricotTree:        t_treeType = typeof(ApricotTree);    break;   
                case (int)TreeType.AvocadoTree:        t_treeType = typeof(AvocadoTree);    break;   
                case (int)TreeType.BananaTree:        t_treeType = typeof(BananaTree);    break;
                case (int)TreeType.CoconutPalm:        t_treeType = typeof(CoconutPalm);    break;
                case (int)TreeType.GrapefruitTree:    t_treeType = typeof(GrapefruitTree);    break;   
                case (int)TreeType.KiwiTree:        t_treeType = typeof(KiwiTree);    break;
                case (int)TreeType.LemonTree:        t_treeType = typeof(LemonTree);    break;
                case (int)TreeType.LimeTree:        t_treeType = typeof(LimeTree);    break;
                case (int)TreeType.MangoTree:        t_treeType = typeof(MangoTree);    break;
                case (int)TreeType.OrangeTree:        t_treeType = typeof(OrangeTree);    break;
                case (int)TreeType.PomegranateTree:    t_treeType = typeof(PomegranateTree);    break;   
                case (int)TreeType.WalnutTree:        t_treeType = typeof(WalnutTree);    break;
            }

            init( this );
        }
    }
}
 
Can you show like two of your trees? that way I can make sure to see whats going on with them
 
No it is in the Treehelper.cs, it is also in the code snippet posted above, but its all clumped together in there
 
I see. It looks like GrowTimer only allows Pear, Peach or Apple. Perhaps that is part of the problem.
 
that is what I was looking for a work around to... I tried adding more cases but there are only so many stumps and tree images in the game so it gave me there error that there are multiple cases with the label value "3478" etc .. any work around ?
 
that is what I was looking for a work around to... I tried adding more cases but there are only so many stumps and tree images in the game so it gave me there error that there are multiple cases with the label value "3478" etc .. any work around ?

Sorry, I don't know what you mean by this. Can you clarify?
 
C#:
public void OnChop( Mobile from )
        {
            int testID = ((Item)i_leaves).ItemID;

            switch (testID)
            {
                case 0xD96:
                case 0xD9A:
                {
                    AppleTree thistree = i_leaves as AppleTree;
                    if ( thistree != null )
                        thistree.Chop( from );
                    break;
                }
                case 0xDAA:
                case 0xDA6:
                {
                    PearTree thistree = i_leaves as PearTree;
                    if ( thistree != null )
                        thistree.Chop( from );
                    break;
                }
                case 0xD9E:
                case 0xDA2:
                {
                    PeachTree thistree = i_leaves as PeachTree;
                    if ( thistree != null )
                        thistree.Chop( from );
                    break;
                }

            }
        }
this part of the code....
 
It is a part of this
https://www.servuo.com/threads/cooking-expansion-set.2501/

But the issue there is, that in my view it is written badly, like everything is overwriting itself with the same code everywhere, each tree / crop has their own timer and yea ;) I will see to get a rewrite for that

I see what you mean @PyrO . PomegranateTree is a sub type of BaseTree, but it has it's own StumpTimer, FruitTimer, and it's own Chop and OnDoubleClick methods. I would have put all of those things in BaseTree. All BaseTree would need to know was the FruitType, which could be a simple enum, and it could then handle EVERYTHING for ALL of the fruits.
 
Yea also I just noticed that it has 2 BaseCrop Classes wich both are Item :p but the second one has a nice add in, so I may add that as well ;)
 
Back