Guest User

Registro/Login

a guest
Dec 26th, 2012
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.92 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.  
  67.             if(!strcmp(inputtext,DOF2_GetString(Conta(playerid),"Senha"),false)&&strlen(inputtext) >= 3 && strlen(inputtext) <= 24)
  68.             {
  69.                
  70.                 SendClientMessage(playerid,-1,"Logado com sucesso!");
  71.                 CarregarPlayer(playerid);
  72.             }
  73.             else
  74.             {
  75.                
  76.                 if(errouSenha[playerid] == 3) return SendClientMessage(playerid,-1,"Você errou a senha três vezes e foi kickado."),Kick(playerid);
  77.                 ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Senha Incorreta!","Senha Incorreta.\nErrando-a três vezes você será kickado automaticamente.","Logar","Sair");
  78.                 errouSenha[playerid] ++;
  79.             }
  80.         }
  81.         else SendClientMessage(playerid,-1,"Você usou a opção 'Sair' e foi kickado do servidor!"),Kick(playerid);
  82.     }
  83.     else if(dialogid == DIALOG_REGISTRO)
  84.     {
  85.        
  86.         if(response)
  87.         {
  88.            
  89.             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");
  90.             DOF2_CreateFile(Conta(playerid));
  91.             DOF2_SetString(Conta(playerid),"Senha",inputtext);
  92.             Dinheiro[playerid] = DINHEIRO_INICIAL,Score[playerid] = SCORE_INICIAL;
  93.             DOF2_SetInt(Conta(playerid),"Dinheiro",Dinheiro[playerid]);
  94.             DOF2_SetInt(Conta(playerid),"Score",Score[playerid]);
  95.             DOF2_SaveFile();
  96.             Logado[playerid] = true;
  97.             GivePlayerMoney(playerid,Dinheiro[playerid]);
  98.             SetPlayerScore(playerid,Score[playerid]);
  99.             SendClientMessage(playerid,-1,"Registrado e Logado com sucesso!");
  100.         }
  101.         else SendClientMessage(playerid,-1,"Você usou a opção 'Sair' e foi kickado do servidor!"),Kick(playerid);
  102.     }
  103.     return 1;
  104. }
  105. stock Nick(playerid)
  106. {
  107.     new nome[24];
  108.     GetPlayerName(playerid,nome,sizeof(nome));
  109.     return nome;
  110. }
  111. stock Conta(playerid)
  112. {
  113.     new arq[64];
  114.     format(arq,sizeof(arq),"%s.ini",Nick(playerid));
  115.     return arq;
  116. }
  117. stock Conectado(playerid)
  118. {
  119.     if(DOF2_FileExists(Conta(playerid)))
  120.     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");
  121.     else
  122.     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");
  123. }
  124. stock CarregarPlayer(playerid)
  125. {
  126.     Logado[playerid] = true;
  127.     errouSenha[playerid] = 0;
  128.     Dinheiro[playerid] = DOF2_GetInt(Conta(playerid),"Dinheiro");
  129.     Score[playerid] = DOF2_GetInt(Conta(playerid),"Score");
  130.     GivePlayerMoney(playerid,Dinheiro[playerid]);
  131.     SetPlayerScore(playerid,Score[playerid]);
  132. }
Advertisement
Add Comment
Please, Sign In to add comment