Skip to content

WeaponTraitDefExtension

juanosarg edited this page Jun 3, 2026 · 1 revision

<- Back

IMPORTANT: This requires a feature to be toggled, learn how here: OptionalFeatures

WeaponTraitDefExtension is a def extension that adds a few custom behaviours for the ranged weapon traits added by Odyssey.

      //Swaps the projectiles produced by this unique weapon for another ones
      public ThingDef projectileOverride;
      //This allows users to specify different projectiles for different guns. If not found, projectileOverride will be used
      public Dictionary<ThingDef, ThingDef> projectileOverrides;
      //If set to true, this projectile override will be ignored if another WeaponTraitDef adds a different override
      public bool lowPreferenceProjectileOverride = false;
      //Swaps the sound produced when firing this unique weapon for another one
      public SoundDef soundOverride;
      //Swaps the sound produced when hitting a pawn with this weapon with melee
      public SoundDef meleeSoundOverride;
      //Override the damage type of the melee attacks with this weapon
      public DamageDef meleeDamageOverride;
      //Swaps the graphic of the weapon. Supports Graphic_Single and Graphic_Random, as well as CutOutComplex
      public Dictionary<ThingDef,GraphicData> graphicOverrides;
      //Graphic overrides will be chosen by the order of this number. Higher takes precedence.
      public float graphicOverridePriority = 100;
      //Add this ability to the wielder when equipping the weapon (and remove it when not in his possession)
      public AbilityDef abilityToAdd;
      //Add this hediff to the wielder after killing a target
      public HediffDef killHediff;
      public float killHediffSeverity = 1;
      //This scales the draw size of the weapon. What a silly thing.
      public float sizeMultiplier = 1;
      //This will make the gun create random projectiles every time it fires. Shenanigan potential: maximum
      public bool randomprojectiles = false;
      //If true, the MaxHitPoints stat of the weapon will be refreshed when the trait is added. This only works if the WeaponTraitDef
      //is assigned VEF.Weapons.WeaponTraitWorker_Extended as its workerClass
      public bool refreshMaxHitPointsStat = false;
      //Conditional stat affecters, like those in genes and precepts, are possible now
      public List<ConditionalStatAffecter> conditionalStatAffecters;
      //This is a system to add abilities with charges via traits, hopefully working better than the vanilla system
      public AbilityWithChargesDetails abilityWithCharges;
      ////Swaps the verbs used by this unique weapon for another ones
      public List<VerbProperties> verbsOverride;
      //This allows users to specify different verbs for different guns. If not found, verbsOverride will be used
      public Dictionary<ThingDef, List<VerbProperties>> verbsOverrides;
      //This randomizes the cooldown of the weapon
      public FloatRange coolDownRange = FloatRange.Zero;
      //This randomizes the burst count of the weapon
      public List<float> burstShotCountRange;
      //This destroys the weapon after a certain amount of shots are fired
      public int limitedUses = 0;
      //Contraband impact. Having this weapon equipped in your colony will cause an impact if visited by a specific faction caravan
      public List<FactionRelationImpacts> factionRelationImpacts;
      //Draws a duplicate of the gun
      public bool drawDuplicate = false;

AbilityWithChargesDetails and FactionRelationImpacts are wrapper classes:

    public class AbilityWithChargesDetails
    {
        public AbilityDef abilityDef;
        public int maxCharges;
        public ThingDef ammoDef;
        public int ammoCountPerCharge;
        public int baseReloadTicks = 60;
        public SoundDef soundReload;
        public string chargeNoun = "charge";
        public string cooldownGerund = "on cooldown";
        public NamedArgument ChargeNounArgument => chargeNoun.Named("CHARGENOUN");

}
    public class FactionRelationImpacts
    {
        public FactionDef factionDef;
        public HistoryEventDef eventDef;
        public int impact;
    }

How do I use this code?

This Def Extension is added to the WeaponTraitDef of the weapon trait you want to add them to.

If you aren't sure if the WeaponTraitDef ALREADY has an extension (for example, if you think another mod will add their own), always use XPATH (xml patching) to add an extension, as there is already a PatchOperationAddModExtension to ensure they don't collide.

For example, on Alpha Armoury:

<modExtensions>
	<li Class="VEF.Weapons.WeaponTraitDefExtension">
		<projectileOverride>AArmoury_Corrosive</projectileOverride>
		<soundOverride>AArmoury_Splash</soundOverride>
		<graphicOverrides>
			<li>
				<key>AArmoury_Gun_Launcher_Unique</key>
				<value>
					<texPath>Things/Weapon/AArmoury_Corrosive</texPath>
					<graphicClass>Graphic_Random</graphicClass>
					<shaderType>CutoutComplex</shaderType>
				</value>
			</li>
		</graphicOverrides>
	</li>
</modExtensions>

Another example in Vanilla Weapons Expanded:

<modExtensions>
	<li Class="VEF.Weapons.WeaponTraitDefExtension">
		<factionRelationImpacts>
			<li>
				<factionDef>Empire</factionDef>
				<eventDef>VWE_DeserterMarkings</eventDef>
				<impact>-50</impact>
			</li>
		</factionRelationImpacts>
	</li>
</modExtensions>

Another one:

<modExtensions>
	<li Class="VEF.Weapons.WeaponTraitDefExtension">
		<abilityWithCharges>
			<abilityDef>VWE_LaunchFlare</abilityDef>
			<maxCharges>4</maxCharges>
			<soundReload>Standard_Reload</soundReload>
			<chargeNoun>flare</chargeNoun>
			<ammoDef>Bioferrite</ammoDef>
			<ammoCountPerCharge>5</ammoCountPerCharge>
			<baseReloadTicks>60</baseReloadTicks>
		</abilityWithCharges>			
	</li>
</modExtensions>

Clone this wiki locally