I can't save my tables in .txt =/
[lua]
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
[/lua]
It won't save with : in it either.
My answer would be don't save to a txt file, save to the server's Sqlite database.
With either these (simpler) :
[url]http://wiki.garrysmod.com/?title=Player.SetPData[/url]
[url]http://wiki.garrysmod.com/?title=Player.GetPData[/url]
Or these (More efficient) :
[url]http://wiki.garrysmod.com/?title=Sql[/url]
so like this
[lua]
function setdata(ply)
ply:SetPData("rank", "xp", "money")
end
[/lua]
[QUOTE=MachinEZ;18170990]so like this
[lua]
function setdata(ply)
ply:SetPData("rank", "xp", "money")
end
[/lua][/QUOTE]
No,
[lua]
function setdata(ply)
ply:SetPData("rank", ranknum)
ply:SetPData("xp", xpnum)
ply:SetPData("money", moneynum)
end
[/lua]
where ranknum, xpnum, and moneynum must be replaced with their respective values, or vars that contain them.
ah ok thanks :DD
Also, I suggest you use string.gsub rather than string.Replace.
string.Replace is a shit copy of gsub :ninja:
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).
[QUOTE=matte3560;18171465]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).[/QUOTE]
SQL would be more efficient than a flat file database, however you should only query necessary.
[QUOTE=Salads;18171516]SQL would be more efficient than a flat file database, however you should only query necessary.[/QUOTE]
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.
[QUOTE=Crazy Quebec;18171590]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.[/QUOTE]
We are doing that, but the server seems to chug when players get killed (this triggers XP saving etc.) anyway.
[QUOTE=matte3560;18171716]We are doing that, but the server seems to chug when players get killed (this triggers XP saving etc.) anyway.[/QUOTE]
Instead of saving on kill, save on ShutDown, PlayerDisconnect and periodically on a timer (Or save a temporary flat file incase the server crashes)
[QUOTE=matte3560;18171716]We are doing that, but the server seems to chug when players get killed (this triggers XP saving etc.) anyway.[/QUOTE]
You're not doing queries only when necessary.
You can save and load to a .txt file using GLON
to use GLON you must make sure your file has the line
[lua]require ( "glon" )[/lua]At the top
TO use glon to save a file do this
[lua]
local data = glon.encode( table_i_want_to_save )
file.Write( file_i_want_to_save_to, data )[/lua]
TO read a glon encoded file back into a table
[lua]
local encdata = file.Read( file_i_want_to_load )
variable_i_want_this_stored_in = glon.decode( encdata )
[/lua]
Sorry, you need to Log In to post a reply to this thread.