1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
--[[
Some helper functions for building sql queries
]]
local fn = nrequire("utility/fn.lua")
local track = nrequire("core/inventory/sv_invtracker.lua")
local q = {}
function q.serialize_player(ply)
local sdata = {}
local invs = {}
for k,v in pairs(ply.data.inventories) do
local idata = string.format("%q",v:Serialize())
invs[k] = {v.Name,string.sub(idata,2,#idata-1)} --remove the otter quotes
end
sdata.inventories = invs
sdata.skills = ply.data.skills
sdata.quests = ply.data.quests
sdata.prayers = ply.data.prayers
sdata.credits = ply.data.credits
local ret = util.TableToJSON(sdata)
return ret
end
function q.deserialize_player(ply,str)
track.ClearInventories(ply)
ply.data = ply.data or {}
local tbl = util.JSONToTable(str)
local invs = tbl.inventories
print("Inventories was", invs)
PrintTable(invs)
for k,v in pairs(invs) do
print("Giveing inventory",v[1],v[2])
track.GiveInventoryWithData(ply,v[1],v[2])
end
ply.data.skills = tbl.skills or {}
ply.data.quests = tbl.quests or {}
ply.data.prayers = tbl.prayers or {}
ply.data.credits = tbl.credits or 100
print("After deserializeing player, their .data is",ply.data)
PrintTable(ply.data)
track.SendPlayerData(ply)
end
function q.s_fmt(fmt,...)
local args = {...}
fn.map(args,MySQLite.SQLStr)
return string.format(fmt,unpack(args))
end
return q
|