17.02.2013, 08:42
(
Последний раз редактировалось Rock; 20.12.2013 в 15:43.
)
Blazing User Database | Complete tutorial
Written by Rock
Choose what you want to learn:1. Creating database and columns
2. Save and extract data from the database
3. Set and extract data DIRECTLY into/from database
4. Last set of functions which BUD have.
You will learn how to use these functions:
Код:
BUD::Setting( setting[], value ) bool BUD::Initialize( ) bool BUD::Exit( ) BUD::VerifyColumn( column[], type[, default value ] ) bool BUD::IsNameRegistered( name[] ) bool BUD::RegisterName( name[], password[] ) BUD::UnregisterName( name[] ) bool BUD::CheckAuth( name[], password[] ) BUD::GetNameUID( name[] ) Float BUD::GetFloatEntry( uid, entry[] ) BUD::GetIntEntry( uid, entry[] ) BUD::GetStringEntry( uid, entry[], &value[][, size ] ) bool BUD::MultiGet( uid, type definitions, ( entry, &variable )... ) bool BUD::MultiSet( uid, type definitions, ( entry, value )... ) bool BUD::SetIntEntry( uid, entry[], value ) bool BUD::SetFloatEntry( uid, entry[], Float:value ) bool BUD::SetStringEntry( uid, entry[], value[][, size ] ) BUD::RunQuery( query[], bool:store_results ) BUD::EscapeSqlString( string[ ] ) BUD::GetSortedData( &results[][], column ) bool BUD::GetNamesForSortedData( results[][], num_results, &names[][] )
Before include BUD we need to have this defined
pawn Код:
#define BUD_USE_WHIRLPOOL false // false - if you don't want to use the WHIRLPOOL plugin and true if we use it
#define BUD_MAX_COLUMNS 10 // 10 - max number of columns witch will be alowed in the database
pawn Код:
#include < BUD >
Next, go to OnGameModeInit if it's a gamemode or OnfilterScriptInit if it's fs
pawn Код:
public OnFilterScriptInit( )
{
}
pawn Код:
BUD::Setting( opt.Database, "Users.db" ); // "Users.db" will be the name of the database we create
BUD::Setting( opt.Asynchronous, true ); // If it's true it will be faster but in case of anything happens with your computer the database can be corrupted.
BUD::Setting( opt.KeepAliveTime, 3000 ); // The database will remain active vor 3000 milliseconds after it's used, this is useful for performance
BUD::Setting( opt.CheckForUpdates, true ); // Name says it all, true if you want to search for updates
WARNING: This must be done before we will use any of it's functions
pawn Код:
BUD::Initialize( );
pawn Код:
BUD::VerifyColumn( "Money", BUD::TYPE_NUMBER );
BUD::TYPE:
TYPE_NUMBER: Numbers (1,2,3, 34343)
TYPE_STRING : String(bla, test, rock)
TYPE_FLOAT : Float(2.0, 3.2, 34.33)
TYPE_BINARY : Not supported yet, this will be in the next version
Optional parameters for VerifyColumn:
pawn Код:
BUD::VerifyColumn( "Money", BUD::TYPE_NUMBER, 50 ); // 50 - optional parameter, this will add value 50 to column "Money" when it's created
If it's a string do like this:
pawn Код:
BUD::VerifyColumn( "Rank", BUD::TYPE_STRING, "Newbie" );
pawn Код:
BUD::Exit( );
At the end your script will look like this:
pawn Код:
#include < a_samp >
#define BUD_USE_WHIRLPOOL false
#define BUD_MAX_COLUMNS 10
#include < BUD >
public OnFilterScriptInit( )
{
BUD::Setting( opt.Database, "Users.db" );
BUD::Setting( opt.Asynchronous, true );
BUD::Setting( opt.KeepAliveTime, 3000 );
BUD::Setting( opt.CheckForUpdates, true );
BUD::Initialize( );
BUD::VerifyColumn( "Points", BUD::TYPE_NUMBER );
// With optional parameter
BUD::VerifyColumn( "Money", BUD::TYPE_NUMBER, 50 );
BUD::VerifyColumn( "Rank", BUD::TYPE_STRING, "Newbie" );
BUD::VerifyColumn( "Health", BUD::TYPE_FLOAT, 100.00 );
}
public OnFilterScriptExit( )
{
BUD::Exit( );
}