Summary

Functions

Finds a faction by index, exact name or part of its name.
GetAll()shared
Returns every registered faction keyed by name.
Returns the registered factions keyed by numeric index.
Returns the faction's default rank, the first rank with default set.
Returns the rank one step above a rank, the one whose position is one lower.
Returns the faction's highest rank, the one with the lowest position.
Returns how many players may be in a faction right now.
Returns the rank one step below a rank, the one whose position is one higher.
Returns the faction's lowest rank, the one with the highest position.
Returns every initialized player in a faction.
Returns the registered factions keyed by name.
Returns whether a player already has the maximum number of characters in a faction.
Returns whether a gender may be chosen for a faction.
Returns whether a model is one of a faction's models for a gender.
New(name)shared
Creates a new, unregistered faction object.
Registers a faction.

Functions

Finds a faction by index, exact name or part of its name.

Partial matches are case-insensitive plain text; the faction with the shortest matching name wins.

Parameters

  • identifier Any Faction index (Number or numeric String), name or part of the name

Returns

  • Faction The faction, or nil if none matches

Returns every registered faction keyed by name.

Returns

  • Map<Faction> Factions keyed by name

Returns the registered factions keyed by numeric index.

Returns

faction.GetDefaultRank(factionID)

shared gamemodes/catwork/gamemode/core/libraries/sh_faction.lua:349

Returns the faction's default rank, the first rank with default set.

Parameters

  • factionID Any Faction name, index or part of the name

Returns

  • String The rank's name, or nil if the faction is not found or has no default rank
  • Map The rank table

faction.GetHigherRank(factionID, rank)

shared gamemodes/catwork/gamemode/core/libraries/sh_faction.lua:313

Returns the rank one step above a rank, the one whose position is one lower.

Parameters

  • factionID Any Faction name, index or part of the name
  • rank Map The current rank table

Returns

  • String The higher rank's name, or nil if rank is already the highest
  • Map The higher rank table

See also

faction.GetHighestRank(factionID)

shared gamemodes/catwork/gamemode/core/libraries/sh_faction.lua:245

Returns the faction's highest rank, the one with the lowest position.

Parameters

  • factionID Any Faction name, index or part of the name

Returns

  • String The rank's name, or nil if the faction is not found or has no ranks
  • Map The rank table

See also

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

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

Parameters

  • name Any Faction name, index or part of the name

Returns

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

faction.GetLowerRank(factionID, rank)

shared gamemodes/catwork/gamemode/core/libraries/sh_faction.lua:332

Returns the rank one step below a rank, the one whose position is one higher.

Parameters

  • factionID Any Faction name, index or part of the name
  • rank Map The current rank table

Returns

  • String The lower rank's name, or nil if rank is already the lowest
  • Map The lower rank table

See also

faction.GetLowestRank(factionID)

shared gamemodes/catwork/gamemode/core/libraries/sh_faction.lua:278

Returns the faction's lowest rank, the one with the highest position.

Parameters

  • factionID Any Faction name, index or part of the name

Returns

  • String The rank's name, or nil if the faction is not found or has no ranks
  • Map The rank table

See also

Returns every initialized player in a faction.

Parameters

Returns

  • List<Player> The players in the faction

Returns the registered factions keyed by name.

Returns

  • Map<Faction> Factions keyed by name

See also

faction.HasReachedMaximum(player, factionID)

shared gamemodes/catwork/gamemode/core/libraries/sh_faction.lua:369

On the server

Returns whether a player already has the maximum number of characters in a faction.

Only factions with a maximum field limit characters.

Parameters

  • player Player The player whose characters are counted
  • factionID Any Faction name, index or part of the name

Returns

  • Boolean true if the maximum is reached, otherwise nil

On the client

Returns whether the local player already has the maximum number of characters in a faction.

Client version of the server's faction.HasReachedMaximum, counting the characters in cw.character:GetAll.

Parameters

  • factionID Any Faction name, index or part of the name

Returns

  • Boolean true if the maximum is reached, otherwise nil

Defined in

faction.IsGenderValid(faction, gender)

shared gamemodes/catwork/gamemode/core/libraries/sh_faction.lua:157

Returns whether a gender may be chosen for a faction.

Factions with a singleGender only accept that gender.

Parameters

  • faction Any Faction name, index or part of the name
  • gender String GENDER_MALE or GENDER_FEMALE

Returns

  • Boolean true if the gender is valid, otherwise nil

faction.IsModelValid(faction, gender, model)

shared gamemodes/catwork/gamemode/core/libraries/sh_faction.lua:173

Returns whether a model is one of a faction's models for a gender.

Parameters

  • faction Any Faction name, index or part of the name
  • gender String GENDER_MALE or GENDER_FEMALE
  • model String Model path

Returns

  • Boolean true if the model is valid, otherwise nil

Creates a new, unregistered faction object.

Set its fields (models, whitelist, material, limit, maximum, singleGender, ranks...) and callbacks, then call CLASS_TABLE:Register on it.

local FACTION = faction.New('#Faction_MPF')

FACTION.whitelist = true
FACTION.material = 'halfliferp/factions/mpf'

FACTION_MPF = FACTION:Register()

Parameters

  • name String optional, defaults to 'Unknown' Name of the faction, can be a language phrase

Returns

  • Faction The new faction object

Registers a faction.

Missing models.male and models.female lists default to the Half-Life 2 citizen models, limit defaults to 128 and the index is a short CRC of name. On the server, during the first boot, the faction's models and its material PNG are added to the client download list.

Parameters

  • data Faction The faction object or table
  • name String Name of the faction, used when data.name is not set

Returns

  • String The faction's name

Defined in