Skip to content

[CPLUS plus ex] SkillActive Base Class

DasKeifer edited this page Oct 8, 2026 · 3 revisions

SkillActive Base Class

Base class for pilot skills that need to perform custom actions while active. Automatically manages event subscriptions and cleanup.

Basic Usage

local mySkill = cplus_plus_ex.baseClasses.SkillActive:new{
    id = "MyEventSkill",
    shortName = "Event Skill",
    fullName = "Event-Driven Skill",
    description = "Reacts to game events"
}

-- Override setupEffect to register your event handlers
function mySkill:setupEffect()
    -- CRITICAL: Store all subscriptions in self.events for automatic cleanup
    table.insert(self.events, modApi.events.onNextTurn:subscribe(function()
        -- React to turn start
        LOG("New turn started!")
    end))
    
    table.insert(self.events, modapiext.events.onPawnMoved:subscribe(function(mission, pawn)
        if cplus_plus_ex:isSkillOnPawn(self.id, pawn) then
            -- React to pawn with this skill moving
            LOG("Our pawn moved!")
        end
    end))
end

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

Methods to Override

setupEffect()

Called when the skill becomes active on any pawn. Register all your event handlers here.

CRITICAL: Store all event subscriptions in self.events table. The base class will automatically unsubscribe them when the skill deactivates.

Example:

function mySkill:setupEffect()
    -- Subscribe to mission start
    table.insert(self.events, modApi.events.onMissionStart:subscribe(function()
        LOG("Mission started!")
    end))
    
    -- Subscribe to pawn killed
    table.insert(self.events, modApi.events.onPawnKilled:subscribe(function(mission, pawn)
        if pawn:IsEnemy() then
            LOG("Enemy killed!")
        end
    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

A skill is "active" when:

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

setupEffect() is called:

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

clearEvents() is called:

  • When the last pilot with this skill exits their mech
  • When entering the Hangar/Time Pod
  • Before setupEffect() to ensure clean state

Internal Details

The SkillActive class:

  • Subscribes to cplus_plus_ex.events.onSkillActive
  • Maintains a registry of all SkillActive-based skills in SkillActive.skills
  • Calls clearEvents() then setupEffect() whenever skill state changes
  • Initializes self.events = {} in the constructor

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

Clone this wiki locally