Skip to content

[CPLUS plus ex] Skill Constraints

DasKeifer edited this page Sep 30, 2026 · 5 revisions

Skill Constraints

Functions for defining skill exclusions, inclusions, and custom constraint logic.

Table of Contents

registerConstraintFunction

  • void cplus_plus_ex:registerConstraintFunction(constraintFn, constraintType)
Argument name Type Description
constraintFn function Constraint function that returns true/false
constraintType string Optional. "inclusion", "exclusion", or "any" / nil (default)

Registers a custom constraint function. Constraint functions are called during skill selection to determine if a candidate skill can be assigned to a pilot.

constraintType:

Value Behavior
"inclusion" Only runs for inclusion-type skills. OR logic. At least one inclusion constraint must pass
"exclusion" Only runs for default/exclusion-type skills. AND logic. All must pass
"any" or nil Runs for all skills. AND logic. All must pass

Constraint function signature:

function(pilot, selectedSkills, candidateSkillId)
    -- pilot: memhack Pilot struct
    -- selectedSkills: Array like table of skill IDs already selected for this pilot
    -- candidateSkillId: Skill ID being considered for assignment
    -- Return true to allow, false to block
    return boolean
end

Example:

-- Only allow powerful skill for slot 2
cplus_plus_ex:registerConstraintFunction(function(pilot, selectedSkills, candidateSkillId)
    if candidateSkillId == "StrongSkill" then
        return #selectedSkills > 1
    end
    return true
end)

checkSkillConstraints

  • bool cplus_plus_ex:checkSkillConstraints(pilot, selectedSkills, candidateSkillId)
Argument name Type Description
pilot Pilot memhack Pilot struct
selectedSkills table Array like table of skill IDs already selected for this pilot
candidateSkillId string Skill ID being considered
slotIdx int Optional explicit skill slot (1 or 2, or 3+ for virtual). When omitted, inferred as #selectedSkills + 1

Generally not expected to be used by mods. May be useful for testing added constraints

Checks if a candidate skill can be assigned to a pilot based on all registered constraint functions. Returns true if all constraints pass, false if any constraint blocks the skill.

Example:

local pilot = Game:GetSquadPilots()[1]
local alreadySelected = {"Health"}

if cplus_plus_ex:checkSkillConstraints(pilot, alreadySelected, "Move", 2) then
    LOG("Move skill is allowed for this pilot in slot 2")
end

Clone this wiki locally