Making Your Own Stats - KonradHeinser/EBSGFramework GitHub Wiki

Intro

In many of the comps in this framework you'll find several of them have sections for stats, like Burst Attack's statRadius; Various Explosion Hediffs' statRadius; Dynamic Resource Gene's maxStat, gainStat, and passiveFactorStat; or the stat limiters in Terrain Cost Override and Ability Validator's. The list could go on, but this page is going to assume that you're here because you found one of those and want to make your own stat. Please note that if you want the stat to do something more advanced (i.e. act as a multiplier on the fall or rise rate of a need), that will require C# knowledge on how to create a defof file, and usually some Harmony patches if the effect is on base game stuff or another mod. Most of the stuff mentioned on this page don't require this framework at all, though near the end I will be talking about anything extra that this framework does allow you to do with stats.


Vanilla Stuff

Much like most other things, all stats have a defName, a label, and a description:

    <StatDef>
        <defName>InsertDefNameHere</defName>
        <label>this is a label</label>
        <description>And this is a description.</description>
    </StatDef>

Much like most other things, it also has various sections not usually seen in other defs. These are all the basic ones:

  • toStringStyle : How is it displayed? If you aren't sure, just go with a few guesses until you find one you like. These are the options you can usually use, though there are other less used ones not listed:
    • PercentZero
    • PercentOne
    • PercentTwo
    • Integer
    • FloatOne
    • FloatTwo
  • showDevelopmentalStageFilter : What stage does this appear for?
    • Child : Only childhood
    • Adult : Only adulthood
    • Child, Adult : Both childhood and adulthood
  • category : What category to assign it in the stat list. Common options include:
    • BasicsPawn
    • PawnCombat
    • PawnWork
    • PawnMisc
    • PawnSocial
  • displayPriorityInCategory : Where in the category does the item appear
  • minValue : The lowest value the stat should have. Usually 0, or a number very close to zero if it's not something you want to allow to be disabled
  • defaultBaseValue : The value the stat will sit at if there are no offsets or factors impacting it. Usually one of these 3:
    • 0 : Used for offsets or stats that you only want to make usable if there is a statOffset in effect somewhere
    • 1 : Usually used for factors because a value of 1 means that the stat usually has no impact
    • Other : Numbers greater than 1 are used for most other things, like radius and range stats
  • hideAtValue : Usually the same as the defaultBaseValue, or 0 in a few cases
  • alwaysHide : If true, it always hides the stat, regardless of hideAtValue
  • statFactors : A list of stats that will affect this one. This allows you to link stats together

Simple Stat Example

While the pregnancy speed stat does involve C#, specifically a harmony patch because it changes how pregnancy works slightly, the xml side of it only uses the things mentioned here in the basics section. In fact, at time of writing there are 26 stats, and only 6 of them require any xml more advanced than what is discussed above. All 6 are the specialized outgoing damage stats which I explain more of near the end of this page:

    <StatDef>
        <defName>EBSG_PawnGestationSpeed</defName>
        <label>pregnancy speed</label>
        <description>There was a description here.</description>
        <category>BasicsPawn</category>
        <defaultBaseValue>1</defaultBaseValue>
        <hideAtValue>1</hideAtValue>
        <minValue>0.001</minValue>
        <showDevelopmentalStageFilter>Adult</showDevelopmentalStageFilter>
        <toStringStyle>PercentZero</toStringStyle>
        <displayPriorityInCategory>2201</displayPriorityInCategory>
    </StatDef>

Linked Stat Example

SHG - Just the Hemomancer utilizes stats for the range of many of its abilities. It starts with a factoring stat that is only increased through certain genes. Then it makes 5 levels of ranges with stats, and has these ranges use the factoring stat in its statFactors section, resulting in the pawn's ability ranges being dynamically based on the genes the pawn has. Note that while the difference in ranges appears to be small, these can grow very quickly. If only taking 2 genes, long range is limited to 23 tiles, but with 4 it grows to 46, and by 6 it goes to 69, which is more than any vanilla weapons, excluding mortars:

    <StatDef>
        <defName>SHG_HemomancyProficiency</defName>
        <label>hemomancy proficiency</label>
        <description>description.</description>
        <category>BasicsPawn</category>
        <defaultBaseValue>0</defaultBaseValue>
        <hideAtValue>0</hideAtValue>
        <minValue>0</minValue>
        <toStringStyle>PercentZero</toStringStyle>
        <displayPriorityInCategory>3450</displayPriorityInCategory>
    </StatDef>

    <StatDef Name="SHG_HemomancerRangeStats" Abstract="true">
        <category>BasicsPawn</category>
        <showIfUndefined>false</showIfUndefined>
        <displayPriorityInCategory>3450</displayPriorityInCategory>
        <statFactors>
            <li>SHG_HemomancyProficiency</li>
        </statFactors>
        <alwaysHide>true</alwaysHide>
    </StatDef>

    <StatDef ParentName="SHG_HemomancerRangeStats">
        <defName>SHG_HemomancerRange_Touch</defName>
        <label>hemomancer touch range</label>
        <description>The range stat for all extremely close range hemomancer abilities.</description>
        <defaultBaseValue>2</defaultBaseValue>
    </StatDef>

    <StatDef ParentName="SHG_HemomancerRangeStats">
        <defName>SHG_HemomancerRange_Short</defName>
        <label>hemomancer short range</label>
        <description>The range stat for all short range hemomancer abilities.</description>
        <defaultBaseValue>5</defaultBaseValue>
    </StatDef>

    <StatDef ParentName="SHG_HemomancerRangeStats">
        <defName>SHG_HemomancerRange_Medium</defName>
        <label>hemomancer medium range</label>
        <description>The range stat for all medium range hemomancer abilities.</description>
        <defaultBaseValue>12</defaultBaseValue>
    </StatDef>

    <StatDef ParentName="SHG_HemomancerRangeStats">
        <defName>SHG_HemomancerRange_Long</defName>
        <label>hemomancer long range</label>
        <description>The range stat for all long range hemomancer abilities.</description>
        <defaultBaseValue>23</defaultBaseValue>
    </StatDef>

    <StatDef ParentName="SHG_HemomancerRangeStats">
        <defName>SHG_HemomancerRange_Extreme</defName>
        <label>hemomancer extreme range</label>
        <description>The range stat for all extreme range hemomancer abilities.</description>
        <defaultBaseValue>38</defaultBaseValue>
    </StatDef>

EBSG Specific stuff

At time of typing, there isn't much this framework does on the stat making front, but this section will give all the options presently available for general use.


  • EBSGDamageExtension : Causes the outgoing damage of a pawn to be multiplied by the stat's value when a valid target is hit. While the framework contains stats for each individual category, this extension can be used to make stats that multiply damage against more than one type of target. By default, all categories are marked false, so you only need to mark them true as needed
    • allowHumanlikes
    • allowDryads
    • allowInsects
    • allowAnimals
    • allowMechanoids
    • allowEntities
    <StatDef ParentName="EBSG_FactoringStat">
        <defName>EBSG_OutgoingDamageFactor_Entity</defName>
        <label>outgoing damage factor (entity)</label>
        <description>A multiplier on outgoing damage against entity targets.</description>
        <category>PawnCombat</category>
        <displayPriorityInCategory>5207</displayPriorityInCategory>
        <modExtensions>
            <li Class="EBSGFramework.EBSGDamageExtension">
                <allowEntities>True</allowEntities>
            </li>
        </modExtensions>
    </StatDef>

⚠️ **GitHub.com Fallback** ⚠️