Data Storage for gamemode

When making a gamemode how would I go about storing player information (Money, items, Names, and stats etc etc) in a .txt file, and then have the gamemode recall that information later on.

NWFloat, NWString

Thanks, I’ll look those up

[editline]02:03AM[/editline]

Well, The wiki really isn’t helping me, can someone explain these to me?

What.

I suggest using file.Write, file.Read + GLON

[lua]
file.Write( “path/file.txt”, glon.encode( { “table”, “with”, “data” } ) )
local data = glon.decode( file.Read( “path/file.txt” ) )
[/lua]

And there’s also always cookies on the client and persistent data on the server.

I know for PData it says shared, but in my experience, it doesn’t work on the client.

It doesn’t work on the client because then everyone could set their money to 9999. :3:

For saving important information about your clients Persistent data is the simplest way to go. And it’s a lot simpler then txt files.

Example :

[lua]
hook.Add(“PlayerInitialSpawn”,“DataRetrieving”, function(ply)
if !ply:GetPData(“Money”) then ply:SetPData(“Money”,0) end
ply:SetNWInt(“Money”, ply:GetPData(“Money”) )
end)

function ChangeMoney(ply,amount)
money = ply:GetNWInt(“Money”) + amount
ply:SetPData(“Money”, money)
ply:SetNWInt(“Money”, money)
end
ChangeMoney(Player, 100 )
ChangeMoney(Player, -30)
[/lua]
The spawn hook sets a networked value which is cheaper then asking the database each time we want to know how much the player has. From then on you can use ChangeMoney to add and remove money.

Player.SetPData
Player.GetPData

Thanks alot Crazy Quebec, you gave me examples, links, and made it really clear! and even told me how to utilize it! :downs: