Guest User

Register/Login Script

a guest
Dec 7th, 2011
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.71 KB | None | 0 0
  1.  
  2. #include <a_samp>
  3. #include <dini>
  4.  
  5.  
  6. #define DIALOG_REGISTER 1
  7. #define DIALOG_LOGIN 2
  8.  
  9.  
  10. public OnPlayerConnect(playerid)
  11. {
  12.     new data[64];
  13.     new name[MAX_PLAYER_NAME];
  14.     GetPlayerName(playerid, name, sizeof(name));
  15.     format(data, sizeof(data), "/Accounts/#s.txt", name);
  16.     if(dini_Exists(data))
  17.     {
  18.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
  19.         return 1;
  20.     }
  21.     ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Please register by typing you password below.", "Register", "Cancel");
  22.     return 1;
  23. }
  24.  
  25. public OnDialogResponse(playerid, dialogid, response, listitem,inputtext[])
  26. {
  27.     if(dialogid == DIALOG_LOGIN)
  28.     {
  29.         if(response == 0)
  30.         {
  31.             SendClientMessage(playerid,0xFFFFFFFF, "You choosed to not login!");
  32.             Kick(playerid);
  33.             return 1;
  34.         }
  35.         if(response == 1)
  36.         {
  37.             if(!strlen(inputtext))
  38.             {
  39.             SendClientMessage(playerid,0xFFFFFFFF, "You havent filled in a password!");
  40.             ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
  41.             return 1;
  42.             }
  43.             Login(playerid, inputtext);
  44.             return 1;
  45.         }
  46.     }
  47.     if(dialogid == DIALOG_REGISTER)
  48.     {
  49.         if(response == 0)
  50.         {
  51.             SendClientMessage(playerid,0xFFFFFFFF, "You choosed to not register!");
  52.             Kick(playerid);
  53.             return 1;
  54.         }
  55.         if(response == 1)
  56.         {
  57.             if(!strlen(inputtext))
  58.             {
  59.             SendClientMessage(playerid,0xFFFFFFFF, "You havent filled in a password!");
  60.             ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Please register by typing you password below.", "Register", "Cancel");
  61.             return 1;
  62.             }
  63.             Register(playerid, inputtext);
  64.             return 1;
  65.         }
  66.     }
  67.     return 1;
  68. }
  69.  
  70. stock Register(playerid,key[])
  71. {
  72.     new data[64];
  73.     new name[MAX_PLAYER_NAME];
  74.     GetPlayerName(playerid, name, sizeof(name));
  75.     format(data, sizeof(data), "/Accounts/#s.txt", name);
  76.     dini_Set(data, "Password", key);
  77.     SendClientMessage(playerid,0xFFFFFFFF, "Account Registered!");
  78.     dini_IntSet(data, "Score",0);
  79.     dini_Create(data);
  80.     return 1;
  81. }
  82.  
  83. stock Login(playerid,key[])
  84. {
  85.     new data[64];
  86.     new name[MAX_PLAYER_NAME];
  87.     GetPlayerName(playerid, name, sizeof(name));
  88.     format(data, sizeof(data), "/Accounts/#s.txt", name);
  89.    
  90.     if(!strcmp(key,dini_Get(data,"Password"),false))
  91.     {
  92.          SetPlayerScore(playerid,dini_Int(data,"Score"));
  93.          SendClientMessage(playerid,0xFFFFFFFF, "Login Successful!");
  94.          return 1;
  95.     }
  96.     else
  97.     {
  98.         SendClientMessage(playerid,0xFF0000FF, "Wrong Password!");
  99.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
  100.         return 1;
  101.     }
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment