Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Register & Login system using BUD - Blazing User Database
- Credits:
- * BUD by Slice
- * BUD tutorial by Rock
- * ZCMD by Zeex - Improved by Yashas
- * SSCANF plugin by Y_Less
- * SA-MP Team - Past & Present (including beta testers)
- * Compuphase for PAWN
- To do:
- - Add autologin
- - Document/Comment & Why is it done the way it is scripted
- - Improve code readability and names
- - Improve dialog text (colors, etc.)
- DONE:
- - Add minimum and maximum password characters
- - Add 3 tries to Login
- */
- #include < a_samp >
- #include < izcmd >
- #include < sscanf2 >
- #if defined MAX_PLAYERS
- #undef MAX_PLAYERS
- #endif
- #define MAX_PLAYERS 50
- #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
- #include < BUD >
- #define MAX_LOGIN_ATTEMPTS 3
- enum
- {
- Register_D1,
- Login_D1,
- Success_1,
- Success_0
- }
- enum data
- {
- isLoggedIn,
- Login_Attempts
- }
- new Player_Info[MAX_PLAYERS][data];
- main()
- {
- print(" zero_11 started");
- }
- public OnGameModeInit()
- {
- SetGameModeText("Blank Script");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- 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
- BUD::Initialize( );
- BUD::VerifyColumn( "Money", BUD::TYPE_NUMBER, 50 ); // 50 - optional parameter, this will add value 50 to column "Money" when it's created
- //BUD::VerifyColumn( "Rank", BUD::TYPE_STRING, "Newbie" );
- return 1;
- }
- public OnGameModeExit()
- {
- BUD::Exit( );
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
- return 1;
- }
- stock GetName( playerid )
- {
- new _RocKzSk[ MAX_PLAYER_NAME ];
- GetPlayerName( playerid, _RocKzSk, sizeof _RocKzSk );
- return ( _RocKzSk );
- }
- public OnPlayerConnect(playerid)
- {
- Player_Info[playerid][isLoggedIn] = 0;
- Player_Info[playerid][Login_Attempts] = 1;
- new _rK[ 128 ];
- if( !BUD::IsNameRegistered( GetName( playerid ) ) )
- {
- format( _rK, sizeof( _rK ), "Welcome %s\nYou need an account to play on this server.", GetName( playerid ) );
- ShowPlayerDialog( playerid, Register_D1, DIALOG_STYLE_INPUT, "New Account", _rK, "Register", "Kick" );
- }
- else
- {
- format( _rK, sizeof( _rK ), "Welcome %s\nThis account is already registered.\nLogin now.", GetName( playerid ) );
- ShowPlayerDialog( playerid, Login_D1, DIALOG_STYLE_INPUT, "Login", _rK, "Login", "Kick" );
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == Register_D1 && response == 1)
- {
- if(strlen(inputtext) >= 3 && strlen(inputtext) <= 16)
- {
- if ( BUD::RegisterName( GetName( playerid ), inputtext ))
- {
- new iUID = BUD::GetNameUID( GetName( playerid ) );
- BUD::MultiSet( iUID, "s", "Password", inputtext );
- new _rK[ 128 ];
- format( _rK, sizeof( _rK ), "Welcome %s\nThis account is already registered.\nLogin now.", GetName( playerid ) );
- ShowPlayerDialog( playerid, Login_D1, DIALOG_STYLE_INPUT, "Login", _rK, "Login", "Kick" );
- }
- }
- else
- {
- new _rK[ 128 ];
- format( _rK, sizeof( _rK ), "Welcome %s\nYou need an account to play on this server.", GetName( playerid ) );
- ShowPlayerDialog( playerid, Register_D1, DIALOG_STYLE_INPUT, "Password minimum: 3 and maximum: 16", _rK, "Register", "Kick" );
- }
- }
- else if(dialogid == Register_D1 && response == 0) return Kick(playerid);
- if(dialogid == Login_D1 && response == 1)
- {
- if( BUD::CheckAuth( GetName( playerid ), inputtext ))
- {
- new _Money, iUID = BUD::GetNameUID( GetName( playerid ) );
- BUD::MultiGet( iUID, "i", "Money", _Money);
- GivePlayerMoney( playerid, _Money );
- SetPlayerScore( playerid, _Money );
- Player_Info[playerid][isLoggedIn] = 1;
- ShowPlayerDialog(playerid, Success_1, DIALOG_STYLE_MSGBOX, "Logged In", "Congratulations...", "Okay", "");
- }
- else
- {
- #if defined MAX_LOGIN_ATTEMPTS
- if(Player_Info[playerid][Login_Attempts] < MAX_LOGIN_ATTEMPTS)
- {
- Player_Info[playerid][Login_Attempts]++;
- new _rK[ 128 ];
- format( _rK, sizeof( _rK ), "Welcome %s\nThis account is already registered.\nLogin now.", GetName( playerid ) );
- ShowPlayerDialog( playerid, Login_D1, DIALOG_STYLE_INPUT, "Login", _rK, "Login", "Kick" );
- }
- else if(Player_Info[playerid][Login_Attempts] >= MAX_LOGIN_ATTEMPTS) return Kick(playerid);
- #else
- new _rK[ 128 ];
- format( _rK, sizeof( _rK ), "Welcome %s\nThis account is already registered.\nLogin now.", GetName( playerid ) );
- ShowPlayerDialog( playerid, Login_D1, DIALOG_STYLE_INPUT, "Login", _rK, "Login", "Kick" );
- #endif
- }
- }
- else if(dialogid == Login_D1 && response == 0) return Kick(playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if( Player_Info[playerid][isLoggedIn] == 1)
- {
- new iUID = BUD::GetNameUID( GetName( playerid ) );
- BUD::MultiSet( iUID, "i","Money", GetPlayerMoney( playerid ));
- }
- Player_Info[playerid][isLoggedIn] = 0;
- Player_Info[playerid][Login_Attempts] = 0;
- return 1;
- }
- CMD:givemoney(playerid, params[]) // need to test ingame & add chat messages
- {
- new target, money;
- if(sscanf(params, "ii", target, money)) return SendClientMessage(playerid, 0xFFFFFF, "USE: /givemoney [player ID] [Money Ammount]");
- if(target != INVALID_PLAYER_ID)
- {
- GivePlayerMoney(target, money);
- }
- else SendClientMessage(playerid, 0xFFFFFF, "Wrong ID! Player not connected.");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment