Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Making gun mods CE compatible

XeoNovaDan edited this page Jan 23, 2019 · 9 revisions

CE uses a completely new shooting system which is fundamentally incompatible with vanilla weapons. As such, any mod adding new weapons is also incompatible and needs to be made compatible via patch.

Creating a CE gun def

To explain the changes between vanilla and CE guns we'll use the example of the M60 from the CE guns mod:

  <ThingDef ParentName="BaseHumanMakeableGun">
    <defName>CE_Gun_MSixty</defName>
    <label>M60</label>
    <description>A belt-fed general-purpose machine gun. Lots of firepower but heavy and cumbersome to carry around. Commonly nicknamed "The Pig".</description>
    <graphicData>
      <texPath>Things/Weapons/M60</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <soundInteract>InteractRifle</soundInteract>
    <statBases>
      <WorkToMake>27500</WorkToMake>
      <SightsEfficiency>0.50</SightsEfficiency>
      <ShotSpread>0.06</ShotSpread>
      <SwayFactor>1.51</SwayFactor>
      <Bulk>14.05</Bulk>
      <Mass>10.50</Mass>
      <RangedWeapon_Cooldown>0.56</RangedWeapon_Cooldown>
    </statBases>
    <costList>
      <Steel>90</Steel>
      <Component>4</Component>
    </costList>
    <verbs>
      <li Class="CombatExtended.VerbPropertiesCE">
        <recoilAmount>0.79</recoilAmount>
        <verbClass>CombatExtended.Verb_ShootCE</verbClass>
        <hasStandardCommand>true</hasStandardCommand>
        <projectileDef>Bullet_762x51mmNATO_FMJ</projectileDef>
        <warmupTime>1.25</warmupTime>
        <range>75</range>
        <ticksBetweenBurstShots>6</ticksBetweenBurstShots>
        <burstShotCount>10</burstShotCount>
        <soundCast>ShotMinigun</soundCast>
        <muzzleFlashScale>9</muzzleFlashScale>
        <targetParams>
          <canTargetLocations>true</canTargetLocations>
        </targetParams>
        <recoilPattern>Mounted</recoilPattern>
      </li>
    </verbs>
    <comps>
      <li Class="CombatExtended.CompProperties_AmmoUser">
        <magazineSize>100</magazineSize>
        <reloadTime>7.8</reloadTime>
        <ammoSet>AmmoSet_762x51mmNATO</ammoSet>
      </li>
      <li Class="CombatExtended.CompProperties_FireModes">
        <aiUseBurstMode>FALSE</aiUseBurstMode>
        <aiAimMode>SuppressFire</aiAimMode>
        <aimedBurstShotCount>5</aimedBurstShotCount>
      </li>
    </comps>
    <weaponTags>
      <li>CE_MachineGun</li>
    </weaponTags>
  </ThingDef>

StatBases

    <statBases>
      <WorkToMake>27500</WorkToMake>
      <SightsEfficiency>0.50</SightsEfficiency>
      <ShotSpread>0.06</ShotSpread>
      <SwayFactor>1.51</SwayFactor>
      <Bulk>14.05</Bulk>
      <Mass>10.50</Mass>
      <RangedWeapon_Cooldown>0.56</RangedWeapon_Cooldown>
    </statBases>

First up, you might notice that this gun does not have any of vanilla's Accuracy_Long, etc. stats. CE does not use them, so you should remove them from your guns to avoid cluttering the stats info ingame. Instead CE uses its own stats:

SightsEfficiency: represents how good a weapon's sights are. Iron sights are worse at this than scopes and reflex sights.

Shotspread: is a weapon's base inaccuracy. Think of a shotgun's projectile spread.

SwayFactor: CE has a Lissajous function to determine how much a weapon sways in the shooter's hands (if you don't know what a Lissajous is, don't worry). Higher values mean the weapon sways more.

Bulk: how much space the weapon takes up in the pawn's inventory.

Verbs

    <verbs>
      <li Class="CombatExtended.VerbPropertiesCE">
        <recoilAmount>0.79</recoilAmount>
        <verbClass>CombatExtended.Verb_ShootCE</verbClass>
        <hasStandardCommand>true</hasStandardCommand>
        <projectileDef>Bullet_762x51mmNATO_FMJ</projectileDef>
        <warmupTime>1.25</warmupTime>
        <range>75</range>
        <ticksBetweenBurstShots>6</ticksBetweenBurstShots>
        <burstShotCount>10</burstShotCount>
        <soundCast>ShotMinigun</soundCast>
        <muzzleFlashScale>9</muzzleFlashScale>
        <targetParams>
          <canTargetLocations>true</canTargetLocations>
        </targetParams>
        <recoilPattern>Mounted</recoilPattern>
      </li>
    </verbs>

VerbPropertiesCE: every CE verb entry needs this set to this.

verbClass: this is where CE shooting mechanics are hooked in. It is vital that you are using a CE verb here or else your gun will not work with CE mechanics at all. You can usually just change this to the CE version whatever vanilla verb you're using, i.e.

  • Verb_LaunchProjectile -> Verb_LaunchProjectileCE
  • Verb_Shoot -> Verb_ShootCE
  • Verb_ShootOneUse -> Verb_ShootCEOneUse
  • Verb_MeleeAttack -> Verb_MeleeAttackCE

projectileDef: this doesn't actually do anything in actual gameplay terms if your weapon has CompAmmoUser. Nevertheless it's a good idea to set this to the default projectile for your ammoSet because this will determine what the gun will list under damage in its info tab ingame.

recoilAmount: as a weapon fires a burst, each shot will make it more inaccurate. This factor determines how much recoil is applied between each shot.

recoilPattern: this determines what pattern bullets scatter in, i.e. if the weapon recoils up and to the right or up/down and left/right.

CompAmmoUser

      <li Class="CombatExtended.CompProperties_AmmoUser">
        <magazineSize>100</magazineSize>
        <reloadTime>7.8</reloadTime>
        <ammoSet>AmmoSet_762x51mmNATO</ammoSet>
      </li>

This Comp is responsible for handling the ammo system. If you want your weapon to have infinite ammo and no magazine, you can leave this out.

magazineSize: how many bullets are in a magazine. Weapons with a magazine size of 0 or unspecified will feed ammo directly from inventory (e.g. bows).

reloadTime: how long it takes to reload the gun, in seconds.

ammoSet: what ammo this gun can fire.

CompFireModes

      <li Class="CombatExtended.CompProperties_FireModes">
        <aiUseBurstMode>FALSE</aiUseBurstMode>
        <aiAimMode>SuppressFire</aiAimMode>
        <aimedBurstShotCount>5</aimedBurstShotCount>
      </li>

This comp handles fire and aim modes.

aiUseBurstMode: by default, AI-controlled pawns such as raiders will use full-auto. This will set them to use burst fire instead. Does nothing on weapons that don't have full-auto fire.

aiAimMode: this is the aim mode AI pawns will default to.

aimedBurstShotCount: this determines how many shots will be fired on burst fire mode. Should be a number between 1 and the verb's .

weaponTags

    <weaponTags>
      <li>CE_MachineGun</li>
    </weaponTags>

CE uses various weapon tags to determine things like which weapons can be used with a shield or which pawns can spawn with it. In the above example, CE_MachineGun marks it as an MG, meaning mercenary machine gunners can spawn with it. Other useful tags include:

  • CE_Sidearm, CE_Sidearm_Melee: determine what weapons can spawn in a raider's inventory
  • CE_OneHandedWeapon: whether this can be used with a shield
  • CE_SMG: raider rocketeers will use this as backup weapon

Determining ingame stats

To help mod makers create compatibility patches, we have created a spreadsheet to calculate ingame stats from real-world data. Simply input your data into the 'Weapon Data' and 'Crafting Data' tabs, then extend the rows in the 'Ingame Stats' and 'Crafting Mats' tabs to get the data for your guns. Use the comments in the top row to get an explanation on each column.

Determining ammo

If you're using a real-world gun, chances are the caliber it uses is already included in CE. To find out, open the Combat Extended mod folder and navigate to Defs/Ammo. There you will find the Defs for all ammo types currently in CE. If your caliber is there you can simply point your gun to that and it will automatically be enabled to show up on traders and crafting menus when users load CE with your mod.

If your caliber is not yet part of CE, see the page on creating a caliber.

Submitting your patch

You can create your compatibility patch as a set of xpath patches that modify your gun defs to conform with CE. You can then submit it to us on the forums or through GitHub and we'll include it as part of the main mod. Then if a user loads up your mod alongside CE it will automatically be patched to be compatible, eliminating the need for a separate mod.

For information on how to create a patch for CE see the page on creating an xpath patch.