My very simple mod crashes rimworld when I spawn its pawn

Started by Fyre, January 14, 2017, 02:22:13 PM

Previous topic - Next topic

Fyre

So I haven't modded Rimworld (or anything) before, and I am trying to create a mod in which you can create robots which perform various jobs.

My first aim is to create a pawn that does nothing but run around hauling things, so I created a "Haulbot" ThinkTree, which is based on the Mechanoid Thinktree with the "JobGiver_Haul" thingy at the top of the priority list, the code is below:

<?xml version="1.0" encoding="utf-8" ?>


<ThinkTrees>

  <ThinkTreeDef>
+ Attachments and other opt
    <defName>Haulbot</defName>
    <thinkRoot Class="ThinkNode_Priority">
      <subNodes>
 
<li Class="JobGiver_Haul"/>

        <li Class="ThinkNode_Subtree">
          <treeDef>Downed</treeDef>
        </li>
       
        <li Class="ThinkNode_Subtree">
          <treeDef>LordDuty</treeDef>
        </li>

        <li Class="JobGiver_WanderAnywhere">
          <maxDanger>Deadly</maxDanger>
        </li>
         
        <li Class="JobGiver_IdleError"/>
       
      </subNodes>
    </thinkRoot>
  </ThinkTreeDef>
 
</ThinkTrees>


I also created a Robot race xml file, again based on the mechanoid race one, that code is following:

<?xml version="1.0" encoding="utf-8" ?>
<ThingDefs>

  <ThingDef ParentName="BasePawn" Name="BaseRobot" Abstract="True">
    <soundImpactDefault>BulletImpactMetal</soundImpactDefault>
    <statBases>
      <PsychicSensitivity>0</PsychicSensitivity>
      <ToxicSensitivity>0</ToxicSensitivity>
      <Flammability>0</Flammability>
      <ComfyTemperatureMin>-100</ComfyTemperatureMin>
      <ComfyTemperatureMax>250</ComfyTemperatureMax>
    </statBases>
    <race>
      <fleshType>Mechanoid</fleshType>
      <needsRest>false</needsRest>
      <hasGenders>false</hasGenders>
      <foodType>None</foodType>
    </race>
  </ThingDef>

  <ThingDef ParentName="BaseRobot">
    <defName>Haulbot</defName>
    <label>haulbot</label>
    <description>A simple hauling robot.</description>
    <statBases>
      <MoveSpeed>1.33</MoveSpeed>
      <ArmorRating_Blunt>0.2</ArmorRating_Blunt>
      <ArmorRating_Sharp>0.7</ArmorRating_Sharp>
      <MeatAmount>0</MeatAmount>
    </statBases>
    <verbs>
      <li>
        <verbClass>Verb_MeleeAttack</verbClass>
        <defaultCooldownTime>2.0</defaultCooldownTime>
        <meleeDamageBaseAmount>20</meleeDamageBaseAmount>
        <meleeDamageDef>Blunt</meleeDamageDef>
        <linkedBodyPartsGroup>HeadAttackTool</linkedBodyPartsGroup>
      </li>
    </verbs>
    <race>
      <intelligence>ToolUser</intelligence>
      <thinkTreeMain>Haulbot</thinkTreeMain>
      <body>MechanicalCentipede</body>
      <baseBodySize>2.0</baseBodySize>
      <baseHealthScale>1.2</baseHealthScale>
      <lifeStageAges>
        <li>
          <def>MechanoidFullyFormed</def>
          <minAge>0</minAge>
          <soundWounded>Pawn_Mech_Centipede_Wounded</soundWounded>
          <soundDeath>Pawn_Mech_Centipede_Death</soundDeath>
          <soundCall>Pawn_Mech_Centipede_Call</soundCall>
        </li>
      </lifeStageAges>
      <soundCallIntervalRange>
        <min>1000</min>
        <max>2000</max>
      </soundCallIntervalRange>
      <soundMeleeHitPawn>Pawn_Melee_MechanoidBash_HitPawn</soundMeleeHitPawn>
      <soundMeleeHitBuilding>Pawn_Melee_MechanoidBash_HitBuilding</soundMeleeHitBuilding>
      <soundMeleeMiss>Pawn_Melee_MechanoidBash_Miss</soundMeleeMiss>
    </race>
    <recipes>
      <li>ShutDownMechanoid</li>
    </recipes>
    <butcherProducts>
      <Steel>80</Steel>
      <Plasteel>50</Plasteel>
      <Component>2</Component>
    </butcherProducts>
  </ThingDef>


</ThingDefs>


And finally I created a "Pawnkinds_Robot" xml, again, predicably, based on on the mechanoid equivalent, code below:

<?xml version="1.0" encoding="utf-8" ?>
<PawnKindDefs>

  <PawnKindDef Name="MechanoidBase" Abstract="True">
    <bodyGraphicData>
      <shaderType>Cutout</shaderType>
    </bodyGraphicData>
    <dessicatedBodyGraphicData>
      <shaderType>Cutout</shaderType>
    </dessicatedBodyGraphicData>
  </PawnKindDef>

  <PawnKindDef>
    <defName>Haulbot</defName>
    <label>haulbot</label>
    <race>Haulbot</race>
    <combatPower>290</combatPower>
    <defaultFactionType>PlayerColony</defaultFactionType>
    <aiAvoidCover>true</aiAvoidCover>
    <lifeStages>
      <li>
        <bodyGraphicData>
          <texPath>Things/Pawn/Mechanoid/Centipede</texPath>
          <graphicClass>Graphic_Multi</graphicClass>
          <drawSize>3</drawSize>
          <shadowData>
            <volume>(0.6, 0.8, 0.6)</volume>
          </shadowData>
        </bodyGraphicData>
      </li>
    </lifeStages>
  </PawnKindDef>

</PawnKindDefs>


So it all seems like it should work at a basic level to me, and in game I am able to load it up without errors, and use the development tools to spawn one in (At the moment it looks like a centipede until I replace that), and it then schlomps around for a few seconds and then Rimworld freezes and crashes. I cant work out why this is happening, and I cant find any sort of error log or anything. Does anyone here know what might be causing it? Im sorry to basically code-dump here, but I felt it would be better to give all the information first.

If you are feeling generous I also have a couple of other more general questions I would really appreciate an answer for:
1) What does "Lord" mean in the code? "LordDuty" and a few other things appear around the code and I have no idea what that means.
2) What is the "MaxDanger" tag in the ThinkTree xml's?
3) Is there a better way to do what I am trying to do here?

Thank you so much for any help you can provide.

Fyre

Okay so I narrowed to problem down to the faction it is assigned to. When I assign the robot to the PlayerColony faction the game crashes shortly after I spawn one in, however when it has no faction, or the mechanoid faction, its fine. Does anyone know why giving it the players faction might be causing Rimworld to crash, and is there any way to fix it?

scuba156

I believe I seen people talking about this on the discord server, and from my understanding any pawn with fleshtype mechanoid is an enemy pawn by default which explains your crashes when setting it to player faction.

You will most likely need to find that method and detour it.

Haplo

Pawn changes are always a bit tricky and you can't do them in most of the cases without some c# programming.
The hauling is one of the easier worktypes, as the game already provides the JobGiver for it (from the trainable animals)
If you later on want to include other worktypes THEN it will get really complicated really soon. (I know what I'm speaking of, I have just reworked my robots to use the animals as a base and that was a real pain sometimes..)
For the Lord duty parts in the ThinkTree: These are for when the pawn isn't a colony member but a part of an independend Group (The Lord is the group manager who handles the Group behaviour, Jobs, ...)