Levels gives every character a level, from 1 to the levels_max_level config (20), and
the experience it has gathered toward the next one. Each level takes the same amount of
experience, the levels_experience_per_level config (1000). Both are stored in the
level and experience columns of the character and networked to its owner alone, so
Player:get_level, Player:get_experience and Player:get_experience_to_level work on
the server and, for the local player, on the client.
Experience is given with Player:give_experience, which can raise or lower the level by
several steps at once, and staff use the experience add, level set and level get
commands. When the levels_combat_experience config is on, players also gain experience
for the damage they deal to NPCs and other players (levels_experience_per_damage) and
for the NPCs they kill (levels_experience_per_kill, more for NPCs with more health); the
AdjustCombatExperience hook changes or cancels that experience. PlayerExperienceChanged
and PlayerLevelChanged report every change.
Every level after the first grants levels_skill_points_per_level skill points, and every
levels_boost_every levels grant levels_boost_points attribute points. The points that
are not spent yet are kept in the skill_points and attribute_points character data,
which the owner receives, and are spent one at a time with Player:spend_skill_point and
Player:spend_attribute_point, each raising a skill or a stat of the Stats plugin by one
level. Clients ask for that with the fl_levels_spend_skill and
fl_levels_spend_attribute messages.
The maximum health of a character grows with its level and its endurance, see
Levels:get_max_health. The plugin applies it whenever one of them changes and when the
player spawns, and answers the GetPlayerMaxHealth hook of the Factions plugin with it,
so the maximum health of a faction never takes its place.
The server has a level of its own, which starts at -1 when the plugin first runs on it and
rises with real time: each level below the levels_server_ramp_level config (4) takes the
levels_server_days_per_level config (7 days), and every level from there on the
levels_server_ramp_days config (1 day) more than the one before, so level 4 takes 8 days
and level 5 9 days; it never goes past levels_max_level. The time of the first run is
kept in a data file of the schema, the same for all of its maps, so a map change keeps the
server level.
Levels.get_server_level and the serverlevel get command show the level, the
serverlevel set command and Levels.set_server_level change it, and ServerLevelChanged reports every
change. Experience cannot take a character past the level cap, the server level plus the
levels_server_cap_offset config (2): a character at the cap keeps the experience it gains
and spends it on levels once the cap rises. Characters below the level floor, the server
level minus the levels_server_floor_offset config (2), are raised to it and keep their
experience; the floor is applied first, so kept experience is only spent on the levels
above it. Both are applied when a character becomes active and when the server level
changes. The staff commands are not bound by the cap, but the floor applies to them. While
the levels_server_progression config is off there is no cap and no floor.
Summary
Hooks
levels_combat_experience config is on: levels_experience_per_kill, multiplied by a tenth of the maximum health of the NPC but never by less than 1.levels_experience_per_damage for every point of damage, while the levels_combat_experience config is on.Functions
Levels.raise_to_floor), which keeps its experience, then spends its kept experience on levels as far as the level cap allows (Levels.catch_up).levels_boost_points for every levels_boost_every levels, so with the defaults 2 points at levels 5, 10, 15 and 20.levels_experience_per_level config, the same for every level.levels_server_cap_offset config (2).levels_server_floor_offset config (2).levels_max_level config.levels_server_days_per_level config (7 days) for every level below the levels_server_ramp_level config (4), and from that level on the levels_server_ramp_days config (1 day) more for each level past the one before it, so with the defaults level 4 takes 8 days, level 5 9 days and level n 7 + (n - 3) days.Levels.get_seconds_for_server_level.levels_skill_points_per_level for every level after the first.levels_server_progression config turns on.Levels.set_first_boot.skill_points and attribute_points character data: the points the level has earned minus the points spent so far, never less than zero.Methods
Levels:get_max_health.health_base + (level - 1) * health_per_level + level * endurance, where endurance is the level of the 'endurance' stat with its boosts, or 0 when no such stat is registered.Hooks
Implements hook GetPlayerMaxHealth
Makes the Factions plugin use the maximum health of the player's level instead of the one of their faction and rank.
Parameters
- target Player
- _max_health Number maximum health of the faction and rank, or nil
Returns
- Number maximum health of the player's level, nil for a player without an active character
Implements hook LoadData
Loads the time of the first run of the plugin on this server, which the server level is counted from, and checks the server level.
Implements hook OnActiveCharacterCleared
Takes the networked level and experience of a character away from the player who drops it.
Parameters
- owner Player
- _character Character the character that is being dropped
Implements hook OnActiveCharacterSet
Works out the unspent points of the character that has become active, networks its level and experience, raises it to the level floor, levels it up with its kept experience as far as the level cap allows and applies its maximum health.
Parameters
- owner Player
- _character Character
Implements hook OnConfigSet
Applies the maximum health to every player when a health config changes, works out the
unspent points of every player again when a config of the level-up points changes, and
checks the server level and brings every character in line with its level cap and level
floor when a config of the server level changes. The hook runs before the new value is
stored, so the work waits for the next tick, when Config.get returns the new value.
Parameters
- key String config key
- _old_value Any
- _new_value Any
Implements hook OneMinute
Checks once a minute whether the server has reached a new level.
Gives a player experience for an NPC they have killed while the
levels_combat_experience config is on: levels_experience_per_kill, multiplied by a
tenth of the maximum health of the NPC but never by less than 1.
Parameters
- npc NPC the NPC that was killed
- attacker Entity
- _inflictor Entity
Levels:PlayerAttributeChanged(actor, attribute_id, _level, _old_level)
server plugins/levels/plugin/sv_hooks.lua:186Implements hook PlayerAttributeChanged
Applies the maximum health again when the endurance of a player has changed.
Parameters
- actor Player
- attribute_id String
- _level Number
- _old_level Number
Implements hook PlayerLevelChanged
Applies the maximum health of the new level. A player who has gone up and is alive is healed by as much as the maximum has grown.
Parameters
- actor Player
- _level Number new level
- _old_level Number level before the change
Implements hook PlayerOneSecond
Applies the maximum health of a living player again when it has changed for a reason that runs no hook, such as a boost to their endurance that has been given or has expired.
Parameters
- actor Player
- _cur_time Number current CurTime()
Gives a spawning player with an active character the maximum health of their level and fills their health up to it.
Parameters
- actor Player
Implements hook PostCharacterLoaded
Applies the maximum health again once the Characters plugin has given the player the health saved with the character, so that saved health above the maximum is cut down.
Parameters
- owner Player
- _character Character
Implements hook PostCreateCharacter
Gives a new character level 1 and no experience, so that the record has them from the moment it is first saved.
Parameters
- _owner Player
- char Character the character being created
- _char_data Map character creation data
Levels:PostEntityTakeDamage(entity, damage_info, took)
server plugins/levels/plugin/sv_hooks.lua:241Gives a player experience for the damage they have dealt to an NPC or another player,
levels_experience_per_damage for every point of damage, while the
levels_combat_experience config is on. Damage beyond the maximum health of the victim
does not count.
Parameters
- entity Entity the entity that was attacked
- damage_info CTakeDamageInfo
- took Boolean whether the entity has actually taken the damage
Implements hook ServerLevelChanged
Brings the character of every player in line with the new server level: raises it to the new level floor and levels it up with its kept experience as far as the new level cap allows.
Parameters
- _level Number new server level
- _old_level Number server level before the change
Functions
Brings a player's character in line with the server level: first raises it to the
level floor (Levels.raise_to_floor), which keeps its experience, then spends its kept
experience on levels as far as the level cap allows (Levels.catch_up). The levels the
floor grants cost no experience, and since the floor is never above the cap, the
experience is never spent past the cap. Server only.
Parameters
- target Player
Returns
- Boolean true if the level has changed
Levels up a player's character as far as its kept experience and the level cap allow, taking the experience each level needs, and tells the player about the level reached. Called when the level cap rises and when a character becomes active. Server only.
Parameters
- target Player
Returns
- Boolean true if the character has gone up
Works out the server level, networks it to every player and runs the
ServerLevelChanged hook when it differs from the last one seen, which is saved with the
time of the first run so that a change while the server was off is reported on the next
start. The plugin calls it on start, once a minute and when a config of the server
level changes. Does nothing before Levels.load_server_data. Server only.
Returns
- Number the server level
Returns the attribute points that a character has earned by reaching a level:
levels_boost_points for every levels_boost_every levels, so with the defaults 2
points at levels 5, 10, 15 and 20.
Parameters
- level Number
Returns
- Number
Returns the experience needed to go from a level to the next one: the
levels_experience_per_level config, the same for every level. A character at the
highest level has no next level to gather experience for.
Parameters
- level Number level to go up from
Returns
- Number experience; 0 when the level is the highest one or above it
Returns the time the plugin first ran on the server. The client knows it once the server has networked it.
Returns
- Number unix time, nil if it is not known yet
Returns the highest level a character can reach through experience: the server level
plus the levels_server_cap_offset config (2). Experience gathered at the cap is kept
until the cap rises. Staff commands are not bound by it.
Returns
- Number between 1 and the highest level; the highest level while the
levels_server_progressionconfig is off
Returns the lowest level a character may have: the server level minus the
levels_server_floor_offset config (2). Characters below it are raised to it.
Returns
- Number between 1 and the level cap; 1 while the
levels_server_progressionconfig is off
Returns the highest level a character can reach, the levels_max_level config.
Returns
- Number never lower than 1
Returns how long the server takes to reach a level from the one before it: the
levels_server_days_per_level config (7 days) for every level below the
levels_server_ramp_level config (4), and from that level on the levels_server_ramp_days
config (1 day) more for each level past the one before it, so with the defaults level 4
takes 8 days, level 5 9 days and level n 7 + (n - 3) days. Level -1, where the server
starts, takes no time.
Parameters
- level Number the level that is reached
Returns
- Number seconds
Returns how long the server takes from its first run to reach a level: the time of every step from level -1 up to that level.
Parameters
- level Number the level that is reached; no higher than the highest level counts
Returns
- Number seconds; 0 for level -1
Returns the level of the server, which rises with the real time since the plugin first
ran on it, see Levels.get_seconds_for_server_level. On the client this is the level the
server has networked.
Returns
- Number from -1 to the highest level a character can reach; -1 while the first run is not known
Returns the level the server is at after some time has passed since its first run.
Levels.get_server_level_at(0) -- -1
Levels.get_server_level_at(7 * 86400) -- 0
Levels.get_server_level_at(36 * 86400) -- 4
Parameters
- elapsed_seconds Number seconds since the first run
Returns
- Number from -1 to the highest level a character can reach
Returns the time until the server reaches its next level.
Returns
- Number seconds, nil at the highest level
Returns how far the server is into its current level.
Returns
- Number seconds spent at the current level
- Number seconds the step to the next level takes; both 0 at the highest level
Returns the skill points that a character has earned by reaching a level:
levels_skill_points_per_level for every level after the first.
Parameters
- level Number
Returns
- Number
Checks whether the server level limits the levels of characters, which is what the
levels_server_progression config turns on. While it is off there is no level cap and
no level floor.
Returns
- Boolean
Loads the time the plugin first ran on the server and the last server level seen, saving the current time as the first run if none was saved yet, networks the first run and checks the server level. The plugin calls it from its LoadData handler. Server only.
Raises a player's character to the level floor if it is below it, keeping its experience as it is, and tells the player about the level reached. Server only.
Parameters
- target Player
Returns
- Boolean true if the character was raised
Sets the time the plugin first ran on the server, which the server level is counted from, saves it, networks it and checks the server level. Server only.
Parameters
- unix_time Number unix time, rounded down
Returns
- Boolean false if the time is not a number
Puts the server at the very start of a level by moving the time of its first run back
by as long as reaching that level takes, see Levels.set_first_boot. The
ServerLevelChanged hook runs if the level differs from the one before. Server only.
Levels.set_server_level(3)
Parameters
- level Number rounded and kept between -1 and the highest level
Returns
- Boolean false if the level is not a number
Networks the level and the experience of a player's character to that player, in the private 'level' and 'experience' networked variables. Called after every change the plugin makes and when a character becomes active; call it yourself after changing the fields of the character directly. Server only.
Parameters
- target Player
Sets the level and the experience of a player's character, works out its unspent points again, networks the change and runs the PlayerExperienceChanged hook, followed by PlayerLevelChanged when the level has changed. A character at the highest level keeps no experience; below it the experience may be more than the level needs, which is how a character at the level cap keeps what it gathers until the cap rises. Neither the level cap nor the level floor is applied here. Nothing happens if neither value changes. Server only.
Parameters
- target Player
- level Number new level, rounded and kept between 1 and the highest level
- experience Number new experience toward the next level, rounded down and never lower than 0
- reason String optional, defaults to
nilwhat the change is for, passed on to the hook
Returns
- Boolean true if the level or the experience has changed
Works out the unspent skill and attribute points of a player's character from its
level and stores them in the skill_points and attribute_points character data: the
points the level has earned minus the points spent so far, never less than zero. Points
that were spent stay spent when the level goes down. Server only.
Parameters
- target Player
Methods
Sets the maximum health of a player to Levels:get_max_health. Their health is cut
down to it if it is higher, or set to it if asked to refill. Nothing happens to a player
without an active character. Server only.
Parameters
- target Player
- refill Boolean optional, defaults to
falsealso fill the health of the player up to the maximum
Returns
- Number the maximum health applied, or nil if nothing was done
Returns the maximum health of a player's character:
health_base + (level - 1) * health_per_level + level * endurance, where endurance is
the level of the 'endurance' stat with its boosts, or 0 when no such stat is registered.
With the defaults a level 1 character of endurance 0 has 10 health and gains 3 for each
level after that.
Parameters
- target Player
Returns
- Number whole number, never lower than 1