ServUO Version
Publish 58
Ultima Expansion
Endless Journey
I'm creating a Pet wars Token that when double clicked creates A pet with the title "Pet wars" amognst other things.

I have it looking at this value here to summon the pet;
C#:
        [CommandProperty( AccessLevel.Administrator )]
        public BaseCreature Pet
        {
            get{ return m_Pet; }
            set{ m_Pet = value; }
        }

My issue is I want it to summon A generic Pet not the exact one I target.
So If I target A troll it will summon "Troll" (with the random stats and an skills the troll would get)
So I want the Value to be set as the BaseCreature Troll (Or what ever else I decided to target)

I was hoping someone could point me in the direction I need to make it so when I target a basecreature It essentialy marks that value as thats creatures .cs?

If that makes sense.
 

Attachments

  • PetWarsScroll.cs
    1.9 KB · Views: 0
Last edited:
Use the Type, so when you target the creature in question, string nameOfCreature = targeted.GetType().Name; , then instantiate it, BaseCreature creature = (BaseCreature)Activator.CreateInstance(nameOfCreature); and before adding to the world you can adjust any properties of the creature!

Sample Method
Code:
public void AddCreature(BaseCreature targetedCreature)
{
    // Get the name of the targeted creature's type
    string nameOfCreature = targetedCreature.GetType().Name;

    // Instantiate a new creature of the same type
    BaseCreature newCreature = (BaseCreature)Activator.CreateInstance(nameOfCreature));

    // Adjust any properties of the new creature
    newCreature.Name = "New " + targetedCreature.Name;

    // Add the new creature to the world
    newCreature.MoveToWorld(new Point3D(targetedCreature.X, targetedCreature.Y, targetedCreature.Z), targetedCreature.Map);
}
 
Last edited by a moderator:
Back