function SaveAchievements(user)
--[[
local str = ""
if user.Achieves then
for k,v in pairs(user.Achieves) do
str = str..k.."@"..v.."\n"
end
end
file.Write("TheChillZone/Achievements/"..string.gsub(user:SteamID(),":","_")..".txt",str)
--user:PrintMessage(3,"[CZM] Achievements saved.")]]
-- Make sure we have all the achievements in file. This will make 11 entries per player.
for k,v in pairs(Achieve) do
local unique = k
print(tostring(unique))
if not user.Achieves[unique] then
user.Achieves[unique] = 0
end
end
local str = ""
Cleared = true
-- Optimize the ID so we can save as little data as possible, yet have enough to make sure there are no duplicates.
local sid = user:SteamID()
local steamid_seperated = string.Explode(":",sid)
local motherfile = string.sub(steamid_seperated[1], 7, 7) .. steamid_seperated[2] -- Thanks to Termy58 for helping me figure this'n out!
sid = string.gsub(sid,steamid_seperated[1],"")
sid = string.gsub(sid,steamid_seperated[2],"")
sid = string.gsub(sid,":","")
-- Players will be seperated into two files, 00 and 01.
if file.Exists("TheChillZone/Achievements/players"..motherfile..".txt") then
print("Exists")
str = file.Read("TheChillZone/Achievements/players"..motherfile..".txt")
print("Str = "..str)
local pbl = string.Explode("\n",str)
for key,v in pairs(pbl) do
print("Checking pbl["..key.."] ("..pbl[key]..")")
for ach,amt in pairs(user.Achieves) do
print("Crosschecking achievement "..ach.." with amount of "..amt.." for pbl["..key.."]")
local pba = string.Explode("@",pbl[key])
if pba[2] then
print("pba[2] exists ("..pba[2]..")")
if pba[1] == sid then -- If the ID matches...
print("pba[1] == sid ("..pba[1].." == "..sid..")")
if pba[2] == ach then -- If the achievement matches...
print("pba[2] == ach ("..pba[2].." == "..ach..")")
print("prior to change, pba[3] == "..pba[3])
str = string.gsub(str,pba[3],amt) -- Replace the old amount with the new amount.
print("after the change, pba[3] == "..pba[3]..", should be "..amt)
Cleared = false
end
end
end
end
end
end
print("\n\n\nSTRING IS: "..str.."\n\n")
if Cleared then
for k,v in pairs(user.Achieves) do
print(tostring(k))
str = str..sid.."@"..k.."@"..v.."\n"
end
end
file.Write("TheChillZone/Achievements/players"..motherfile..".txt",str)
end