DEBUG = true function Debug(text) if DEBUG == true then print(text) end end require("sqlite") sql.Query("CREATE TABLE IF NOT EXISTS saves ( inc INTEGER UNIQUE AUTO INCREMENT, id TEXT NOT NULL, name TEXT NOT NULL, job TEXT NOT NULL, money INTEGER NOT NULL )") function Save( ply ) local id = ply:UniqueID(); id = sql.SQLStr( id ); sql.Query( "UPDATE saves SET job = '" .. sql.SQLStr( ply:GetNWString( "job" ) ) .. "', money = '" .. sql.SQLStr( ply:GetNWInt( "money" ) ) .. "' WHERE id = '" .. id .. "' AND name = '" .. sql.SQLStr( ply:Nick() ) .. "'" ); Debug("Saved") end AddChatCommand( "/save", Save, true ) hook.Add("PlayerDisconnect", "Save player on disconnect", Save ) function AutoSave() end function CreateNewSave( ply ) local id = ply:UniqueID(); id = sql.SQLStr( id ); print(sql.Query( "INSERT INTO saves ( id, name, job, money ) VALUES ( '" .. id .. "', '" .. sql.SQLStr( ply:Nick() ) .. "', '" .. sql.SQLStr( ply:GetNWString( "job" ) ) .. "', '" .. ply:GetNWInt( "money" ) .. "' )")) Debug("Created new save") end function Load( ply ) local id = ply:UniqueID(); id = sql.SQLStr( id ); if (sql.QueryRow( "SELECT * FROM saves WHERE id = '" .. id .. "' AND name = '" .. sql.SQLStr( ply:Nick() ) .. "' LIMIT 1;")==nil) then Debug("New player profile for " .. ply:Nick() ) CreateNewSave( ply ) end local data = sql.QueryRow( "SELECT * FROM saves WHERE id = '" .. id .. "' AND name = '" .. sql.SQLStr( ply:Nick() ) .. "'" ); ply:SetNWString( "job", tostring(data["job"]) ) ply:SetNWInt( "money", tonumber(data["money"]) ) Debug("Loaded profile for " .. ply:Nick() ) end hook.Add("PlayerInitialSpawn", "Load player profile", Load ) Debug("data.lua loaded")