[Solved] Apply hediff to body part, without surgery? (XML only please)

Started by AileTheAlien, July 14, 2018, 12:29:18 PM

Previous topic - Next topic

AileTheAlien

I want to make implants self-administerable with pills. For flavor-text, they're biological symbiotes / parasites, and they slowly attach / integrate with your body. However, I can only see how to add hediffs to body parts with surgery (e.g. <appliedOnFixedBodyParts><li>Stomach</li></appliedOnFixedBodyParts>), but pills apply it to the whole body. Is there some way to make a custom pill that applies a thing to a specific body part? Alternately, is there a way to make surgery self-administerable, and also not apply anesthetic?

PleccyMM

#1
You could use a CompUseEffect to add a hediff to the pill - of course this would require some source code which can be hard to write.

This code should probably work for adding a bionic stomach to a colonist if properly referenced in the xml file:


using System;
using Verse;
using RimWorld;

namespace NameOfSourceFile
{
    public class CompUseEffect_InstallBionicStomach : CompUseEffect
    {
        public override void DoEffect(Pawn usedBy)
        {
                base.DoEffect(usedBy);
                Hediff hediff = HediffMaker.MakeHediff(HediffDefOf.BionicStomach, usedBy, null);
                BodyPartRecord part = null;
                usedBy.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.ConsciousnessSource).TryRandomElement(out part);
                usedBy.health.AddHediff(hediff, part, null, null);

        }
    }
}


It simply says to add the hediff BionicStomach to the colonist in question once the pill is used.

And of course you'd need a second .cs file with the HediffDefOf.BionicStomach referenced, below is an example:


using System;
using Verse;
using RimWorld;

namespace NameOfSourceFile
{
    [DefOf]
    public static class HediffDefOf
    {
        public static HediffDef BionicStomach;
    }
}



If you need help setting up a solution for source code I suggest checking https://rimworldwiki.com/wiki/Modding_Tutorials/Setting_up_a_solution as it has by far the best description. - PleccyMM

PleccyMM


AileTheAlien

I actually haven't gotten into C# modding yet. Last time I tried to set it up, it was a massive hassle of problems because I:
- have Linux instead of Windows
- don't have Visual Studio

The actual C# coding wouldn't be too hard, since I use a lot of languages in my day job. The toolchain setup will take most of the work, and I barely have time for plain XML mods. :)

AileTheAlien

I'm making and updating Rimworld mods on my vacation again, and have found a reasonable (-ish) work-around to my old problem here. Many drugs or their addiction hediffs, cause other hediffs randomly, like chemical damage to the kidneys. Using that, my tentative solution is:

  • pawn eats pill-item
  • pawn gets "pill-eaten" hediff
  • pill-eaten hediff gives out hediff for the implant/alien symbiote thing, on a very short random interval, like 0.1 days
  • pill-eaten hediff degrades to zero quickly (like, a day) and disappears
  • symbiote hediff continues to tick upwards over time
  • symbiote hediff maxes out, and shows the correct flavor-text, stats, etc
The XML for the pill (the symbiote shouldn't matter, since it's defined just like other organ-implants or pill-effects in the base game, changing over time) looks like this. That works reasonably well, but it's got a few issues:

  • the random symbiote-started effect could actually fail to happen before the pill-effect runs out

    • it's unlikely, but still possible, because it's random
  • the game shows a big paper-envelope icon / notification, like it's a bad random accident (like all other things using this, currently in the game), but the player specifically chose to administer the pill, so it'd be annoying
  • the pill-effect is visible, and needs to be defined with a proper label, description, etc
Does anyone know a better way to do this? I looked through the XML in the base-game, and nothing else seemed useful, that could give a pawn a hediff on a specific body part. (Searching around the forums, it seems like the hediffs currently in the base-game's XML are the only ones available. Healer mech serum, resurrector mech serum, and psychic lances all have specific effects when used, but don't appear to be able to give an arbitrary hediff like a drug-item can, or like one hediff can cause another hediff.) Can hediffs be hidden from the player? I thought I found one of those in the past, but can't remember what it was. (I know thought-defs, especially if using multiple stages, can be hidden, but that's not what I need here.) Can the notification be disabled, when the secondary hediff gets applied? (Note, I'm not doing any C#. I'm on vacation from my programming job, so basic XML + sprites mods are all I have effort for. Not interested in trying to set up a C# toolchain for Rimworld on Linux; That'd take far too much time, for too little benefit.)

Thanks anyone, who has tips on this!

Fakeaccount123

#5
That should work. I am doing a mod that allows pawn to get psylinks and that is exactly how i did it. I added a drug that can randomly generate or upgrade the psylink hediff.
Another alternative is to use the xml of Psychic amplifier (if you have royalty) and copy how it works. You can add this in the <comps> of the pill:

<Comps>
      <li Class="CompProperties_Usable">
        <compClass>CompUsableImplant</compClass>
        <useJob>UseItem</useJob>
        <useLabel>swallow symbiote (or whatever you like)</useLabel>
      </li>
      <li Class="CompProperties_UseEffectInstallImplant">
        <hediffDef>HeartSymbioteHediff</hediffDef>
        <bodyPart>Heart</bodyPart>
      </li>
</Comps>

technically you won´t be "taking" the pill so you can't give it to prisoners but your colonist should be able to use the pill to get the symbiote hediff

AileTheAlien

I forgot that Royalty added a self-implantable thing. This set of XML tags works great (with or without the DLC), thanks! :)

(Now I just need to find a good sound-effect to use. The closest I could find so far is Pawn_Melee_HumanBite_Hit, although the start of MechSerumUsed is good...but then it has a long mechanical-thing sound afterwards. The surgery or vomit sounds would be close, but they're not defined as one-shots, and I can't figure out what combination of tags would allow a sustain sound to play one-shot...)