Guest User

Login e Registro

a guest
Dec 27th, 2012
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.04 KB | None | 0 0
  1. #include <a_samp>
  2. #include <DOF2>
  3.  
  4. #define DIALOG_LOGIN 0
  5. #define DIALOG_REGISTRO 1
  6. #define DINHEIRO_INICIAL 5000
  7. #define SCORE_INICIAL 1
  8. new errouSenha[MAX_PLAYERS],
  9. Dinheiro[MAX_PLAYERS],
  10. Score[MAX_PLAYERS],
  11. bool:Logado[MAX_PLAYERS];
  12. public OnFilterScriptInit()
  13. {
  14.     print("\n--------------------------------------");
  15.     print(" Blank Filterscript by your name here");
  16.     print("--------------------------------------\n");
  17.     return 1;
  18. }
  19.  
  20. public OnFilterScriptExit()
  21. {
  22.     return 1;
  23. }
  24. public OnPlayerRequestSpawn(playerid)
  25. {
  26.     if(IsPlayerNPC(playerid)) return true;
  27.     if(Logado[playerid] == false)
  28.     {
  29.        
  30.         SendClientMessage(playerid, -1, "Logue-se!.");
  31.         return false;
  32.     }
  33.     return 1;
  34. }
  35. public OnPlayerRequestClass(playerid, classid)
  36. {
  37.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  38.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  39.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerConnect(playerid)
  44. {
  45.     Conectado(playerid);
  46.     return 1;
  47. }
  48.  
  49. public OnPlayerDisconnect(playerid, reason)
  50. {
  51.     DOF2_SetInt(Conta(playerid),"Dinheiro",Dinheiro[playerid]);
  52.     DOF2_SetInt(Conta(playerid),"Score",Score[playerid]);
  53.     DOF2_SaveFile();
  54.     return 1;
  55. }
  56.  
  57.  
  58. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  59. {
  60.     if(dialogid == DIALOG_LOGIN)
  61.     {
  62.        
  63.         if(response)
  64.         {
  65.            
  66.             if(!strval(inputtext)) return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Caracteres inválidos","Digite apenas números e letras!","Logar","");
  67.  
  68.             else if(!strcmp(inputtext,DOF2_GetString(Conta(playerid),"Senha"),false))
  69.             {
  70.                
  71.                 SendClientMessage(playerid,-1,"Logado com sucesso!");
  72.                 CarregarPlayer(playerid);
  73.             }
  74.             else
  75.             {
  76.                
  77.                 if(errouSenha[playerid] == 3) return SendClientMessage(playerid,-1,"Você errou a senha três vezes e foi kickado."),Kick(playerid);
  78.                 ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Senha Incorreta!","Senha Incorreta.\nErrando-a três vezes você será kickado automaticamente.","Logar","Sair");
  79.                 errouSenha[playerid] ++;
  80.             }
  81.         }
  82.         else SendClientMessage(playerid,-1,"Você usou a opção 'Sair' e foi kickado do servidor!"),Kick(playerid);
  83.     }
  84.     else if(dialogid == DIALOG_REGISTRO)
  85.     {
  86.        
  87.         if(response)
  88.         {
  89.            
  90.             if(strlen(inputtext) < 3 || strlen(inputtext) > 24) return ShowPlayerDialog(playerid,DIALOG_REGISTRO,DIALOG_STYLE_PASSWORD,"Erro","Digite uma senha de 3 à 24 caracteres!","Registrar","Sair");
  91.             DOF2_CreateFile(Conta(playerid));
  92.             DOF2_SetString(Conta(playerid),"Senha",inputtext);
  93.             Dinheiro[playerid] = DINHEIRO_INICIAL,Score[playerid] = SCORE_INICIAL;
  94.             DOF2_SetInt(Conta(playerid),"Dinheiro",Dinheiro[playerid]);
  95.             DOF2_SetInt(Conta(playerid),"Score",Score[playerid]);
  96.             DOF2_SaveFile();
  97.             Logado[playerid] = true;
  98.             GivePlayerMoney(playerid,Dinheiro[playerid]);
  99.             SetPlayerScore(playerid,Score[playerid]);
  100.             SendClientMessage(playerid,-1,"Registrado e Logado com sucesso!");
  101.         }
  102.         else SendClientMessage(playerid,-1,"Você usou a opção 'Sair' e foi kickado do servidor!"),Kick(playerid);
  103.     }
  104.     return 1;
  105. }
  106. stock Nick(playerid)
  107. {
  108.     new nome[24];
  109.     GetPlayerName(playerid,nome,sizeof(nome));
  110.     return nome;
  111. }
  112. stock Conta(playerid)
  113. {
  114.     new arq[64];
  115.     format(arq,sizeof(arq),"%s.ini",Nick(playerid));
  116.     return arq;
  117. }
  118. stock Conectado(playerid)
  119. {
  120.     if(DOF2_FileExists(Conta(playerid)))
  121.     ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Logue-se","Bem vindo novamente ao servidor.\nPara logar-se digite sua senha no diálogo abaixo:","Logar","Sair");
  122.     else
  123.     ShowPlayerDialog(playerid,DIALOG_REGISTRO,DIALOG_STYLE_PASSWORD,"Registre-se","Bem vindo à sua primeira vez no servidor.\nPara Registrar-se digite sua senha no diálogo abaixo:","Registrar","Sair");
  124. }
  125. stock CarregarPlayer(playerid)
  126. {
  127.     Logado[playerid] = true;
  128.     errouSenha[playerid] = 0;
  129.     Dinheiro[playerid] = DOF2_GetInt(Conta(playerid),"Dinheiro");
  130.     Score[playerid] = DOF2_GetInt(Conta(playerid),"Score");
  131.     GivePlayerMoney(playerid,Dinheiro[playerid]);
  132.     SetPlayerScore(playerid,Score[playerid]);
  133. }
Advertisement
Add Comment
Please, Sign In to add comment