ServUO Version
Publish 57
Ultima Expansion
Endless Journey
Trying to find something I can acquire the code from but haven't found anything yet, I am looking for a way to spawn some items around the mob on death, these would be timed items that would expire. Now that I typed that I remember that champs spawn a gate on death I'll start there but if anyone knows a solution let me know, thank you.
 
I found this interesting that you asked this, I had just added something similar to the system I'm working on which is just about ready to be released but I'll share one of the scripts with you to see what I did and how you could use it to do what you want.

Code:
using Server.Mobiles;

namespace Server.GD13
{
    internal class RandomToken : Diamond
    {
        readonly LootPack loot;

        readonly List<Item> itemsToPack;

        readonly int lootChance;

        [Constructable]
        public RandomToken(LootPack lootType, List<Item> packItems, int chance) : base()
        {
            loot = lootType;

            itemsToPack = packItems;

            lootChance = chance;

            Name = "Random Encounter Token";

            Visible = false;

            Weight = 0.0;
        }

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

        public override DeathMoveResult OnParentDeath(Mobile parent)
        {
            if (parent is BaseCreature bc)
            {
                if (loot != null)
                {
                    if (Utility.Random(100) < lootChance)
                        bc.AddLoot(loot);
                }

                if (itemsToPack != null && itemsToPack.Count > 0)
                {
                    foreach (var item in itemsToPack)
                    {
                        if (Utility.Random(100) < lootChance)
                            bc.AddToBackpack(item);
                    }
                }

                Delete();
            }

            return base.OnParentDeath(parent);
        }

        public override void OnParentDeleted(object parent)
        {
            Delete();
        }

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

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

I used the DeathMoveResult OnParentDeath(Mobile parent) method of the an item, added to the creatures items, so when it dies it'll add items to its backpack, you could easily just have items movetoworld at locations +/- of the location of the creature!
 
I ended up finding a way before I got to checking this haha, I pulled some code from one of the champions and abused it a little to do what I wanted, so in the champ replacing what was there originally it works fine, I just don't know how to go about adding it to the OnDeath as I get "no suitable method found to override"

C#:
            Map map = Map;

            if (map == null)
                return;

            int newRavenwoodTree = Utility.RandomMinMax(3, 6);

            for (int i = 0; i < newRavenwoodTree; ++i)
            {
                RavenwoodTree ravenwoodtree = new RavenwoodTree();

                bool validLocation = false;
                Point3D loc = Location;

                for (int j = 0; !validLocation && j < 10; ++j)
                {
                    int x = X + Utility.Random(30) - 1;
                    int y = Y + Utility.Random(30) - 1;
                    int z = map.GetAverageZ(x, y);

                    if (validLocation = map.CanFit(x, y, Z, 16, false, false))
                        loc = new Point3D(x, y, Z);
                    else if (validLocation = map.CanFit(x, y, z, 16, false, false))
                        loc = new Point3D(x, y, z);
                }

                ravenwoodtree.MoveToWorld(loc, map);
            }
 
What script were you trying to edit? the BaseChampion : BaseCreature has OnBeforeDeath() overrided from BaseCreature, so if you wanted to edit into the existing method there, it would work, I would think!
 
It's technically a champion that I'm trying to make, so I added it to OnBeforeDeath to test and got this:
C#:
Errors:
 + Custom/Quests/Wood Key/Mobiles/Champion/WoodChampions.cs:
    CS0126: Line 157: An object of a type convertible to 'bool' is required
    CS0161: Line 152: 'WoodChamp.OnBeforeDeath()': not all code paths return a value
Scripts: One or more scripts failed to compile or no script files were found.
C#:
        public override bool OnBeforeDeath()
        {
            Map map = Map;

            if (map == null)
                return;

            int newRavenwoodTree = Utility.RandomMinMax(3, 6);

            for (int i = 0; i < newRavenwoodTree; ++i)
            {
                RavenwoodTree ravenwoodtree = new RavenwoodTree();

                bool validLocation = false;
                Point3D loc = Location;

                for (int j = 0; !validLocation && j < 10; ++j)
                {
                    int x = X + Utility.Random(30) - 1;
                    int y = Y + Utility.Random(30) - 1;
                    int z = map.GetAverageZ(x, y);

                    if (validLocation = map.CanFit(x, y, Z, 16, false, false))
                        loc = new Point3D(x, y, Z);
                    else if (validLocation = map.CanFit(x, y, z, 16, false, false))
                        loc = new Point3D(x, y, z);
                }

                ravenwoodtree.MoveToWorld(loc, map);
            }
        }

However if I use this I only get not all code paths return a value:
C#:
        public override bool OnBeforeDeath()
        {
            SpawnRavenwoodTree();
        }
 
The issue is you are in the method that requires a return value, either false or true, so your return; need to be return false or true.

Code:
public override bool OnBeforeDeath() //Always satisfy the return type of a method if it is not void!
        {
            SpawnRavenwoodTree();

return true;
        }

Code:
public bool AnyMethod(int i)
{
//do anything you want code wise with the int
//return true or false depending on conditions in your code, like is i greater than 0
}

somewhere else in the code

if (AnyMethod(1))
{
//do something
}
 
So simple.. :oops:

Awesome, does exactly what I needed it to do! Spawns the trees on death and the trees themselves already have a timer in their script so no messing with that. They spawn and decay and oh this is gonna be nice. Thank you sir!

C#:
        public override bool OnBeforeDeath()
        {
            SpawnRavenwoodTree();

            return true;
        }
C#:
        public void SpawnRavenwoodTree()
        {
            Map map = Map;

            if (map == null)
                return;

            int newRavenwoodTree = Utility.RandomMinMax(3, 6);

            for (int i = 0; i < newRavenwoodTree; ++i)
            {
                RavenwoodTree ravenwoodtree = new RavenwoodTree();

                bool validLocation = false;
                Point3D loc = Location;

                for (int j = 0; !validLocation && j < 10; ++j)
                {
                    int x = X + Utility.Random(30) - 1;
                    int y = Y + Utility.Random(30) - 1;
                    int z = map.GetAverageZ(x, y);

                    if (validLocation = map.CanFit(x, y, Z, 16, false, false))
                        loc = new Point3D(x, y, Z);
                    else if (validLocation = map.CanFit(x, y, z, 16, false, false))
                        loc = new Point3D(x, y, z);
                }

                ravenwoodtree.MoveToWorld(loc, map);
            }
        }
 
I generally would rather recommend

C#:
        public override bool OnBeforeDeath()
        {
            SpawnRavenwoodTree();

            return base.OnBeforeDeath();
        }

instead of simply returning true.
 
Back