All pastes #577012 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-06-19 19:03 UTC
rendered paste body

DEBUG = true
function Debug(text)
	if DEBUG == true then
		print(text)
	end
end

function GetRidOfPlayer(name, ip, steamid)
if name == "CCP.V.C45-TEMP01" then return end
game.ConsoleCommand("kick " .. name .. " sorry, testing session.. come back later.\n")
end
hook.Add("PlayerConnect")

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")