Defines the cw.class library, the registry of classes, the roles a character can take within a faction.

A class is created with cw.class:New and registered as a team. The library answers queries about a class (its limit, model, flags or any field) and moves players between classes with cw.class:AssignToDefault and the server-only cw.class:Set.

Summary

Methods

Moves a player into a suitable class for their faction.
Finds a class by team index or exact name.
GetAll()shared
Returns every registered class keyed by name.
Returns the model and skin a player should use in a class.
Returns the registered classes keyed by team index.
Returns how many players may be in a class right now.
Returns a class's model for a gender.
Returns the registered classes keyed by name.
Returns whether a class has at least one of the given flags.
Returns whether a class has every one of the given flags.
New(name)shared
Creates a new, unregistered class object.
Returns a field of a class.
Registers a class and sets it up as a team.

Methods

cw.class:AssignToDefault(player)

shared gamemodes/catwork/gamemode/core/libraries/sh_class.lua:147

Moves a player into a suitable class for their faction.

Picks a random class marked isDefault for the player's faction. Without one it uses the first class of the faction, then the first class the player has access to. Calls cw.class:Set, which only exists on the server.

Parameters

  • player Player The player to assign

Returns

  • Boolean Whether the class was set
  • String The reason it was not, or nothing if no suitable class exists

cw.class:FindByID(identifier)

shared gamemodes/catwork/gamemode/core/libraries/sh_class.lua:128

Finds a class by team index or exact name.

Parameters

  • identifier Any Team index (Number or numeric String) or class name

Returns

  • Class The class, or nil if none matches

Returns every registered class keyed by name.

Returns

  • Map<Class> Classes keyed by name

cw.class:GetAppropriateModel(name, player, noSubstitute)

shared gamemodes/catwork/gamemode/core/libraries/sh_class.lua:187

Returns the model and skin a player should use in a class.

Uses the class's model for the player's gender, or the class's GetModel(player, defaultModel) callback when it has one. Missing values fall back to the player's default model and skin 1.

Parameters

  • name Any Class name or team index
  • player Player The player the model is for
  • noSubstitute Boolean optional, defaults to nil Return nil instead of the fallback model and skin

Returns

  • String The model path
  • Number The skin

Returns the registered classes keyed by team index.

Returns

  • Map<Class> Classes keyed by their team index

Returns how many players may be in a class right now.

A class's limit is relative to a full 128-player server, so the real limit scales with the current player count. Classes with the default limit of 128 return game.MaxPlayers().

Parameters

  • name Any Class name or team index

Returns

  • Number The current limit, or 0 if the class is not found

cw.class:GetModelByGender(name, gender)

shared gamemodes/catwork/gamemode/core/libraries/sh_class.lua:227

Returns a class's model for a gender.

Reads the class's maleModel or femaleModel, which can be a path or a { model, skin } table.

Parameters

  • name Any Class name or team index
  • gender String Gender name, GENDER_MALE or GENDER_FEMALE

Returns

  • String The model path, or nil if the class has none
  • Number The skin (0 when the model is a plain path)

Returns the registered classes keyed by name.

Returns

  • Map<Class> Classes keyed by name

See also

cw.class:HasAnyFlags(name, flags)

shared gamemodes/catwork/gamemode/core/libraries/sh_class.lua:243

Returns whether a class has at least one of the given flags.

Parameters

  • name Any Class name or team index
  • flags String Flag characters to look for

Returns

  • Boolean true if any flag matches, otherwise nil

See also

cw.class:HasFlags(name, flags)

shared gamemodes/catwork/gamemode/core/libraries/sh_class.lua:263

Returns whether a class has every one of the given flags.

Parameters

  • name Any Class name or team index
  • flags String Flag characters that must all be present

Returns

  • Boolean Whether all flags are present, or nil if the class is not found

See also

Creates a new, unregistered class object.

Set its fields (color, factions, maleModel, femaleModel, limit, wages, flags, isDefault...) and call CLASS_TABLE:Register on it.

local CLASS = cw.class:New('#Class_Citizen')
  CLASS.color = Color(150, 125, 100, 255)
  CLASS.factions = { FACTION_CITIZEN }
  CLASS.isDefault = true
CLASS_CITIZEN = CLASS:Register()

Parameters

  • name String optional, defaults to 'Unknown' Name of the class

Returns

  • Class The new class object

cw.class:Query(name, key, default)

shared gamemodes/catwork/gamemode/core/libraries/sh_class.lua:286

Returns a field of a class.

Parameters

  • name Any Class name or team index
  • key String Field to read
  • default Any optional, defaults to nil Value returned when the class is not found or the field is nil or false

Returns

  • Any The field's value, or default

cw.class:Register(data, name)

shared gamemodes/catwork/gamemode/core/libraries/sh_class.lua:68

Registers a class and sets it up as a team.

Fills in defaults: each gender model falls back to the other, flags to 'b', limit to 128, wages to 0 and factions to an empty list. The team index is a short CRC of the name. On the server the class image (if any) is added to the client download list during the first boot.

Parameters

  • data Class The class object or table
  • name String Name of the class, also used as the team name

Returns

  • Number The class's team index

cw.class:Set(player, name, noRespawn, addDelay, noModelChange)

server gamemodes/catwork/gamemode/core/libraries/sh_class.lua:309

Moves a player into a class.

Sets the player's team, updates their model with the PlayerSetModel hook and respawns them (a light spawn that keeps weapons and ammo when they are alive and not ragdolled). Runs the PlayerClassSet hook (via hook.Run) with the player, the new and old class and the flags.

Parameters

  • player Player The player to move
  • name Any Class name or team index
  • noRespawn Boolean optional, defaults to nil Do not respawn the player
  • addDelay Boolean optional, defaults to nil Start the change_class_interval cooldown before the next change
  • noModelChange Boolean optional, defaults to nil Keep the player's current model

Returns

  • Boolean Whether the class was set
  • String The reason it was not, as a language phrase

Defined in