Ludeon Forums

RimWorld => Mods => Help => Topic started by: kwang4 on July 02, 2020, 10:17:22 PM

Title: [Solved]C# methods of removing a hediff?
Post by: kwang4 on July 02, 2020, 10:17:22 PM
Somewhat basic, but I'm trying to remove a hediff from a dead body and returning an item. Method one is finding hediff name using DefDatabase and removing it, which works.

HediffDef h = DefDatabase<HediffDef>.GetNamed("ATPP_HediffVX2Chip");
innerPawn.health.hediffSet.hediffs.Remove(innerPawn.health.hediffSet.GetFirstHediffOfDef(h));


Second is creating a hediff with HediffMaker which has the correct hediffDef inside and targeting the pawn, but it never worked.

                HediffDef h = DefDatabase<HediffDef>.GetNamed("ATPP_HediffVX2Chip");
                Hediff hed = HediffMaker.MakeHediff(h, innerPawn, null);
                innerPawn.health.hediffSet.hediffs.Remove(hed);


Could someone explain why this doesn't work, and a possible fix to do it this way? Targeting and removing or adding hediffs has been a huge weakness of mine in rw modding for a while.
Title: Re: C# methods of removing a hediff?
Post by: LWM on July 06, 2020, 03:33:09 PM
Fun fact: you can use the debug tools to make an animal pregnant 4 or 5 times. (this is not actually healthy for the animal involved)

Internally, that's represented by having 5 different hediffs that all have the "pregnant" def.

The second approach isn't working because you're creating a new hediff and then asking "Hey, does this pawn have THIS hediff? (the one I just created over here?)" And the game is saying "Nope!" The pawn has a similar hediff with the same stats, same def, etc, but it's not the same.
Title: Re: C# methods of removing a hediff?
Post by: RawCode on July 07, 2020, 02:01:14 PM
under normal conditions you should just look how game handle hediffs (and any other things) on it's own and do exactly same.

and in most cases removing some object from array is not valid, mostly because objects have cleanup procedure and just removing from array will cause undefined state, like hediff removed but effects are not recalculated.
Title: Re: C# methods of removing a hediff?
Post by: kwang4 on July 12, 2020, 11:17:54 AM
Ahh I get it now. Thanks for the clarification both of y'all!
The pregnant example was pretty hilarious