RivalityFX Docsrivalityfx.com ↗

Registration — registerMode / unregisterMode

Stability: Stable.

The entry point for every mode. A mode resource builds a plain-data descriptor and registers it with the SDK (exports.sdk:registerMode), which the engine mirrors and runs.

exports.sdk:registerMode(def)

Registers a mode. Call it from your mode resource once the SDK has started.

CreateThread(function()
    while GetResourceState('sdk') ~= 'started' do Wait(100) end
    exports.sdk:registerMode(MODE)
end)
ParameterTypeRequiredNotes
deftableyesThe mode descriptor. Must have a unique def.id.

Validation

The descriptor is validated before it is accepted (Sdk.validateMode). A plain-data mode otherwise fails silently at runtime — a mistyped role spawns players into the void, an unknown driver leaves them frozen on "Waiting for players…". Validation turns those into a clear console diagnostic.

  • Errors refuse the mode. If anything is structurally wrong, the mode is not registered and every problem is printed:

    [sdk] mode koth REFUSED -- 2 error(s):
    [sdk]   - `teamCount` must be an integer >= 2 (the number of teams)
    [sdk]   - `rules.win` is required -- one of { roundWins=N } | { score=N } | { timeLimit=S }
  • Warnings are logged but allowed (e.g. a driver not registered yet, no teamCount for a teamless mode, an unpinned apiVersion).

  • What's checked: id/types/enums (queue), apiVersion vs the SDK, teamCount (integer ≥ 2; only 2 supported today), minToStart ≤ perTeam, numeric timings, armor/loadout shapes, and the full rules block (structure, phases, score, win, zones). Game-design choices (round counts, kill limits, …) are never second-guessed. Arena spawn coverage is checked by the engine at consume time (an arena block with fewer entries than your teamCount logs a warning).

Behaviour

  • The SDK tags the descriptor with the calling resource (def.resource = GetInvokingResource()), so it can drop the mode if that resource stops.

  • Missing fields are filled with defaults at registration time:

    FieldDefault applied
    perTeam1
    minToStart1
    maxRound-1
    timings{}
    teamCount2 (only when rules is present)

    Other fields (e.g. rules, driver, label, respawns) are not defaulted here — behaviour resolves at tick time (tick > rules runtime > named driver) and rules/phase keys fall back inside the runtime. See Mode descriptor for the full default table.

  • Registering an id that already exists overwrites the previous descriptor.

  • On success the SDK prints:

    [sdk] mode registered: <id> (<label>) from <resource>

Registering the same def table more than once is harmless (it just re-registers the same id). Register each mode once, after the SDK is started.

exports.sdk:unregisterMode(id)

Removes a mode by id. After this, the mode no longer appears in the lobby and players can no longer join it. Existing scenes of that mode are not torn down by this call — they drain as players leave.

exports.sdk:unregisterMode('mygame')
ParameterTypeRequiredNotes
idstringyesThe id of a registered mode. Unknown ids are a no-op.

Automatic cleanup

You usually don't need unregisterMode. When a mode's owning resource stops, the SDK automatically unregisters every mode tagged with that resource, so a stopped mode can never have its hooks invoked again. Restarting your mode resource re-runs your registration thread and re-registers it.

See also