Ludeon Forums

RimWorld => Mods => Help => Topic started by: Stolij on September 01, 2016, 07:04:11 AM

Title: rimworld dll modding: getting the pawn that used an item
Post by: Stolij on September 01, 2016, 07:04:11 AM
i was getting into dll modding rimworld,
but i have no idea how to get which pawn used an item.

Sorry if this is a dumb/obvious question.


Any help is really appreciated.
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Master Bucketsmith on September 01, 2016, 07:22:51 AM
Quote from: Stolij on September 01, 2016, 07:04:11 AM
i was getting into dll modding rimworld,
but i have no idea how to get which pawn used the specific item.

Sorry if this is a dumb/obvious question.


Any help is really appreciated.
Well, what exactly is your question?
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Stolij on September 01, 2016, 07:35:54 AM
Quote from: Master Bucketsmith on September 01, 2016, 07:22:51 AM
Well, what exactly is your question?
my question is
How do you get which colonist used an item (like drugs etc)
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Master Bucketsmith on September 01, 2016, 08:31:39 AM
Quote from: Stolij on September 01, 2016, 07:35:54 AM
my question is
How do you get which colonist used an item (like drugs etc)
Ah, I see. :)
Have you looked at existing items to what you're trying to achieve and traced the code?
ILSpy will allow you to click on names and it'll show you where it's defined. Can be helpful figuring out how vanilla does it.
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Stolij on September 01, 2016, 09:05:28 AM
Quote from: Master Bucketsmith on September 01, 2016, 08:31:39 AM
Ah, I see. :)
Have you looked at existing items to what you're trying to achieve and traced the code?
ILSpy will allow you to click on names and it'll show you where it's defined. Can be helpful figuring out how vanilla does it.
(I do use ILSpy) I looked in the workshop and the forum, the Dermal Regenerator (by Skullywag) does remove hediffs but is a building instead of an item.
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Master Bucketsmith on September 01, 2016, 11:53:07 AM
Okay so, are you looking for a way to figure out for a specific instance of an item to keep track of who used it?
Or to keep track of what a specific pawn has used?
I would expect that to be covered with hediffs.
I've not done anything with those, myself, so I don't have a ready-to-consume answer. :P
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Lockdown on September 01, 2016, 01:10:08 PM
It depends on exactly what type of item you're referring to. You mentioned drugs as an example, which is a consumable, so you'd want to override the PostIngested(Pawn ingester) method in your item's Thing class. The ingester parameter will be whatever pawn just ate it.
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Stolij on September 01, 2016, 02:40:13 PM
actually im trying to make a drug that removes all addictions, but it probably does not know which pawn to remove the addiction from, so it doesn't.
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Lockdown on September 01, 2016, 02:46:29 PM
How would it not know which pawn? The pawn instance is given to you by PostIngested, you just have it clear their addictions in that method.

Post your code if you're still having trouble getting it to work.
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: Stolij on September 01, 2016, 03:57:38 PM
well i have this public class Class1 : ThingWithComps
    {
        private Hediff foundAddiction = null;
        private Pawn OwnerPawn = null;
        public override void Tick()
        {
            foreach (Hediff Addiction in OwnerPawn.health.hediffSet.GetHediffs<Hediff>())
            {
                if (Addiction is Hediff_Addiction)
                {
                    foundAddiction = Addiction;
                    OwnerPawn.health.hediffSet.hediffs.Remove(foundAddiction);
                }
            }
        }
Title: Re: rimworld dll modding: getting the pawn that used an item
Post by: mrofa on September 01, 2016, 06:42:57 PM
Either you need a workgiver and a job or float menu on a item

Example of float menu: (myPawn is the selected pawn)
public override IEnumerable<FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {



            List<FloatMenuOption> list = new List<FloatMenuOption>();

            {
                if (!myPawn.CanReserve(this))
                {

                    FloatMenuOption item = new FloatMenuOption("CannotUseReserved".Translate(), null);
                    return new List<FloatMenuOption>
{
item
};
                }
                if (!myPawn.CanReach(this, PathEndMode.Touch, Danger.Some))
                {
                    FloatMenuOption item2 = new FloatMenuOption("CannotUseNoPath".Translate(), null);
                    return new List<FloatMenuOption>
{
item2
};

                }

                if (myPawn != OwnerPawn)
                {
                    Action action3 = delegate
                    {
                        OwnerPawn = myPawn;
                        OwnerPawnID = myPawn.thingIDNumber;
                    };
                    list.Add(new FloatMenuOption("ClutterMakeOwnerPart1".Translate() + myPawn.Name.ToStringShort + "ClutterMakeOwnerPart2".Translate(), action3));
                }



                if (StoredClothSetList.Count <= 0 && myPawn == OwnerPawn && !Interaction)
                {
                    Action action1 = delegate
                    {
                        if (myPawn.drafter.CanTakeOrderedJob())
                        {
                            myPawn.drafter.TakeOrderedJob(LockerJob);
                        }
                        else
                        {
                            myPawn.QueueJob(LockerJob);
                            myPawn.jobs.StopAll();
                        }
                        OwnerPawn = myPawn;
                        myPawn.Reserve(this);
                        num = 0;

                    };
                    list.Add(new FloatMenuOption("ClutterStoreCloths".Translate(), action1));
                }
                if (StoredClothSetList.Count > 0 && myPawn == OwnerPawn && !Interaction)
                {
                    Action action2 = delegate
                    {
                        if (myPawn.drafter.CanTakeOrderedJob())
                        {
                            myPawn.drafter.TakeOrderedJob(LockerJob);
                        }
                        else
                        {
                            myPawn.QueueJob(LockerJob);
                            myPawn.jobs.StopAll();
                        }
                        myPawn.Reserve(this);
                        num = 1;

                    };
                    list.Add(new FloatMenuOption("ClutterSwitchCloths".Translate(), action2));
                }

            }
            return list;
        }