Skip to content

[CPLUS plus ex] SkillTrait Base Class

DasKeifer edited this page Oct 8, 2026 · 3 revisions

SkillTrait Base Class

Base class for pilot skills that add vanilla traits to pawns (e.g., "Jumper" or "Guarded").

Basic Usage

local mySkill = cplus_plus_ex.baseClasses.SkillTrait:new{
    id = "MyCustomTrait",
    shortName = "Custom Trait",
    fullName = "Custom Trait",
    description = "Adds a custom status effect",
    trait = "Custom_Status_Icon"  -- Optional: trait ID to display
}

-- Override applyTrait to implement your trait's behavior
function mySkill:applyTrait(pawnId, pawn, isActive)
    if isActive then
        -- Skill just activated - add effects
        pawn:SetCustom("My_Custom_Effect", true)
    else
        -- Skill deactivated - remove effects
        pawn:SetCustom("My_Custom_Effect", false)
    end
end

function mod:init()
    cplus_plus_ex:registerSkill("Custom", mySkill)
end

Methods to Override

applyTrait(pawnId, pawn, isActive)

Called whenever the skill activates or deactivates on a pawn.

Parameters:

  • pawnId (number): Pawn ID (0-2 for player mechs)
  • pawn (Pawn): The pawn object (from Game:GetPawn(pawnId))
  • isActive (boolean): true when skill activates, false when it deactivates

Important: This is called for activation AND deactivation. Always check isActive to know which operation to perform.

Example:

function mySkill:applyTrait(pawnId, pawn, isActive)
    if isActive then
        -- Add bonus armor
        pawn:SetArmor(true)
    else
        -- Remove bonus armor
        pawn:SetArmor(false)
    end
end

Skill Definition Properties

Registering with SkillTrait:new{}, you can include any of standard properties as supported by Skill Registration. See that page for full details on supported properties.

When Skills Activate/Deactivate

Skills are considered "active" when:

  1. The pilot has earned the skill (reached the appropriate level)
  2. The pilot is in one of the 3 active mechs

applyTrait() is called:

  • When a pilot with this skill enters a mech (activation)
  • When a pilot with this skill exits a mech (deactivation)
  • When loading a saved game with an active skill
  • When a pilot levels up and earns this skill (if already in a mech)

Internal Details

The SkillTrait class:

  • Subscribes to cplus_plus_ex.events.onSkillActive
  • Maintains a registry of all SkillTrait-based skills in SkillTrait.skills
  • Automatically calls applyTrait() when skill state changes

You generally don't need to interact with these internals.

Clone this wiki locally