Your Ad Here

Subscribe
 Post #1
 3rd November 2009
MachinEZ's Avatar
March 2008
75 Posts
I can't save my tables in .txt =/
local id = string.Replace( ply:SteamID(), "." , "_" )
	if !file.Exists("ag/"..string.lower(id)..".txt") then
		local name = string.Replace( ply:SteamID(), ".", "_" )
		local t = {id = ply:SteamID(), xp = 0, rank = 1, money = 0}
		file.Write( "ag/"..name..".txt", util.TableToKeyValues(t) )
		ply:SetNetworkedInt("rank", 1)
		ply:SetNetworkedInt("xp", 0)
		ply:SetNetworkedInt("money", 0)
	else
		print("Found profile for "..ply:Nick())
		local name = string.Replace( ply:SteamID(), ".", "_" )
		local read = util.KeyValuesToTable( file.Read( "ag/"..name..".txt") )
		ply:SetNetworkedInt( "xp", read.xp)
		ply:SetNetworkedInt( "rank", read.rank)
		ply:SetNetworkedInt( "money", read.money)
	end
 Post #2
 3rd November 2009
yakahughes's Avatar
April 2008
947 Posts
It won't save with : in it either.
 Post #3
 3rd November 2009
Gold Member
Crazy Quebec's Avatar
May 2008
2,586 Posts
My answer would be don't save to a txt file, save to the server's Sqlite database.

With either these (simpler) :
http://wiki.garrysmod.com/?title=Player.SetPData
http://wiki.garrysmod.com/?title=Player.GetPData

Or these (More efficient) :
http://wiki.garrysmod.com/?title=Sql
 Post #4
 3rd November 2009
MachinEZ's Avatar
March 2008
75 Posts
so like this
function setdata(ply)
ply:SetPData("rank", "xp", "money")
end
 Post #5
 3rd November 2009
yakahughes's Avatar
April 2008
947 Posts
so like this
function setdata(ply)
ply:SetPData("rank", "xp", "money")
end
No,

function setdata(ply)
ply:SetPData("rank", ranknum)
ply:SetPData("xp", xpnum)
ply:SetPData("money", moneynum)
end

where ranknum, xpnum, and moneynum must be replaced with their respective values, or vars that contain them.
 Post #6
 3rd November 2009
MachinEZ's Avatar
March 2008
75 Posts
ah ok thanks :DD
 Post #7
 3rd November 2009
Dennab
October 2009
416 Posts
Also, I suggest you use string.gsub rather than string.Replace.

string.Replace is a shit copy of gsub
 Post #8
 3rd November 2009
matte3560's Avatar
March 2009
32 Posts
Quick question: is the SQLite saving more efficient than file writing? I'm working on a DM gamemode with a friend, and we currently use file writing to update xp, levels and so on. This does seem to make our test server struggle a bit when there are multiple players on (Pentilum 3 based server for testing purposes only, so that's part of the issue).
 Post #9
 3rd November 2009
Salads's Avatar
November 2008
619 Posts
Quick question: is the SQLite saving more efficient than file writing? I'm working on a DM gamemode with a friend, and we currently use file writing to update xp, levels and so on. This does seem to make our test server struggle a bit when there are multiple players on (Pentilum 3 based server for testing purposes only, so that's part of the issue).
SQL would be more efficient than a flat file database, however you should only query necessary.
 Post #10
 3rd November 2009
Gold Member
Crazy Quebec's Avatar
May 2008
2,586 Posts
SQL would be more efficient than a flat file database, however you should only query necessary.
Exactly for instance when you want to know the value of a player's data, only query the database once at startup then use a copy of the value you keep in a variable on the server. After that you should only need to save to the database.
 Post #11
 3rd November 2009
matte3560's Avatar
March 2009
32 Posts
Exactly for instance when you want to know the value of a player's data, only query the database once at startup then use a copy of the value you keep in a variable on the server. After that you should only need to save to the database.
We are doing that, but the server seems to chug when players get killed (this triggers XP saving etc.) anyway.
 Post #12
 3rd November 2009 Last edited by | FlapJack |; 3rd November 2009 at 08:33PM..
Dennab
October 2009
416 Posts
We are doing that, but the server seems to chug when players get killed (this triggers XP saving etc.) anyway.
Instead of saving on kill, save on ShutDown, PlayerDisconnect and periodically on a timer (Or save a temporary flat file incase the server crashes)
 Post #13
 3rd November 2009
Salads's Avatar
November 2008
619 Posts
We are doing that, but the server seems to chug when players get killed (this triggers XP saving etc.) anyway.
You're not doing queries only when necessary.
 Post #14
 4th November 2009
gmt2001's Avatar
August 2007
218 Posts
You can save and load to a .txt file using GLON

to use GLON you must make sure your file has the line
require ( "glon" )
At the top

TO use glon to save a file do this
local data = glon.encode( table_i_want_to_save )
file.Write( file_i_want_to_save_to, data )

TO read a glon encoded file back into a table
local encdata = file.Read( file_i_want_to_load )
variable_i_want_this_stored_in = glon.decode( encdata )
Reply

All times are GMT. The time now is 07:11AM.

Facepunch Studios 2010 - Server 'MARGE'