Skip to content

GetPlayerProgress

Everything a mode saves with a character - stats, skills, perk points, perks, nourishment and energy.

One table:

  • stats and skills - {strength = {level = 12, xp = 340.5, next = 620, points = 2}, ...}, one entry for each the server knows. level is the level, xp the XP gathered toward the next level, next the XP the next level takes in all (0 at the top level, or before the game has reported it) and points the perk points not spent yet (0 for none);
  • stats.mainlevel - the main level, among the stats: level is the figure the game works out from the other levels, xp and next are 0 (it gathers no XP) and points is the pool of perk points that belong to no stat or skill;
  • perks - a list of perk GUIDs;
  • nourishment and energy - 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.

GetPlayerProgress(pid)
Parameter Type
pid number the player

table | nil - {stats, skills, perks, nourishment, energy}, every stat and skill {level, xp, next, points}; nil for a player not connected

-- 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) }) end
end

SetPlayerProgress · OnPlayerProgressChange · GetPlayerStat · GetPlayerPerkPoints · GetPlayerPerks · GetDatabase · the Stats, skills, XP and perks group of the index