aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/database/sv_queries.lua
blob: 4e48255fef9901631d18915c4fedcb44440da3e8 (plain)
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
--[[
	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
		invs[k] = {v.Name,v:Serialize()}
	end
	sdata.inventories = invs
	sdata.skills = ply.data.skills
	sdata.quests = ply.data.quests
	sdata.prayers = ply.data.prayers
	sdata.credits = ply.data.credits
	return util.TableToJSON(sdata)
end

function q.deserialize_player(ply,str)
	print("Deseriailizeing player",ply," with ", str)
	track.ClearInventories(ply)
	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 = ply.data or {}
	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