[Solved-ish]Prevent hediff on mechanoids

Started by Nathan9456, October 05, 2020, 04:34:06 PM

Previous topic - Next topic

Nathan9456

New to rimworld modding.

I'm making a basic tranquilizer gun mod. I've got it all worked out and I'm just expanding on the features. I don't want my tranquilizer gun to tranquilize mechanoids.

I've dug around the base code a bit. I see organs typically decide how hediffs are applied. How could I prevent a hediff fired from a gun from affecting a mechanoid?

Thanks!

RawCode

you need "condition" normally conditions are defined with "if (bool) {}" statement...

it will be a bit more simple to help if you explain what exactly is wrong.

Nathan9456

#2
Nothing is exactly wrong. Like there are no errors because I havent written any code identifying mechanoids.

Its more a issue of identifying the mechanic I would need to use. So I noted that organs are the difference that really separated mechanoids from humans. I was hoping someone could expand on that. Like is that accurate? Should I try to create a mechanic that identified mechanoid organs and returns just base damage? I also saw that they are their own faction. I could try something there.

I use ILspy to dig around the base game and I can't find anything addressing this issue.

Your suggestion I create some logic in C# makes sense. I'll have to get the organ stats, perhaps of where the bullet hit. This is a little outside of my wheelhouse so I'd appreciate any suggestions but I'm guessing looking at the base game shooting logic would give me a clue of how it chooses which organs are damaged and I would work from there.

Update. I found a workaround. I dug around the base game C# and found a faction identifier.

            if (Def != null && hitThing != null && hitThing is Pawn hitPawn)
            {
                if (hitPawn.Faction == Faction.OfMechanoids) //If Mechanoid... had to identify by faction so it'd probably tranquilize mechanoids of mod factions or mechanoids somehow in other factions.
                        {
                        Messages.Message("TranqBullet_MechanoidMessage".Translate(
                        this.launcher.Label, hitPawn.Label
                        ), MessageTypeDefOf.NeutralEvent);
                        var tranqOnPawn = hitPawn.health?.hediffSet?.GetFirstHediffOfDef(Def.HediffToAdd);

                        if (tranqOnPawn != null) //Ensures no hediff is applied. May remove later.
                        {
                            tranqOnPawn.Severity = 1.0f;
                        }
                }

Solarius Scorch

I have no idea how modding Rimworld works, but it should be pointed out that there are robotic units other than mechanoids (at least in many mods - Androids, Mics Robots, etc.). These also shouldn't be affected by your tranquillizer, but are probably not part of the mechanoid faction?

RawCode

some mods are garbage, ever worse then some "hello world" mods in help section, trying to make your mod "compatible with everything in existence" is waste of time.

it's possible to open "Races_Mechanoid" and check fields that makes pawn "mechanical", but... there are no ways to ensure, that your favorite 137th mod about robots actually have fields set.