ServUO Version
Publish 57
Ultima Expansion
Endless Journey
So a while back I got some help writing this trash bag, the only way we could get it to work at the time was how it is coded now.. well little did I know this piece of code is using a cliloc and since it's 0 shows up as unknown mega cliloc error, ClassicUO suppresses those messages so I wasn't aware of it until used on another client. So I'm not sure how to correct it and need a little more help here is the section of code causing the errors:

The Empty function is where I am stuck at, especially the "Empty(0);" which I wasn't aware of but is actually using a cliloc..


C#:
        public override bool OnDragDrop(Mobile from, Item dropped)
        {
            if (!base.OnDragDrop(from, dropped))
                return false;

            if (dropped is SpellbookStrap)
            {
                from.SendLocalizedMessage(1075256); // That is blessed; you cannot throw it away.
                return false;
            }

            AddCleanupItem(from, dropped);

            if (TotalItems >= 50)
            {
                Empty(0); // The trash is full!  Emptying!
                from.SendMessage("The trash is full!  Emptying!");
            }
            else
            {
                from.SendMessage("The item will be deleted in three minutes."); // The item will be deleted in three minutes

                if (m_Timer != null)
                    m_Timer.Stop();
                else
                    m_Timer = new EmptyTimer(this);

                m_Timer.Start();
            }

            return true;
        }

        public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
        {
            if (!base.OnDragDropInto(from, item, p))
                return false;

            if (item is SpellbookStrap)
            {
                from.SendLocalizedMessage(1075256); // That is blessed; you cannot throw it away.
                return false;
            }

            AddCleanupItem(from, item);

            if (TotalItems >= 50)
            {
                Empty(0); // The trash is full!  Emptying!
                from.SendMessage("The trash is full!  Emptying!");
            }
            else
            {
                from.SendMessage("The item will be deleted in three minutes."); // The item will be deleted in three minutes

                if (m_Timer != null)
                    m_Timer.Stop();
                else
                    m_Timer = new EmptyTimer(this);

                m_Timer.Start();
            }

            return true;
        }

        public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
        {
            base.GetContextMenuEntries(from, list);
            List<Item> items = Items;
            if (items.Count > 0)
                list.Add(new EmptyTrash(this));
        }

        private class EmptyTrash : ContextMenuEntry
        {
            private readonly TrashBagBrit trashBagBrit;

            public EmptyTrash(TrashBagBrit trashBagBrit) : base(0154, 5)
            {
                this.trashBagBrit = trashBagBrit;
            }

            public override void OnClick()
            {
                trashBagBrit.Empty(0);
            }
        }

        public void Empty(int message)
        {
            List<Item> items = Items;

            if (items.Count > 0)
            {
                PublicOverheadMessage(Network.MessageType.Regular, 0x3B2, message, "");

                for (int i = items.Count - 1; i >= 0; --i)
                {
                    if (i >= items.Count)
                        continue;

                    ConfirmCleanupItem(items[i]);

                    #region SA
                    if (.01 > Utility.RandomDouble())
                        DropToCavernOfDiscarded(items[i]);
                    else
                        items[i].Delete();
                    #endregion
                }

                if (m_Cleanup.Any(x => x.mobiles != null))
                {
                    foreach (var m in m_Cleanup.Select(x => x.mobiles).Distinct())
                    {
                        if (m_Cleanup.Find(x => x.mobiles == m && x.confirm) != null)
                        {
                            double point = m_Cleanup.Where(x => x.mobiles == m && x.confirm).Sum(x => x.points);
                            m.SendMessage("You have received approximately {0} points for turning in {1} items for Clean Up Britannia.", point.ToString(), m_Cleanup.Count(r => r.mobiles == m)); // You have received approximately ~1_VALUE~points for turning in ~2_COUNT~items for Clean Up Britannia.
                            PointsSystem.CleanUpBritannia.AwardPoints(m, point);
                        }
                    }
                    m_Cleanup.Clear();
                }
            }

            if (m_Timer != null)
                m_Timer.Stop();

            m_Timer = null;
        }
 
You know.. I hadn't even though about just replacing that with the actual cliloc lol.. but then wouldn't the message come from the trash bag itself and not be a message to the player?
 
Last edited:
Based off the code you provided and what Empty(); does, yes, it would make it appear overhead. Although in this case it would still appear in system messages since objects in your inventory can't display an overhead message. It would show the message to anyone around you in their system message as well.

That being said, you could easily replace
C#:
PublicOverheadMessage(Network.MessageType.Regular, 0x3B2, message, "");
with
C#:
if (RootParent is Mobile m)
{
   m.SendLocalizedMessage(message);
}
else
{
    PublicOverheadMessage(Network.MessageType.Regular, 0x3B2, message, "");
}

Or instead of using RootParent, simply add Mobile m to the Empty method (public void Empty(Mobile m, int message)) and change Empty(0); to Empty(from, 501478); then use the SendLocalizedMessage.
 
Back