Player extensions of the Factions plugin: the faction, rank and whitelists of a player. Every player is in a faction and holds a rank in it, and has a list of the factions they are whitelisted for. The player methods read these on the server and the client; on the server they also move the player to another faction, change their rank and give or take whitelists.

This file also holds the Factions functions that register and look up factions, count their members against the limits of the factions and their ranks, tell who may promote and demote whom, and, on the server, give the members of a faction what the faction and their rank grant them: weapons, maximum health and armor, a model and the feelings of NPCs. The loader of faction definition files is here as well.

Summary

Methods

Checks whether the rank of the player lets them demote another player.
Checks whether the rank of the player lets them promote another player.
Moves the player one rank down unless they already hold the lowest rank.
Returns the faction the player belongs to.
Returns the ID of the player's faction.
Returns the player's rank in their faction as an index into the faction's rank list.
Returns the ID of the player's current rank.
Returns the table of the rank the player holds in their faction.
Returns the faction whitelists of the player.
Whitelists the player for a faction by adding a Whitelist record to their user record and networking the updated list.
Checks whether the player is whitelisted for a faction.
Checks whether the player holds the given rank of their faction or any rank above it.
Moves the player one rank up unless they already hold the highest rank.
Moves the player into a faction: resets the rank to the default rank of the faction, regenerates the name, sets the team, adjusts gender and model, gives the default description of a faction that does not let players write one, and runs both factions' leave and join callbacks.
Sets the player's rank in their current faction, networks it, regenerates their name from the faction's name template and gives them the model, the weapons and the maximum health and armor of the rank.
Removes the player's whitelist for a faction, destroying its Whitelist record and networking the updated list.

Methods

Player:can_demote(target)

shared plugins/factions/plugin/lib/sh_faction.lua:790

Checks whether the rank of the player lets them demote another player.

Parameters

  • target Player the player who would be demoted

Returns

  • Boolean

See also

Player:can_promote(target)

shared plugins/factions/plugin/lib/sh_faction.lua:782

Checks whether the rank of the player lets them promote another player.

Parameters

  • target Player the player who would be promoted

Returns

  • Boolean

See also

Moves the player one rank down unless they already hold the lowest rank. Server only.

Returns

  • Boolean true when the player was demoted

Returns the faction the player belongs to.

Returns

  • Faction the faction, or nil if the player's faction ID is not registered

Player:get_faction_id()

shared plugins/factions/plugin/lib/sh_faction.lua:714

Returns the ID of the player's faction. On the server it is read from the active character, so that it is right as soon as the character is selected.

Returns

  • String faction ID, 'player' when no faction has been networked

Returns the player's rank in their faction as an index into the faction's rank list.

Returns

  • Number rank index; on the client -1 when no rank has been networked

Player:get_rank_name()

shared plugins/factions/plugin/lib/sh_faction.lua:740

Returns the ID of the player's current rank. Errors if the player has no faction or rank.

Returns

  • String rank ID

Player:get_rank_table()

shared plugins/factions/plugin/lib/sh_faction.lua:747

Returns the table of the rank the player holds in their faction.

Returns

  • Map rank table with id and name fields and the optional fields described at Faction:add_rank; nil if the player is not a member of a faction or has no rank

Player:get_whitelists()

shared plugins/factions/plugin/lib/sh_faction.lua:797

Returns the faction whitelists of the player.

Returns

  • List Whitelist records on the server, empty for a player without a user record; whitelisted faction IDs on the client

Player:give_whitelist(faction_id)

server plugins/factions/plugin/lib/sh_faction.lua:945

Whitelists the player for a faction by adding a Whitelist record to their user record and networking the updated list. Does nothing if they already have it or have no user record, as is the case for bots. Server only.

Parameters

  • faction_id String

Player:has_whitelist(faction_id)

shared plugins/factions/plugin/lib/sh_faction.lua:808

Checks whether the player is whitelisted for a faction.

Parameters

  • faction_id String

Returns

  • Boolean

Player:is_rank(str_rank, strict)

shared plugins/factions/plugin/lib/sh_faction.lua:757

Checks whether the player holds the given rank of their faction or any rank above it.

Parameters

  • str_rank String rank ID, letter case is ignored
  • strict Boolean optional, defaults to false require exactly that rank, not one above it

Returns

  • Boolean false as well when the player has no rank or the rank does not exist

Player:promote_rank()

server plugins/factions/plugin/lib/sh_faction.lua:915

Moves the player one rank up unless they already hold the highest rank. Server only.

Returns

  • Boolean true when the player was promoted

Player:set_faction(id)

server plugins/factions/plugin/lib/sh_faction.lua:834

Moves the player into a faction: resets the rank to the default rank of the faction, regenerates the name, sets the team, adjusts gender and model, gives the default description of a faction that does not let players write one, and runs both factions' leave and join callbacks. The player then gets the weapons, the maximum health and armor and the rank model of the new faction, and NPCs feel about them as that faction says. The rank is set here rather than with Player:set_rank, so only the OnPlayerFactionChanged hook reports the move. Neither the limit of the faction nor its can_transfer callback is checked; see Factions.can_transfer. Server only.

Parameters

  • id String ID of a registered faction

Player:set_rank(rank)

server plugins/factions/plugin/lib/sh_faction.lua:890

Sets the player's rank in their current faction, networks it, regenerates their name from the faction's name template and gives them the model, the weapons and the maximum health and armor of the rank. The limit of the rank is not checked, and nothing happens to a player who is not a member of a registered faction. Server only.

Parameters

  • rank Number rank index, 1 being the lowest; ignored if the faction has no such rank

Player:take_whitelist(faction_id)

server plugins/factions/plugin/lib/sh_faction.lua:965

Removes the player's whitelist for a faction, destroying its Whitelist record and networking the updated list. A player who is playing a character of that faction and may no longer load it (see Factions:PlayerCanUseCharacter) loses it at once: it is saved and dropped, the player is spawned again and gets the main menu with the reason. Server only.

Parameters

  • faction_id String

Defined in