Repository navigation
[CPLUS plus ex] SkillTrait Base Class
DasKeifer edited this page Oct 8, 2026
·
3 revisions
Base class for pilot skills that add vanilla traits to pawns (e.g., "Jumper" or "Guarded").
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)
endCalled whenever the skill activates or deactivates on a pawn.
Parameters:
-
pawnId(number): Pawn ID (0-2 for player mechs) -
pawn(Pawn): The pawn object (fromGame:GetPawn(pawnId)) -
isActive(boolean):truewhen skill activates,falsewhen 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
endRegistering with SkillTrait:new{}, you can include any of standard properties as supported by Skill Registration. See that page for full details on supported properties.
Skills are considered "active" when:
- The pilot has earned the skill (reached the appropriate level)
- 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)
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.