Skip to content

SetPlayerProgress

Puts a saved progression back on the player’s character - a whole restore.

progress has the shape GetPlayerProgress returns, and every part of it is optional: a part left out is left alone.

  • stats and skills - each value is a level (12) or {level = 12, xp = 340.5, points = 2}; every one is an exact set, as SetPlayerStat and SetPlayerSkill make it, lowering too. points are the perk points not spent yet, set exactly as SetPlayerPerkPoints sets them - none counts as 0, so the points a fresh character starts with never outlive the restore of one who had spent theirs. A name the server does not know, an entry without a level, a level outside 0 .. 30, an xp below 0 or points above 999 skips the whole entry, which is logged. warfare follows the weapon skills: only its points are put back.
  • stats.mainlevel - the main level is the game’s to work out, so only its points, the pool of perk points that belong to no stat or skill, are put back; whatever level the entry holds is ignored. Restoring the stats and skills moves the main level by itself.
  • perks - a list of GUIDs (or names): when it is there, the character ends up with exactly those perks, {} meaning none (with the caveat below). Every player is given the perfect block, the riposte and the master strikes when they first spawn, and the list GetPlayerProgress returns holds them; a list of the mode’s own takes them away unless it names them too.
  • nourishment and energy - numbers, as SetPlayerNourishment and SetPlayerEnergy take them.

The restore belongs at the login, before the player’s first spawn: the orders wait for the spawn and go out right after it, in order. The perks the character holds beyond the list are taken away only once the server has heard which perks they hold (the player’s game reports them after the spawn); a restore at the login therefore adds the missing ones, and a second call after OnPlayerProgressChange’s first one makes the list exact.

SetPlayerProgress(pid, progress)
Parameter Type
pid number the player
progress table {stats = {...}, skills = {...}, perks = {...}, nourishment = n, energy = n}, a stat or skill level or {level, xp, points}

boolean - false for an argument that is no table, or a player not connected

-- the text progress_text() saved (see GetPlayerProgress), back into a table
local function progress_table(text)
local progress = {stats = {}, skills = {}, perks = {}}
for kind, name, level, xp, points in text:gmatch("(%a+):([%w_]+):(%d+):([%d.]+):(%d+)") do
progress[kind == "stat" and "stats" or "skills"][name] = {level = tonumber(level), xp = tonumber(xp), points = tonumber(points)}
end
for perk in text:gmatch("perk:([%x%-]+)") do progress.perks[#progress.perks + 1] = perk end
return progress
end
function OnPlayerConnect(pid)
local name = GetPlayerName(pid)
db:Query("SELECT progress FROM players WHERE name = @n", { n = name }, function(rows, err)
if GetPlayerName(pid) ~= name then return end -- they left before the answer
if err then Log("progress: " .. err) return end -- restored[pid] stays unset: nothing is saved over the character
if rows[1] and rows[1].progress then SetPlayerProgress(pid, progress_table(rows[1].progress)) end
restored[pid] = true
end)
end

GetPlayerProgress · OnPlayerProgressChange · SetPlayerStat · SetPlayerSkill · SetPlayerPerkPoints · AddPlayerPerk · the Stats, skills, XP and perks group of the index