diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-21 17:52:42 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-21 17:52:42 -0400 |
| commit | 5e6e88f98300d4c3d41aad7cff5346539f4f9f66 (patch) | |
| tree | bc5de00f63a8b1d5226b0c2988fcdaa06f6e2f13 /gamemode/core/database | |
| parent | 978909d830dd173f8b018f36c5f142d225732ba1 (diff) | |
| download | artery-5e6e88f98300d4c3d41aad7cff5346539f4f9f66.tar.gz artery-5e6e88f98300d4c3d41aad7cff5346539f4f9f66.tar.bz2 artery-5e6e88f98300d4c3d41aad7cff5346539f4f9f66.zip | |
Fixed loading bug
Fixed a bug where the equipment inventory would not load correctly.
Diffstat (limited to 'gamemode/core/database')
| -rw-r--r-- | gamemode/core/database/sv_queries.lua | 9 | ||||
| -rw-r--r-- | gamemode/core/database/sv_setup.lua | 28 |
2 files changed, 15 insertions, 22 deletions
diff --git a/gamemode/core/database/sv_queries.lua b/gamemode/core/database/sv_queries.lua index 4e48255..f059b44 100644 --- a/gamemode/core/database/sv_queries.lua +++ b/gamemode/core/database/sv_queries.lua @@ -11,19 +11,21 @@ function q.serialize_player(ply) local sdata = {} local invs = {} for k,v in pairs(ply.data.inventories) do - invs[k] = {v.Name,v:Serialize()} + 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 - return util.TableToJSON(sdata) + local ret = util.TableToJSON(sdata) + return ret end function q.deserialize_player(ply,str) - print("Deseriailizeing player",ply," with ", str) track.ClearInventories(ply) + ply.data = ply.data or {} local tbl = util.JSONToTable(str) local invs = tbl.inventories print("Inventories was", invs) @@ -32,7 +34,6 @@ function q.deserialize_player(ply,str) 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 {} diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua index 607c7be..6a7548d 100644 --- a/gamemode/core/database/sv_setup.lua +++ b/gamemode/core/database/sv_setup.lua @@ -52,35 +52,22 @@ function sql.GetPlayerData(ply) local s64 = ply:SteamID64() local q_str = q.s_fmt(fetch_player_query,s64) local q_suc = function(res,li) - --print("Got player's data:",res,type(res)) + print("Got player's data:",res,type(res)) if res == nil then - --print("Was nil, createing player data") + print("Was nil, createing player data") sql.CreatePlayerTable(ply) else - --PrintTable(res) assert(#res == 1,"Not unique!") - --print("Was unique!") local meta = res[1].MetaData local plyd = res[1].PlayerData local mtbl = util.JSONToTable(meta) - --print("About to check if we are on the right server") + print("About to check if we are on the right server") if mtbl.lastserver ~= game.GetIPAddress() then - --print("Connecting player to ", mtbl.lastserver, " was on ", game.GetIPAddress()) + print("Connecting player to ", mtbl.lastserver, " was on ", game.GetIPAddress()) ply:ConCommand("connect " .. mtbl.lastserver) return end - --print("We were on the right server") - - --print("Before finding data in the metatable, mtbl was ") - --PrintTable(mtbl) - --print(type(mtbl.lastlocation)) - local _,_,x,y,z = string.find(mtbl.lastlocation,"([-%d%.]+) ([-%d%.]+) ([-%d%.]+)") - local vec = {x,y,z} - for k,v in pairs(vec) do vec[k] = tonumber(v) end - --print("setting player pos to") - --PrintTable(vec) - - ply:SetPos(Vector(unpack(vec))) + ply:SetPos(mtbl.lastlocation) q.deserialize_player(ply,plyd) end end @@ -88,6 +75,11 @@ function sql.GetPlayerData(ply) MySQLite.query(q_str,q_suc,q_fai) end +concommand.Add("artery_loadplayer",function(ply,cmd,args) + if not ply:IsAdmin() then return end + sql.GetPlayerData(ply) +end) + function sql.CreatePlayerTable(ply) --print("Createing player table....") local s64 = ply:SteamID64() |
