I have already checked the wiki about this just making sure.
How would I load and save my information from a table.
My purpose for this is levels, would I save the stats after the player has successfully mine an ore?
Like run the save function directly after?
via sql.Query() and a correct line of SQL actions.
such as: "SELECT * FROM TABLE some_table WHERE id = "'..player:steamID()..'"" etc.
You can use my unfinished, around 1 year old code as a reference:
[lua]function CRP.DBCheckup()
if sql.TableExists("CRP_stats") then
print("CRP_stats exists!")
else
sql.Query("CREATE TABLE CRP_stats (id TEXT, name TEXT, money INT)")
print("CRP_stats didn't exist! Creating one now!")
end
end
CRP.DBCheckup()
function CRP.DBPlayerCheckup(ply)
local DBresult = sql.Query("SELECT * FROM CRP_stats WHERE id = '"..ply:SteamID().."'")
if DBresult == true then
CRP.DBLoadPlayer(ply)
else
CRP.DBNewPlayer(ply)
end
end
hook.Add("PlayerInitialSpawn", "PlayerCheckup", CRP.DBPlayerCheckup)
function CRP.DBLoadPlayer(ply)
local DBresult = sql.Query("SELECT * FROM CRP_stats WHERE id = '"..ply:SteamID().."'")
ply.CRPstats = {}
ply.CRPstats["Name"] = DBresult.name or ply:Name()
ply.CRPstats["Job"] = CRP.Teams[team.GetName(ply:Team())].Name or "Unemployed"
ply.CRPstats["Money"] = DBresult.money or 0
ply.CRPstats["Salary"] = CRP.Teams[team.GetName(ply:Team())].Salary or 0
CRP.SendStats(ply, false, false, true)
end
function CRP.DBNewPlayer(ply)
sql.Query("INSERT INTO CRP_stats ('id', 'name', 'money') VALUES ('"..ply:SteamID().."', 'Stranger', '0')")
CRP.DBLoadPlayer(ply)
end
function CRP.SendStats(ply, Stat, Type, SendAll)
if SendAll == true then
umsg.Start( "StatsMessage", ply )
umsg.String( ply.CRPstats.Name )
umsg.String( ply.CRPstats.Job )
umsg.Long( ply.CRPstats.Money )
umsg.Long( ply.CRPstats.Salary )
umsg.End()
end
if Stat == true then
if Type == 'String' then
umsg.Start( "StatsMessage", ply )
umsg.String( ply.CRPstats[Stat] )
umsg.End()
end
if Type == 'Long' then
umsg.Start( "StatsMessage", ply )
umsg.Long( ply.CRPstats[Stat] )
umsg.End()
end
end
end[/lua]
Obviously no one wants to help me, and just want to laugh at a new coder, thanks.
[code]function LevelUpSound( ply )
timer.Simple( 0.25, function()
ply:EmitSound( "/garrysmod/content_downloaded.wav" )
timer.Simple( 0.25, function()
ply:EmitSound( "/garrysmod/content_downloaded.wav" )
timer.Simple( 0.25, function()
ply:EmitSound( "/garrysmod/content_downloaded.wav" )
timer.Simple( 0.25, function()
ply:EmitSound( "/garrysmod/save_load1.wav" )
end )
end )
end )
end )
end[/code]
[url=http://gmodwiki.net/Lua/Libraries/timer/Create]You might wanna check out this useful function[/url]
Thanks, but I really just need help with the SQLite stuff. If anyone has a script that I could just look over for a saving function, much appreciated.
[QUOTE=nubstuff5;41052295]Thanks, but I really just need help with the SQLite stuff. If anyone has a script that I could just look over for a saving function, much appreciated.[/QUOTE]
You use an insert query to add data to your tables. Then you use a select statement to retrieve the data, look up sqlite syntax and examples on how to use it online.
Sorry, you need to Log In to post a reply to this thread.