Advertisement
Guest User

Register System by XStormiest

a guest
May 2nd, 2013
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.17 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. #include <a_samp> //Thanks to SA-MP Team
  3. #include <bud>   //Thanks to Slice for his awesome Blazing User Database System.
  4.  
  5. enum dData
  6. {
  7.    Score,
  8.    Money
  9. }
  10.  
  11. #define DATABASE_NAME "Register.db" //the name of the database , can be edit. [WARNING]Syntax .db must be there!!!! ex: Mytabe.db, SS.db
  12.  
  13. //if youd isable these 2 : you'll get an warning but don't worry cause is just an warning ;)
  14. #define SAVE_SCORE true //if save_score is true , score column will be created in the database also, will be save and loat from the database , else the oposite will happen
  15. #define SAVE_MONEY true //if save_money is true , money column will be created in the database also, will be save and loat from the database , else the oposite will happen
  16.  
  17.  
  18. #define REGISTER_DIALOG 15 // ID OF THE REGISTER DIALOG
  19. #define LOGIN_DIALOG 18 // ID OF THE LOGIN DIALOG
  20.  
  21. #define MAX_CHARACTERS 10 //max of characters for the password
  22. #define MIN_CHARACTERS 5 //min of characters for the password
  23.  
  24. #define SERVER_NAME "[Name of the server]" //the name of the server wich will appear in your dialog
  25.  
  26. public OnFilterScriptInit()
  27. {
  28.     print("\n--------------------------------------");
  29.     print(" Register system by XStormiest. loaded!");
  30.     print("--------------------------------------\n");
  31.     //Save in to the Database
  32.     BUD::Setting( opt.Database, DATABASE_NAME);
  33.     BUD::Setting( opt.Asynchronous, true );
  34.     BUD::Setting( opt.KeepAliveTime, 3000);
  35.     BUD::Setting( opt.CheckForUpdates, true);
  36.    
  37.     BUD::Initialize();
  38.     #if SAVE_SCORE == true
  39.     BUD::VerifyColumn("Score",BUD::TYPE_NUMBER);
  40.     #endif
  41.    
  42.     #if SAVE_MONEY == true
  43.     BUD::VerifyColumn("Money",BUD::TYPE_NUMBER);
  44.     #endif
  45.     return 1;
  46. }
  47.  
  48. public OnFilterScriptExit()
  49. {
  50.     print("\n--------------------------------------");
  51.     print(" Blank Filterscript by XStormiest. unloaded!");
  52.     print("--------------------------------------\n");
  53.     return 1;
  54. }
  55.  
  56. public OnPlayerConnect(playerid)
  57. {
  58.     new name[MAX_PLAYER_NAME];
  59.     GetPlayerName(playerid,name,sizeof(name));
  60.     if(BUD::IsNameRegistered(name) == false)
  61.     {
  62.        new register[256];
  63.        format(register,sizeof(register), "Welcome to %s,%s\nPlease enjoy the server by making your account.\nYou'll have benefits like saving your stats.\nWrite under your desired password",SERVER_NAME,name);
  64.        ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"Register...",register,"Register","Leave");
  65.     }
  66.     else
  67.     {
  68.        new login[256];
  69.        format(login,sizeof(login),"Hey again %s, and welcome again to the %s\nIt look like you already register in our database\nSo please log in by using your password",name,SERVER_NAME);
  70.        ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"Login...",login,"Login","Leave");
  71.     }
  72.     return 1;
  73. }
  74.  
  75. public OnPlayerDisconnect(playerid,reason)
  76. {
  77.    new name[MAX_PLAYER_NAME];
  78.    GetPlayerName(playerid,name,sizeof(name));
  79.    new userid = BUD::GetNameUID(name);
  80.    if(BUD::IsNameRegistered(name) == true)
  81.    {
  82.       #if SAVE_SCORE == true
  83.       BUD::MultiSet(userid,"i","Score",GetPlayerScore(playerid) );
  84.       #endif
  85.      
  86.       #if SAVE_MONEY == true
  87.       BUD::MultiSet(userid,"i","Money",GetPlayerMoney(playerid) );
  88.       #endif
  89.    }
  90.    return 1;
  91. }
  92.  
  93. public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
  94. {
  95.   new name[MAX_PLAYER_NAME];
  96.   GetPlayerName(playerid,name,sizeof(name));
  97.   new userid = BUD::GetNameUID(name);
  98.  
  99.   if(dialogid == REGISTER_DIALOG)
  100.   {
  101.     if(!response) Kick(playerid);
  102.     if(response)
  103.     {
  104.       if(strlen(inputtext) < MIN_CHARACTERS || strlen(inputtext) > MAX_CHARACTERS)
  105.       {
  106.         new register[256];
  107.         format(register,sizeof(register), "Welcome to %s,%s\nPlease enjoy the server by making your account.\nYou'll have benefits like saving your stats.\nWrite under your desired password\nPassword must be min %d characters, and max %d characters",SERVER_NAME,name,MIN_CHARACTERS,MAX_CHARACTERS);
  108.         ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"Register...",register,"Register","Leave");
  109.       }
  110.       else
  111.       {
  112.          BUD::RegisterName(name,inputtext);
  113.          #if SAVE_SCORE == true
  114.          BUD::MultiSet(userid,"i","Score",0);
  115.          #endif
  116.          
  117.          #if SAVE_MONEY == true
  118.          BUD::MultiSet(userid,"i","Money",0);
  119.          #endif
  120.          SendClientMessage(playerid,-1,"[ACCOUNT]Your account was created and saved to the database.");
  121.       }
  122.     }
  123.   }
  124.   if(dialogid == LOGIN_DIALOG)
  125.   {
  126.      if(!response) Kick(playerid);
  127.      if(response)
  128.      {
  129.         if(BUD::CheckAuth(name,inputtext) == false)
  130.         {
  131.            new login[256];
  132.            format(login,sizeof(login),"Hey again %s, and welcome again to the %s\nIt look like you already register in our database\nSo please log in by using your password\nERROR: incorrect password",name,SERVER_NAME);
  133.            ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"Login...",login,"Login","Leave");
  134.         }
  135.         else
  136.         {
  137.            #if SAVE_SCORE == true
  138.            SetPlayerScore(playerid,BUD::GetIntEntry(userid,"Score") );
  139.            #endif
  140.            
  141.            #if SAVE_MONEY == true
  142.            ResetPlayerMoney(playerid);
  143.            GivePlayerMoney(playerid,BUD::GetIntEntry(userid,"Money"));
  144.            #endif
  145.            
  146.            SendClientMessage(playerid,-1,"[ACCOUNT]Your account was loaded from the database.");
  147.         }
  148.      }
  149.   }
  150.   return 1;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement