GetPlayerProgress
Everything a mode saves with a character - stats, skills, perk points, perks, nourishment and energy.
One table:
statsandskills-{strength = {level = 12, xp = 340.5, next = 620, points = 2}, ...}, one entry for each the server knows.levelis the level,xpthe XP gathered toward the next level,nextthe XP the next level takes in all (0at the top level, or before the game has reported it) andpointsthe perk points not spent yet (0for none);stats.mainlevel- the main level, among the stats:levelis the figure the game works out from the other levels,xpandnextare0(it gathers no XP) andpointsis the pool of perk points that belong to no stat or skill;perks- a list of perk GUIDs;nourishmentandenergy- numbers, or absent (nil) until the player’s game has reported them.
SetPlayerProgress takes the same shape back. A player whose game has not reported yet gives empty stats and
skills and no perks: never save that over a stored character - wait for OnPlayerProgressChange’s first call,
and for a character you restored, for the restore itself. The table is a copy; changing it changes nothing.
Syntax
Section titled “Syntax”GetPlayerProgress(pid)| Parameter | Type | |
|---|---|---|
pid |
number | the player |
Returns
Section titled “Returns”table | nil - {stats, skills, perks, nourishment, energy}, every stat and skill {level, xp, next, points}; nil for a player not connected
Example
Section titled “Example”-- keep it as one line of text in the character's row: "stat:strength:12:340.5:2;skill:alchemy:7:12.0:0;perk:<guid>"local function progress_text(pid) local progress = GetPlayerProgress(pid) if not progress or next(progress.skills) == nil then return nil end -- the game has not reported yet: nothing to save local parts = {} for name, v in pairs(progress.stats) do parts[#parts + 1] = string.format("stat:%s:%d:%.1f:%d", name, v.level, v.xp, v.points) end for name, v in pairs(progress.skills) do parts[#parts + 1] = string.format("skill:%s:%d:%.1f:%d", name, v.level, v.xp, v.points) end for _, perk in ipairs(progress.perks) do parts[#parts + 1] = "perk:" .. perk end return table.concat(parts, ";")end
function saveProgress(pid) local text = progress_text(pid) -- read now: the write runs later if text then db:Execute("UPDATE players SET progress = @p WHERE name = @n", { p = text, n = GetPlayerName(pid) }) endendSee also
Section titled “See also”SetPlayerProgress · OnPlayerProgressChange · GetPlayerStat · GetPlayerPerkPoints · GetPlayerPerks · GetDatabase · the Stats, skills, XP and perks group of the index
