Damage Def Help

Started by BasedGreg, May 31, 2019, 06:23:30 PM

Previous topic - Next topic

BasedGreg

Hello Ludeon,
I'm here due to the fact that I have very little idea as to what I'm doing.
I have a little personal mod I work on that adds a couple guns and melee weapons and I have run into a bit of a roadblock.

One of my recent weapons, a charge "revolver", has something that I haven't tried before. I was going to add a taser to the front of the weapon in order to amplify its melee effectiveness. I have long since given up on trying to add Stun as one of the capacities of the melee attacks and have gone on to trying to make my own damage def that works similarily to blunt damage but has an extended stun duration.

Here's what I have so far for the damage def:

<DamageDef Name="TaseBase">
    <defName>Tase</defName>
    <label>tase</label>
    <workerClass>DamageWorker_Blunt</workerClass>
    <externalViolence>true</externalViolence>
    <deathMessage>{0} has been tased to death.</deathMessage>
    <hediff>Crush</hediff>
    <hediffSkin>Bruise</hediffSkin>
    <hediffSolid>Crack</hediffSolid>
    <harmAllLayersUntilOutside>true</harmAllLayersUntilOutside>
    <impactSoundType>Blunt</impactSoundType>
    <armorCategory>Blunt</armorCategory>
    <overkillPctToDestroyPart>0.2~0.6</overkillPctToDestroyPart>
    <buildingDamageFactor>1.5</buildingDamageFactor>
    <bluntStunDuration>12.0</bluntStunDuration>
    <bluntInnerHitChance>0.4</bluntInnerHitChance>
    <bluntInnerHitDamageFractionToConvert>
      <min>0.1</min>
      <max>0.2</max>
    </bluntInnerHitDamageFractionToConvert>
    <bluntInnerHitDamageFractionToAdd>
      <min>0.2</min>
      <max>0.35</max>
    </bluntInnerHitDamageFractionToAdd>
    <bluntStunChancePerDamagePctOfCorePartToHeadCurve>
      <points>
        <li>(0.04, 0.20)</li>
        <li>(0.5, 1)</li>
      </points>
    </bluntStunChancePerDamagePctOfCorePartToHeadCurve>
    <bluntStunChancePerDamagePctOfCorePartToBodyCurve>
      <points>
        <li>(0.4, 0)</li>
        <li>(0.9, 0.15)</li>
      </points>
    </bluntStunChancePerDamagePctOfCorePartToBodyCurve>
  </DamageDef>


And here's my code for the weapon itself:

<ThingDef ParentName="BaseHumanMakeableGun">
    <defName>Gun_chargeRevolver</defName>
    <label>reducer</label>
    <description>The quickest draw in the galaxy, this spacer tier revolver uses an entire cartridge for each shot. The resulting effect is a slow yet terribly, powerful shot. The muzzle of the gun is armed with a powerful tazer for stunning opponents that get a bit too close and personal.</description>
    <graphicData>
      <texPath>Things/Ranged/Reducer</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <soundInteract>Interact_Revolver</soundInteract>
    <statBases>
      <WorkToMake>29000</WorkToMake>
      <Mass>1.6</Mass>
      <AccuracyTouch>0.81</AccuracyTouch>
      <AccuracyShort>0.78</AccuracyShort>
      <AccuracyMedium>0.62</AccuracyMedium>
      <AccuracyLong>0.53</AccuracyLong>
      <RangedWeapon_Cooldown>2.2</RangedWeapon_Cooldown>
    </statBases>
    <weaponTags>
      <li>SpacerGun</li>
      <li>Revolver</li>
    </weaponTags>
    <costList>
      <Plasteel>45</Plasteel>
      <ComponentSpacer>3</ComponentSpacer>
    </costList>
    <recipeMaker>
  <researchPrerequisite>ChargedShot</researchPrerequisite>
      <skillRequirements>
        <Crafting>9</Crafting>
      </skillRequirements>
  <recipeUsers Inherit="False">
        <li>FabricationBench</li>
      </recipeUsers>
    </recipeMaker>
    <verbs>
      <li>
        <verbClass>Verb_Shoot</verbClass>
        <hasStandardCommand>true</hasStandardCommand>
        <defaultProjectile>Bullet_chargeRevolver</defaultProjectile>
        <warmupTime>0.01</warmupTime>
        <range>30</range>
        <soundCast>Shot_ChargeRifle</soundCast>
        <soundCastTail>GunTail_Light</soundCastTail>
        <muzzleFlashScale>9</muzzleFlashScale>
      </li>
    </verbs>
    <tools>
      <li>
        <label>grip</label>
        <capacities>
          <li>Blunt</li>
        </capacities>
        <power>11</power>
        <cooldownTime>2</cooldownTime>
      </li>
      <li>
        <label>barrel</label>
        <capacities>
  <li>Tase</li>
  <li>Poke</li>
        </capacities>
<power>11</power>
        <cooldownTime>2.5</cooldownTime>
      </li>
    </tools>
  </ThingDef>


When I do this all I get is this error:

Could not resolve cross-reference to Verse.ToolCapacityDef named Tase (wanter=capacities)
Verse.Log:Error(String, Boolean)
Verse.DirectXmlCrossRefLoader:TryResolveDef(String, FailMode, Object)
Verse.WantedRefForList`1:TryResolve(FailMode)
Verse.DirectXmlCrossRefLoader:ResolveAllWantedCrossReferences(FailMode)
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.Root:<Start>m__1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__1()

Cannot call ItemFromXmlFile with resolveCrossRefs=true while loading is already in progress.
Verse.Log:Error(String, Boolean)
Verse.DirectXmlLoader:ItemFromXmlFile(String, Boolean)
RimWorld.PlayerKnowledgeDatabase:ReloadAndRebind()
RimWorld.PlayerKnowledgeDatabase:.cctor()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.Root:<Start>m__1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__1()


I have no idea what to do at this point so this is my last attempt before my dream of a charge taser revolver dies.
Halp.

yadaptor

Hello there, I think I may be able to help.
I see that you did an Damagedef, which seems ok, but the gun itself may not target the damagedef itself, instead it may target a thing called Maneuverdef. Which in fact, calls for a damagedef. Here, a maneuverdef for a Stab:
  <ManeuverDef>
    <defName>Stab</defName>
    <requiredCapacity>Stab</requiredCapacity>
    <verb>
      <verbClass>Verb_MeleeAttackDamage</verbClass>
      <meleeDamageDef>Stab</meleeDamageDef>
    </verb>
    <logEntryDef>MeleeAttack</logEntryDef>
    <combatLogRulesHit>Maneuver_Stab_MeleeHit</combatLogRulesHit>
    <combatLogRulesDeflect>Maneuver_Stab_MeleeDeflect</combatLogRulesDeflect>
    <combatLogRulesMiss>Maneuver_Stab_MeleeMiss</combatLogRulesMiss>
    <combatLogRulesDodge>Maneuver_Stab_MeleeDodge</combatLogRulesDodge>
  </ManeuverDef>

Try doing one of those, calling for your damagedef, see how that plays out

BasedGreg

Thank you so much for pointing that out. After tinkering around with code for a bit I managed to get the game to load without an error code. But now I seem to have run into a very strange effect. Whenever I try to melee attack with the revolver, the pawn just drops it wherever they are and goes to punch their opponent to death, inevitably dying in the process.

:/

So I have no idea what to do with that. Any suggestions?

yadaptor

I still have to test it, not really sure if it's vanilla or modded behaviour, but if you're manually telling the pawns to attack someone mellee, they drop their ranged weapons, only attacking with their gun if the enemy comes to their mellee range (mine do, that's why I'm not sure if it's modded or not, so many mods).
Or are they simply droping the gun when the enemy gets in their punching range?

Mehni

Quote
<capacities>
        <li>Tase</li>
        <li>Poke</li>
</capacities>

Here you tell the game: "Use my Tase ToolCapacityDef".

QuoteCould not resolve cross-reference to Verse.ToolCapacityDef named Tase (wanter=capacities)

Here the game says to you: "You don't have a ToolCapacityDef named Tase".

To make a fresh new melee attack you need about 4 different moving parts, and you're missing at least one of them. The ManeuverDef is also one of them: see the <requiredCapacity> tag? That is another link to the ToolCapacityDef.

It feels like an over-engineered system, but it is what it is.

account13123

I was wrestling with this to try and make a non-overpowered nonlethal melee weapon option since almost everything in the workshop is like, sniper rifles that instantly down people in power armor from across the map which is just way too crazy. So I tried making a sap/blackjack.

For a ranged weapon like a taser or beanbag, it's trivial; define your incapacitating hediff, define a damage type that applies it, and call that damage type in the gun's bullet definition.

For melee weapons it seems your weapon's melee attack("tool") needs you to define a capacity which needs you do define a maneuver which needs you to define a damage type which you then finally attach your hediff definition to. 4 different XML files on top of your thing def! And clearly I missed something, because it still didn't work. That's what I get for trying to cargo cult code without knowing what it does.