I'm trying to make a custom gamemode based off of the Cinema gamemode, and I was wondering what type of saving method I should use for this. Correct me if I'm wrong, but if I remember correctly you can only save with Get/SetPData, file.write(), and sql databases. Personally, I'm leaning more toward the file.write() method. The things I will be saving are standard things saved, like money, stats, player time, and custom moderation ranks.
SetPData is really useful if you want to store few values, they will persist on your local machine
Anyway, i really enjoy serializating players into json string and then saving these into files with file.Write, and again, this only will work on your machine, if do you wanna look for multi servers, go ahead with mysql
but you can do:
[lua]
function save(ply)
local tbl = {}
tbl.Health = ply:Health()
tbl.Pos = ply:GetPos()
tbl.Angle = ply:EyeAngles()
tbl.Money = ply:getDarkVar("money",0)
file.Write("savedata/"..ply:SteamID64()..".txt",util.TableToJSON(tbl))
end
function load(ply)
if(file.Exists("savedata/"..ply:SteamID64()..".txt","DATA")) then
local tbl = util.JSONToTable(file.Read("savedata/"..ply:SteamID64()..".txt","DATA"))
ply:SetHealth(tbl.Health)
ply:SetPos(tbl.Pos)
ply:SetEyeAngles(tbl.Angle)
ply:setDarkRPVar("money",tbl.Money)
end
end
[/lua]
Maybe you'll get lua errors since i can't remember how to get player money on darkrp
Anyway, that's how do i serialize player data, you can run save(player) in disconnect hook and load(player) in initial spawn hook
You really shouldn't save data to files since it is being saved into the data folder which can be downloaded by clients.
Get/SetPData are using sqlite and should be pretty damn fast compared to saving it to files.
[QUOTE=syl0r;47087029]You really shouldn't save data to files since it is being saved into the data folder which [I]can be downloaded by clients[/I]...[/QUOTE]
hmm...So? It's readable, not writable
[QUOTE=gonzalolog;47086880]SetPData is really useful if you want to store few values, they will persist on your local machine
Anyway, i really enjoy serializating players into json string and then saving these into files with file.Write, and again, this only will work on your machine, if do you wanna look for multi servers, go ahead with mysql
but you can do:
[lua]
function save(ply)
local tbl = {}
tbl.Health = ply:Health()
tbl.Pos = ply:GetPos()
tbl.Angle = ply:EyeAngles()
tbl.Money = ply:getDarkVar("money",0)
file.Write("savedata/"..ply:SteamID64()..".txt",util.TableToJSON(tbl))
end
function load(ply)
if(file.Exists("savedata/"..ply:SteamID64()..".txt","DATA")) then
local tbl = util.JSONToTable(file.Read("savedata/"..ply:SteamID64()..".txt","DATA"))
ply:SetHealth(tbl.Health)
ply:SetPos(tbl.Pos)
ply:SetEyeAngles(tbl.Angle)
ply:setDarkRPVar("money",tbl.Money)
end
end
[/lua]
Maybe you'll get lua errors since i can't remember how to get player money on darkrp
Anyway, that's how do i serialize player data, you can run save(player) in disconnect hook and load(player) in initial spawn hook[/QUOTE]
If I do it like this, will I be able to prevent it from being downloaded to clients?
Don't run this in clientside, disable allowupload and disable allowcslua
And i don't see how players would download it
I'd recommend MySQL as it's much easier to manage data and can scale to multiple servers without issue.
[QUOTE=StonedPenguin;47087681]I'd recommend MySQL as it's much easier to manage data and can scale to multiple servers without issue.[/QUOTE]
Alright, thanks, I'll go with MySQL, just in case I need to manage more than one server.
Sorry, you need to Log In to post a reply to this thread.