DEBUG = truefunction Debug(text) if DEBUG == true then print(text) endendrequire("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")endAddChatCommand( "/save", Save, true )hook.Add("PlayerDisconnect", "Save player on disconnect", Save ) function AutoSave()endfunction 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")endfunction 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() )endhook.Add("PlayerInitialSpawn", "Load player profile", Load )Debug("data.lua loaded")