Hooks called by Characters System

Summary

Hooks

Lets plugins add their stages to the character creation screen.
Lets plugins add buttons to the main menu.
Called on the server after a character has been banned or unbanned and saved.
Called on the server after Characters.set_desc has changed the physical description of a player's active character and networked it.
Called on the server after Characters.set_gender has changed the gender of a player's active character and networked it.
Called on the server after Characters.set_model has changed the model of a player and of their active character and networked it.
Called on the server after Characters.set_name has changed the name of a player's active character and networked it.
Called on the client when the server has refused a request of the local player to load or delete one of their characters, after the reason has been shown to them.
Called on the client after the character creation screen has opened the panel of a stage and run its on_open method.
Lets plugins add to the data of a character creation request.
Lets plugins add user records that are loaded although no connected player owns them, so that their characters are found in memory rather than loaded again from the database.
Called on the client shortly after the local player has created a character that is their only one, 1.5 seconds before that character is loaded automatically.
Asks for the models the player can choose from in the general stage of character creation.
Lets plugins change how many characters a player may have.
Lets plugins give a character that is being created to another user record than the one of the player who creates it.
Lets plugins supply the text shown when the server has refused to create a character.
Decides whether a scoreboard card shows the character of its player.
Called on the server when a player is left without an active character, after the character has been saved and while it is still the active one.
Called on the server when a character has become the active character of a player, after its ID, name, gender, description and model have been networked.
Called on the server when a player who already has an active character selects a character, before the selected character becomes the active one.
Called on the server when a player has asked to delete one of their characters, right before it is deleted.
Called on the client when the list of the local player's characters has arrived from the server and has been stored in PLAYER.characters.
Called on the client when a character panel of the loading screen has been given its character, after the model has been set.
Decides whether a player may delete one of their characters.
Decides whether a player may leave their active character for another one.
Decides whether a player may load one of their characters.
Validates the data of a character that is about to be created.
Decides whether a player has to have an active character to be in the world.
Called on the server once a loaded character has been applied to its player: the player has been spawned and given the model, skin, health, armor and ammo of the character.
Called on the server when a character has been built and added to the record of its owner, before it is saved and sent to the owner.
Called on the server after the character list has been sent to a player who has joined, which happens once their record is restored and they have initialized.
Called on the server when the request of a client to create a character arrives, before the data is converted and passed to Characters.create.
Lets plugins prepare for or prevent the saving of a character.
Lets plugins keep the player on the current stage of character creation.
Called on the server right before the record of a player is saved together with a character.

Hooks

AddCharacterCreationMenuStages(self)

client plugins/characters/plugin/views/cl_character_creation.lua:31

Lets plugins add their stages to the character creation screen. Called on the client each time the screen is created, before its first stage is opened.

Parameters

  • panel Panel the fl_char_create panel; call its add_stage method with the ID of a theme panel

Called from

Call sites

AddMainMenuItems(self, self.sidebar)

client plugins/characters/plugin/views/cl_main_menu.lua:92

Lets plugins add buttons to the main menu. Called on the client whenever the menu fills its sidebar: when it is created and when a submenu is closed.

Parameters

  • panel Panel the fl_main_menu panel; add buttons with its add_button method
  • sidebar Panel the newly created sidebar that the buttons go into

Called from

Call sites

CharacterBanChanged(owner, character, banned)

server plugins/characters/plugin/lib/sh_character.lua:607

Called on the server after a character has been banned or unbanned and saved.

Parameters

  • owner Player the owner of the character, nil when they are not connected
  • character Character
  • banned Boolean true when the character is banned now

Called from

Call sites

CharacterDescChanged(target, char, new_desc, old_desc)

server plugins/characters/plugin/lib/sh_character.lua:803

Called on the server after Characters.set_desc has changed the physical description of a player's active character and networked it.

Parameters

  • owner Player
  • char Character the active character, nil if the player has none
  • new_desc String
  • old_desc String the description that was networked before the change

Called from

Call sites

CharacterGenderChanged(target, char, new_gender, old_gender)

server plugins/characters/plugin/lib/sh_character.lua:860

Called on the server after Characters.set_gender has changed the gender of a player's active character and networked it.

Parameters

  • owner Player
  • char Character the active character, nil if the player has none
  • new_gender Number CHAR_GENDER_* value
  • old_gender Number the CHAR_GENDER_* value that was networked before the change

Called from

Call sites

CharacterModelChanged(target, char, model, old_model)

server plugins/characters/plugin/lib/sh_character.lua:830

Called on the server after Characters.set_model has changed the model of a player and of their active character and networked it.

Parameters

  • owner Player
  • char Character the active character, nil if the player has none
  • model String the new model path
  • old_model String the model that was networked before the change

Called from

Call sites

CharacterNameChanged(target, char, new_name, old_name)

server plugins/characters/plugin/lib/sh_character.lua:777

Called on the server after Characters.set_name has changed the name of a player's active character and networked it.

Parameters

  • owner Player
  • char Character the active character, nil if the player has none
  • new_name String
  • old_name String the name that was networked before the change

Called from

Call sites

CharacterRequestFailed(action, text)

client plugins/characters/plugin/cl_nethooks.lua:62

Called on the client when the server has refused a request of the local player to load or delete one of their characters, after the reason has been shown to them. The character loading screen uses it to bring back the card of a character that was not deleted.

Parameters

  • action String 'select' or 'delete'
  • text String the translated reason

Call sites

CharPanelCreated(id, self.panel)

client plugins/characters/plugin/views/cl_character_creation.lua:439

Called on the client after the character creation screen has opened the panel of a stage and run its on_open method. Lets plugins adjust the stage panels of other plugins.

Parameters

  • id String ID of the stage, as it was passed to add_stage
  • panel Panel the panel created for the stage

Called from

Call sites

CollectCharacterCreationData(self, request_data)

client plugins/characters/plugin/views/cl_character_creation.lua:281

Lets plugins add to the data of a character creation request. Called on the client right before the request is sent, after the extra_data table of the creation screen has been merged into the data the stages have collected.

Parameters

  • panel Panel the fl_char_create panel
  • data Map the data that is about to be sent, changed in place

Call sites

CollectLoadedUserRecords(records)

server plugins/characters/plugin/lib/sh_character.lua:371

Lets plugins add user records that are loaded although no connected player owns them, so that their characters are found in memory rather than loaded again from the database. Called on the server by Characters.find_by_name, with the records of the connected players already in the list.

Parameters

  • records List<User> the records whose characters are searched, added to in place

Called from

Call sites

FirstCharacterCreated(chars[1])

client plugins/characters/plugin/views/cl_character_creation.lua:299

Called on the client shortly after the local player has created a character that is their only one, 1.5 seconds before that character is loaded automatically.

Parameters

  • char Map networked data of the new character

Call sites

GetCharacterCreationModels(char_data)

client plugins/characters/plugin/views/cl_character_general.lua:203

Asks for the models the player can choose from in the general stage of character creation. Called on the client every time the model list is rebuilt, which happens when the stage is opened with a gender already chosen and whenever the gender changes.

Parameters

  • char_data Map character data collected so far, including the gender ('male', 'female' or 'universal') that has been picked

Returns

  • List<String> model paths. The stage has no models of its own, so it offers none unless a handler returns a list, as the Factions plugin does

Called from

Call sites

GetCharacterLimit(target, limit)

shared plugins/characters/plugin/lib/sh_character.lua:100

Lets plugins change how many characters a player may have. Called on the server when a character is about to be created, and on the client for the local player when the main menu decides whether the creation screen may be opened, so a handler that is meant to be seen in the menu has to be shared.

Parameters

  • target Player the player whose limit is requested
  • limit Number the value of the character_limit config

Returns

  • Number the limit to use for this player; return nothing to keep the config value

Called from

Call sites

GetCharacterOwner(target, data)

shared plugins/characters/plugin/lib/sh_character.lua:184

Lets plugins give a character that is being created to another user record than the one of the player who creates it. Called by Characters.create, which the plugin runs on the server, once the creation data has passed the PlayerCreateCharacter hook. A character that belongs to another record is saved on its own and is not sent to the player.

Parameters

  • target Player the player the character is created for
  • data Map creation data the character is built from

Returns

  • User the record that is to own the character; return nothing to let the player own it

Called from

Call sites

GetCharCreationErrorText(response.success, status)

client plugins/characters/plugin/views/cl_character_creation.lua:315

Lets plugins supply the text shown when the server has refused to create a character. Called on the client.

Parameters

  • success Boolean always false here
  • status Number the CHAR_ERR_* code the server answered with

Returns

  • String translated error text; when nothing is returned the menu uses its own text for the codes of the Characters plugin

Call sites

IsCharacterCardVisible(card, target)

client plugins/characters/plugin/cl_hooks.lua:189

Decides whether a scoreboard card shows the character of its player. Called on the client when a scoreboard player card is rebuilt.

Parameters

  • card Panel the scoreboard player card
  • target Player the player the card belongs to

Returns

  • Boolean return false to hide the character name, model icon and physical description, which leaves only the Steam name on the card

Called from

Call sites

OnActiveCharacterCleared(self, character)

server plugins/characters/plugin/sv_plugin.lua:82

Called on the server when a player is left without an active character, after the character has been saved and while it is still the active one. Handlers take back what they have given the player for the character.

Parameters

  • owner Player
  • character Character the character that is being dropped

Called from

Call sites

OnActiveCharacterSet(target, target:get_character())

server plugins/characters/plugin/sv_plugin.lua:49

Called on the server when a character has become the active character of a player, after its ID, name, gender, description and model have been networked. The Characters plugin spawns the player from its own handler of this hook; other plugins use it to apply what they keep on the character.

Parameters

  • owner Player
  • character Character the character that is now active

Called from

Call sites

OnCharacterChange(target, character, target:get_character())

server plugins/characters/plugin/sv_plugin.lua:24

Called on the server when a player who already has an active character selects a character, before the selected character becomes the active one.

Parameters

  • owner Player
  • new_char Character the character that is about to become active
  • old_char Character the character that is still active

Called from

Call sites

OnCharacterDelete(actor, id, character)

server plugins/characters/plugin/sv_nethooks.lua:118

Called on the server when a player has asked to delete one of their characters, right before it is deleted. The request has passed Characters.can_delete by then.

Parameters

  • actor Player
  • id Number ID of the character
  • character Character the character that is about to be deleted

Call sites

OnCharactersReceived(data)

client plugins/characters/plugin/cl_nethooks.lua:22

Called on the client when the list of the local player's characters has arrived from the server and has been stored in PLAYER.characters. The server sends it when the player joins and again whenever one of their characters is created, deleted or changed. The list is stored as soon as it arrives, so the messages that the server sends after it are handled with the new list in place; only while the local player does not exist yet is it held back.

Parameters

  • characters List<Map> networked data of every character of the local player

Called from

  • store_characters

Call sites

PanelCharacterSet(self, char_data)

client plugins/characters/plugin/views/cl_character_load.lua:238

Called on the client when a character panel of the loading screen has been given its character, after the model has been set. Lets plugins change how the character is presented.

Parameters

  • panel Panel the fl_character_panel; its model preview is panel.model
  • char_data Map networked data of the character

Called from

Call sites

PlayerCanDeleteCharacter(actor, character)

server plugins/characters/plugin/lib/sh_character.lua:489

Decides whether a player may delete one of their characters. Called on the server for every request to delete a character that is neither active nor banned.

Parameters

  • actor Player the player who wants to delete the character
  • character Character the character they want to delete

Returns

  • Boolean return false to refuse
  • String a language phrase that tells the player why and Map the arguments of the phrase; a generic text is shown when the reason is omitted

Called from

Call sites

PlayerCanSwitchCharacter(actor, character, current)

server plugins/characters/plugin/lib/sh_character.lua:438

Decides whether a player may leave their active character for another one. Called on the server when a player who has an active character that is not banned asks to load another character. The Characters plugin itself refuses while the player is dead or ragdolled.

Parameters

  • actor Player the player who wants to switch
  • character Character the character they want to load
  • current Character their active character

Returns

  • Boolean return false to refuse
  • String a language phrase that tells the player why and Map the arguments of the phrase; a generic text is shown when the reason is omitted

Called from

Call sites

PlayerCanUseCharacter(actor, character)

server plugins/characters/plugin/lib/sh_character.lua:453

Decides whether a player may load one of their characters. Called on the server for every request to load a character, after the plugin's own checks and, for a player who is switching characters, after the PlayerCanSwitchCharacter hook.

Parameters

  • actor Player the player who wants to load the character
  • character Character the character they want to load

Returns

  • Boolean return false to refuse
  • String a language phrase that tells the player why and Map the arguments of the phrase; a generic text is shown when the reason is omitted

Called from

Call sites

PlayerCreateCharacter(target, data)

shared plugins/characters/plugin/lib/sh_character.lua:170

Validates the data of a character that is about to be created. Called by Characters.create, which the plugin runs on the server, before the character record is built.

Parameters

  • owner Player the player the character is created for
  • data Map creation data: name, phys_desc, gender, model, skin, name_generated, description_generated and the fields that other plugins add

Returns

  • Number return a CHAR_ERR_* code to refuse the character; it becomes the result of Characters.create and is sent to the client. Return nothing to accept the data

Called from

Call sites

PlayerNeedsCharacter(target)

shared plugins/characters/plugin/lib/sh_character.lua:123

Decides whether a player has to have an active character to be in the world. Called on both realms: on the server when the player spawns, on the client for the local player when the intro closes and when the HUD and the scoreboard are about to be drawn. The answer only matters while the player has no active character, or a banned one.

Parameters

  • target Player the player in question

Returns

  • Boolean return false to let the player stay in the world without a character; nothing to leave the decision to the Characters plugin

Called from

Call sites

PostCharacterLoaded(owner, character)

server plugins/characters/plugin/sv_hooks.lua:154

Called on the server once a loaded character has been applied to its player: the player has been spawned and given the model, skin, health, armor and ammo of the character. The Characters plugin forwards the hook to the client of the owner, where handlers receive only the ID of the character.

Parameters

  • owner Player
  • character Character

Called from

Call sites

PostCreateCharacter(target, char, data)

server plugins/characters/plugin/lib/sh_character.lua:209

Called on the server when a character has been built and added to the record of its owner, before it is saved and sent to the owner. Handlers copy their own fields from the creation data to the character.

Parameters

  • owner Player
  • char Character the new character, not saved yet
  • char_data Map creation data the character was built from

Called from

Call sites

PostRestoreCharacters(actor)

server plugins/characters/plugin/sv_hooks.lua:110

Called on the server after the character list has been sent to a player who has joined, which happens once their record is restored and they have initialized.

Parameters

  • actor Player

Call sites

PreCreateCharacter(actor, data)

server plugins/characters/plugin/sv_nethooks.lua:68

Called on the server when the request of a client to create a character arrives, before the data is converted and passed to Characters.create. Handlers can fill in or change the data in place. A name that a handler has replaced counts as generated and may repeat the name of another character; a description that a handler has replaced counts as generated and may be of any length.

Parameters

  • actor Player the player who sent the request
  • data Map data collected by the creation menu: name, description, gender ('male', 'female' or 'universal'), model, skin and the fields that other stages add

Call sites

PreSaveCharacter(target, character)

server plugins/characters/plugin/lib/sh_character.lua:710

Lets plugins prepare for or prevent the saving of a character. Called on the server by Characters.save, before the SaveCharacterData hook.

Parameters

  • owner Player
  • character Character the character that is about to be saved

Returns

  • Boolean return false to cancel the save

Called from

Call sites

PreStageChange(self.stages[self.stage], self.panel)

client plugins/characters/plugin/views/cl_character_creation.lua:251

Lets plugins keep the player on the current stage of character creation. Called on the client when the screen is about to move on from a stage (on the last stage, before the player is asked to confirm), after the on_validate method of the stage panel has passed.

Parameters

  • id String ID of the current stage
  • panel Panel the panel of that stage

Returns

  • Boolean return false to stay on the stage
  • String error text to show; a generic error is shown when it is omitted

Called from

Call sites

SaveCharacterData(target, character)

server plugins/characters/plugin/lib/sh_character.lua:716

Called on the server right before the record of a player is saved together with a character. Handlers write the data they keep for the character into its fields.

Parameters

  • owner Player
  • character Character the character that is being saved

Called from

Call sites

Defined in