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.
statsandskills- each value is a level (12) or{level = 12, xp = 340.5, points = 2}; every one is an exact set, asSetPlayerStatandSetPlayerSkillmake it, lowering too.pointsare the perk points not spent yet, set exactly asSetPlayerPerkPointssets them - none counts as0, 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 alevel, aleveloutside0..30, anxpbelow0orpointsabove999skips the whole entry, which is logged.warfarefollows the weapon skills: only itspointsare put back.stats.mainlevel- the main level is the game’s to work out, so only itspoints, the pool of perk points that belong to no stat or skill, are put back; whateverlevelthe 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 listGetPlayerProgressreturns holds them; a list of the mode’s own takes them away unless it names them too.nourishmentandenergy- numbers, asSetPlayerNourishmentandSetPlayerEnergytake 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.
Syntax
Section titled “Syntax”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} |
Returns
Section titled “Returns”boolean - false for an argument that is no table, or a player not connected
Example
Section titled “Example”-- the text progress_text() saved (see GetPlayerProgress), back into a tablelocal 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 progressend
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)endSee also
Section titled “See also”GetPlayerProgress · OnPlayerProgressChange · SetPlayerStat · SetPlayerSkill · SetPlayerPerkPoints · AddPlayerPerk · the Stats, skills, XP and perks group of the index
