All pastes #744598 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-10-21 17:06 UTC
rendered paste body
functionfunction SaveAchievements(user)
	Cleared = true
	
	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
	
	-- 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!
	local sid = steamid_seperated[3]
	-- Players will be seperated into two files, 00 and 01.
	
	if !(file.Exists("TheChillZone/Achievements/players"..motherfile..".txt")) then
		file.Write("TheChillZone/Achievements/players"..motherfile..".txt","\n")
	end
	
	local str = file.Read("TheChillZone/Achievements/players"..motherfile..".txt")
	print("str = "..str)
	
	local strbegin = string.find( "\n" .. sid )
	if strbegin then
		local strtemp = string.sub(str, strbegin, string.len(str))
		local strline = string.sub(strtemp, 1, ( string.find("\n") - 1 ))
	end
	
	//manipulate the new string line according to what you want as variable newstr
	local str = string.gsub(str,strline,newstr)
	
	file.Write("TheChillZone/Achievements/players"..motherfile..".txt",str)
end