ServUO Version
Publish Unknown
Ultima Expansion
None
I think I start here?
public override void OnDoubleClick(Mobile from)
{

}


I've gotten that to produce things.
But I would like to target something first.
Basically I'm targeting some raw food and want to use it on a fire.
Or maybe I need have my character near a fire?
Given up on adding to the cooking menu when you double click on a pan or something.
 
Code:
Food.Target = new SomeTarget(Player);

Code:
    public class SomeTarget : Target
    {
        private readonly PlayerMobile PM;

        public SomeTarget(PlayerMobile pm) : base(3, false, TargetFlags.None)
        {
            PM = pm;
        }

        protected override void OnTarget(Mobile from, object targeted)
        {
            if (targeted is FirePitAddon)
            {
                    //code applied to FirePitAddon

                    PM.SendMessage("FirePit Targeted");
            }
        }
    }
 
Sorry I've gotten a little further but still can't figure out what I need to do next.
By the way I'm working from here .... \Scripts\Items\Consumables\CookableFood.cs

Which starts like...
public abstract class CookableFood : Item, IQuality, ICommodity

The Item class is someing you might take note of here.
Changing things up a bit here is where I'm at.

public override void OnDoubleClick(Mobile from)
{
if (ItemID == 0x1E1F)
{
from.SendLocalizedMessage(1010018); // What do you want to use this item on?
from.Target = new ItemTarget(this);
}
}

public class ItemTarget : Target
{
private readonly Item m_Item;

public ItemTarget(Item item) : base(2, false, TargetFlags.None)
{
m_Item = item;
}

protected override void OnTarget(Mobile from, object targeted)
{
from.SendLocalizedMessage(500494); //using this for a test message - // You can't use a bladed item on that!

}
}
The above works and after I click on the compfire it does show the message -
You can't use a bladed item on that!. (again only using that phrase for a test).
So it looks like everything is going to work.

But I can't add my next line of code which is...
new SoylentGreen().MoveToWorld(Location, Map); // Location, Map are underlined and won't work
public class ItemTarget : Target
{
private readonly Item m_Item;

public ItemTarget(Item item) : base(2, false, TargetFlags.None)
{
m_Item = item;
}

protected override void OnTarget(Mobile from, object targeted)
{
from.SendLocalizedMessage(500494); //using this for a test message - // You can't use a bladed item on that!
new SoylentGreen().MoveToWorld(Location, Map); // Location, Map are underlined and won't work
}
}

The problem coems from (Location, Map) being part of : Item and not : Target
I can put this line of code here...
public override void OnDoubleClick(Mobile from)
{
if (ItemID == 0x1E1F)
{
from.SendLocalizedMessage(1010018); // What do you want to use this item on?
new SoylentGreen().MoveToWorld(Location, Map); // this line works here because this part of the code is part of : Item
}
}
But using that code above I never get to use my target which I what I'm trying to do.
I think I'm close but having a hard time on what to do next.
Thanks for the help again.
Sorry I can't figure things out.
 
If you call for Location and Map without any tie to who's Location and who's Map, the code will assume you're taking the properties from Item but you can't access them from there.

If you want to add the SoylentGreen to a location you've to specify it with from.Location, from.Map, cause "from" is the argument passed to the method "OnTarget", or targeted.Location, targeted.Map (even though you've to identify it as Item or whatever it is). Those are the only two arguments you pass so the only two sources for OnTarget to grab those properties.

With "identify it as Item or whatever it is" I mean (for example):

C#:
protected override void OnTarget(Mobile from, object targeted)
{
    if (targeted is Item ite)
    {
         new SoylentGreen().MoveToWorld(ite.Location, ite.Map);
    }
}

Anyway I don't get the logic behind it very well, cause if you want specific behaviours when something is targeted you should override OnTarget in that specific element and not the base Item. This would avoid the identification, since you're already in the that element.
 
Last edited:
Back