Skills library
Part of Character Stats
Registry of the skill definitions, together with the player methods that read and change
the skills of a player's character.
Definitions are SkillBase objects registered with Skills.register, usually by
Skills.include_skills loading the files of a plugin's skills folder. This file adds
skills to the extra folders of every plugin and handles that folder through the
PluginIncludeFolder hook. It is part of the lib folder of the Stats plugin, which Flux
includes before the other folders of the plugin and before its sh_plugin.lua, so the skills
folder of the Stats plugin is loaded this way too, as are those of the plugins and the
schema that load after it. SkillBase is defined by lib/classes/sh_skill.lua, which Flux
includes after this file but before the skills folder of any plugin.
What a character has of a skill is kept in a Skill record: its rank, from 0 to the max
of the skill. A rank changes only when it is set, by staff or by the code of a plugin, such
as the Levels plugin spending a point on it. The server networks the skills of a player to
that player alone, in the private 'skills' networked variable, which the getters read on
the client.
Summary
Functions
Functions
Gives a character a record for every registered skill it has none for. A new record starts at the given rank, rounded down and kept between 0 and the skill's max, or at rank 0. The records are saved with the character.
Parameters
- character Character
- ranks Map optional, defaults to
nilstarting ranks keyed by skill ID
Returns
- Number amount of records added
Returns the definition of a registered skill.
Parameters
- id String skill ID
Returns
- SkillBase the skill definition, or nil if it is not registered
Finds the record that a character keeps for a skill.
Parameters
- character Character character record; anything else finds nothing
- skill_id String
Returns
- Skill the record, or nil if the character has none
Returns every registered skill definition.
Returns
- Map skill definitions keyed by skill ID
Includes every file of a folder as a skill definition. Each file gets a fresh SKILL global, a SkillBase named after the file, that is registered once the file has run.
-- skills/sh_athletics.lua, registered as 'athletics'
SKILL.name = 'skill.athletics.title'
SKILL.attribute = 'strength'
Parameters
- directory String folder to include files from
Checks whether a skill is shown to a player on the character sheet. A skill with its hidden field set is never shown; any other can be hidden with the IsSkillVisible hook.
Parameters
- skill SkillBase skill definition
- target Player player whose skills are being shown
Returns
- Boolean
Stores a skill definition and runs the SkillRegistered hook. Missing fields get defaults:
the name 'skill.other.name', the description 'skill.other.desc' and a max of 4. The max
is rounded down and is never below 1.
local skill = SkillBase.new('lockpicking')
skill.name = 'skill.lockpicking.title'
skill.attribute = 'reflexes'
Skills.register(skill.skill_id, skill)
Parameters
- id String unique skill ID; raises an error when it is not a string
- data SkillBase skill definition; nothing happens when it is nil
See also
Networks the skills of a player's character to that player again. Called after every change the plugin makes; call it yourself after changing the records directly.
Parameters
- target Player
Builds the table that is networked for a player: the rank of every registered skill their character has a record for.
Parameters
- target Player
Returns
- Map ranks keyed by skill ID
Sets the rank of a skill of a player's character, networks the skills and runs the PlayerSkillChanged hook. Nothing happens if the rank does not change or the character has no record for the skill.
Parameters
- target Player
- skill_id String
- rank Number new rank, rounded and kept between 0 and the skill's max
Returns
- Boolean true if the rank has changed