Player class
Part of Factions System
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
Methods
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
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
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
Returns the ID of the player's current rank. Errors if the player has no faction or rank.
Returns
- String rank ID
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
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
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
Checks whether the player is whitelisted for a faction.
Parameters
- faction_id String
Returns
- Boolean
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
falserequire exactly that rank, not one above it
Returns
- Boolean false as well when the player has no rank or the rank does not exist
Moves the player one rank up unless they already hold the highest rank. Server only.
Returns
- Boolean true when the player was promoted
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
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
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