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

Gives a character a record for every registered skill it has none for.
find(id)shared
Returns the definition of a registered skill.
Finds the record that a character keeps for a skill.
Returns every registered skill definition.
Includes every file of a folder as a skill definition.
Checks whether a skill is shown to a player on the character sheet.
Stores a skill definition and runs the SkillRegistered hook.
Networks the skills of a player's character to that player again.
Builds the table that is networked for a player: the rank of every registered skill their character has a record for.
Sets the rank of a skill of a player's character, networks the skills and runs the PlayerSkillChanged hook.

Functions

Skills.create_records(character, ranks)

server plugins/stats/plugin/lib/sh_skills.lua:147

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 nil starting 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

Skills.get_record(character, skill_id)

server plugins/stats/plugin/lib/sh_skills.lua:131

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

Skills.get_stored()

shared plugins/stats/plugin/lib/sh_skills.lua:30

Returns every registered skill definition.

Returns

  • Map skill definitions keyed by skill ID

Skills.include_skills(directory)

shared plugins/stats/plugin/lib/sh_skills.lua:85

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

Skills.is_visible(skill, target)

shared plugins/stats/plugin/lib/sh_skills.lua:94

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

Skills.register(id, data)

shared plugins/stats/plugin/lib/sh_skills.lua:54

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

Skills.sync(target)

server plugins/stats/plugin/lib/sh_skills.lua:193

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

Skills.to_networkable(target)

server plugins/stats/plugin/lib/sh_skills.lua:178

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

Skills.update(target, skill_id, rank)

server plugins/stats/plugin/lib/sh_skills.lua:206

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

Defined in