Subscribe
 Post #1
 2 Weeks Ago
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
 2 Weeks Ago
yakahughes's Avatar
April 2008
353 Posts
It won't save with : in it either.
 Post #3
 2 Weeks Ago
Crazy Quebec's Avatar
May 2008
1,226 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
 2 Weeks Ago
MachinEZ's Avatar
March 2008
75 Posts
so like this
function setdata(ply)
ply:SetPData("rank", "xp", "money")
end
 Post #5
 2 Weeks Ago
yakahughes's Avatar
April 2008
353 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
 2 Weeks Ago
MachinEZ's Avatar
March 2008
75 Posts
ah ok thanks :DD
 Post #7
 2 Weeks Ago
| FlapJack |'s Avatar
October 2009
398 Posts
Also, I suggest you use string.gsub rather than string.Replace.

string.Replace is a shit copy of gsub
 Post #8
 2 Weeks Ago
matte3560's Avatar
March 2009
28 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
 2 Weeks Ago
Salads's Avatar
November 2008
602 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
 2 Weeks Ago
Crazy Quebec's Avatar
May 2008
1,226 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
 2 Weeks Ago
matte3560's Avatar
March 2009
28 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
 2 Weeks Ago Last edited by | FlapJack |; 2 Weeks Ago at 09:33PM..
| FlapJack |'s Avatar
October 2009
398 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
 2 Weeks Ago
Salads's Avatar
November 2008
602 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
 2 Weeks Ago
gmt2001's Avatar
August 2007
209 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 11:56PM.

Facepunch Studios 2009 - Server 'Softlayer 2.0'