Advertisement
Kronus13

kRegister & Login System (C/Lang - 3 Idiomas)

Oct 18th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.25 KB | None | 0 0
  1. /*
  2.                 ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~
  3.                     Register & Login System
  4.                 ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~
  5.            
  6.         Olá galera , sou Kronus13 sou novo em Pawn
  7.      e programei este simples sistema de registro/login ,
  8.     utilizando a include iCmd para criar simples comandos.
  9.    
  10.         Faz 15 dias que conheci o fórum e me registrei ,
  11.       porém , precisei aguardar pela ativação da minha conta
  12.     enquanto isso... estudei bastante e assisti todos os videos
  13.      do paulor , que me abriram muito a mente para programar.
  14.    
  15.         Por isso programei esse sistema de registro/login ,
  16.     para ver e mostrar a vocês meus resultados e tambem saber
  17.       se vocês acham que eu possa a vir ser um bom scripter.
  18. */
  19.  
  20.  
  21.  
  22. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  23. /*            Includes             */
  24. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  25.  
  26. #include <      a_samp      >
  27. #include <       icmd       >
  28. #include <       dof2       >
  29. #include <       lang       >
  30.  
  31.  
  32. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  33. /*            Definições           */
  34. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  35.  
  36. #undef MAX_PLAYERS
  37. #define MAX_PLAYERS             ( 50 )              // ~ Defina aqui o número máximo de players/slots do seu host/server.
  38.  
  39. #define PASTA_USERS             "Contas/%s.ini"     // ~ Defina aqui o local de salvamento das contas dos players.
  40.  
  41. #define SKIN_INICIAL            ( 23 )              // ~ Defina aqui a skin inicial do player após o registro.
  42.  
  43.  
  44.  
  45. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  46. /*             Dialogs             */
  47. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  48. #define DIALOG_LANGUAGE         ( 00 ) // ~ Defina aqui o id da dialog de linguagem , caso haja outra dialog com o mesmo id.
  49. #define DIALOG_REGISTER         ( 01 ) // ~ Defina aqui o id da dialog de registro , caso haja outra dialog com o mesmo id.
  50. #define DIALOG_LOGIN            ( 02 ) // ~ Defina aqui o id da dialog de login , caso haja outra dialog com o mesmo id.
  51. #define DIALOG_MIDIOMA          ( 03 ) // ~ Defina aqui o id da dialog de mudança de idioma  , caso haja outra dialog com o mesmo id.
  52.  
  53.  
  54.  
  55. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  56. /*    Enums, Varáveis e Arrays.    */
  57. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  58. enum pInfo
  59. {
  60.     Idioma ,
  61.     Morreu ,
  62.     Matou
  63. }
  64. new pDados[ MAX_PLAYERS ][ pInfo ];
  65. new bool: pLogado[ MAX_PLAYERS ];
  66. new kstring[128];
  67. new mstring[128];
  68. new estring[128];
  69.  
  70.  
  71.  
  72. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  73. /*            Callbacks            */
  74. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  75. public OnFilterScriptExit()
  76. {
  77.     for(new i = 0; i < GetMaxPlayers(); ++i)
  78.     {
  79.         if(pLogado[i])
  80.             SalvarDados(i);
  81.     }
  82.     DOF2_Exit();
  83.     return 1;
  84. }
  85.  
  86. public OnPlayerRequestClass(playerid, classid)
  87. {
  88.     for(new i = 0; i < 100; ++i)
  89.         SendClientMessage(playerid, -1, " ");
  90.    
  91.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  92.     ShowPlayerDialog(playerid, DIALOG_LANGUAGE, DIALOG_STYLE_LIST, "{FFFFFF}NomeDoSeuServer", "{FFFFFF} ~ Fala Português ? \n\n ~ Speak English ? \n\n ~ Habla español ?", "Selecionar", "" );
  93.     return 1;
  94. }
  95.  
  96. public OnPlayerDisconnect(playerid, reason)
  97. {
  98.     if(pLogado[playerid])
  99.         SalvarDados(playerid);
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerDeath(playerid, killerid, reason)
  104. {
  105.     pDados[playerid][Morreu]++;
  106.     pDados[killerid][Matou]++;
  107.     return 1;
  108. }
  109.  
  110. public OnPlayerCommandText(playerid, commandid, params[])
  111. {
  112.     switch(commandid)
  113.     {
  114.         case iscmd("m,u,d,a,r,n,o,m,e"), iscmd("c,h,a,n,g,e,n,a,m,e"), iscmd("r,e,b,a,u,t,i,z,a,r"):
  115.         {
  116.             new nome_antigo[25];
  117.             if(!params[0])return SendClientMessageLang(playerid, 0xFF0000FF, "( ERRO ): Uso incorreto , o correto seria: /mudarnome [ Nome Novo ]", "( ERROR ): Incorrect usage, the correct would be: /changename [ New Name ]", "( ERROR ): El uso incorrecto, la correcta sería: /rebautizar [ Nuevo Nombre ]");
  118.  
  119.             nome_antigo = Nome(playerid);
  120.             DOF2_RemoveFile(Contas(playerid));
  121.                
  122.             SetPlayerName(playerid, params);
  123.             format(kstring, sizeof kstring, "Você alterou seu nome de {FFFFFF}%s{00FF00}, para {FFFFFF}%s{00FF00}.", nome_antigo, Nome(playerid));
  124.             format(mstring, sizeof mstring, "You changed your name from {FFFFFF}%s{00FF00} to {FFFFFF}%s{00FF00}.", nome_antigo, Nome(playerid));
  125.             format(estring, sizeof estring, "Usted cambió su nombre {FFFFFF}%s {00FF00} a {FFFFFF}%s {00FF00}.", nome_antigo, Nome(playerid));
  126.             SendClientMessageLang(playerid, 0x00FF00FF, kstring, mstring, estring);
  127.             SalvarDados(playerid);
  128.         }
  129.        
  130.         case iscmd("m,u,d,a,r,s,e,n,h,a") , iscmd("c,h,a,n,g,e,p,a,s,s"), iscmd("c,a,m,b,i,a,r,c,o,n,t,r,a,s,e,n,a"):
  131.         {
  132.             if(!params[0])return SendClientMessageLang(playerid, 0xFF0000FF, "( ERRO ): Uso incorreto , o correto seria: /mudarsenha [ Senha Nova ]", "( ERROR ): Incorrect usage, the correct would be: /changepass [ New Password ]", "( ERROR ): El uso incorrecto, la correcta sería: /cambiarcontrasena [ Nueva contraseña ]");
  133.                
  134.             DOF2_SetString(Contas(playerid), "Senha", params);
  135.             format(kstring, sizeof kstring, "Você alterou sua senha para {FFFFFF}%s{00FF00}.", params);
  136.             format(mstring, sizeof mstring, "You changed your password to {FFFFFF}%s{00FF00}.", params);
  137.             format(estring, sizeof estring, "Ha cambiado la contraseña para {FFFFFF}%s {00FF00}.", params);
  138.             SendClientMessageLang(playerid, 0x00FF00FF, kstring, mstring, estring);
  139.         }
  140.        
  141.         case iscmd("m,u,d,a,r,i,d,i,o,m,a"), iscmd("c,h,a,n,g,e,i,d,i,o,m"), iscmd("c,a,m,b,i,a,r,i,d,i,o,m,a"):
  142.         {
  143.             if(GetPlayerLang(playerid) == 0)return ShowPlayerDialog(playerid, DIALOG_MIDIOMA, DIALOG_STYLE_MSGBOX, "{FFFFFF}NomeDoSeuServer", "Para qual idioma deseja mudar ?", "Inglês", "Espanhol");
  144.             if(GetPlayerLang(playerid) == 1)return ShowPlayerDialog(playerid, DIALOG_MIDIOMA, DIALOG_STYLE_MSGBOX, "{FFFFFF}NomeDoSeuServer", "To which language you want to change ?", "Portuguese", "Spanish");
  145.             if(GetPlayerLang(playerid) == 2)return ShowPlayerDialog(playerid, DIALOG_MIDIOMA, DIALOG_STYLE_MSGBOX, "{FFFFFF}NomeDoSeuServer", "Para el idioma que desea cambiar ?", "Portugués", "Inglés");
  146.         }
  147.        
  148.         case iscmd("c,o,m,a,n,d,o,s") , iscmd("c,o,m,m,a,n,d,s"):
  149.         {
  150.             SendClientMessageLang(playerid, 0xFFFF00FF, "Comandos do servidor:", "Server's commands:", "Comandos del servidor:");
  151.             SendClientMessage(playerid, 0xFFFF00FF,     "~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~");
  152.             SendClientMessageLang(playerid, 0xFFFFFFFF, " ~ /mudarnome - /mudarsenha - /mudaridioma - /comandos", " ~ /changename - /changepass - /changeidiom - /commands", " ~ /rebautizar - /cambiarcontrasena - /cambiaridioma - /comandos");
  153.             SendClientMessage(playerid, 0xFFFF00FF,     "~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~");
  154.         }
  155.     }
  156.     return 1;
  157. }
  158.  
  159. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  160. {
  161.     if(dialogid == DIALOG_LANGUAGE)
  162.     {
  163.         if(response)
  164.         {
  165.             switch(listitem)
  166.             {
  167.                 case 0:
  168.                 {
  169.                     SetPlayerLang(playerid, 0);
  170.                     if(DOF2_FileExists(Contas(playerid)))
  171.                         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logando...", "{FFFFFF} ~ Bem-vindo de volta ! \n\n ~ Digite sua senha abaixo:", "Logar", "Cancelar");
  172.                     else
  173.                         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registrando...", "{FFFFFF} ~ Bem-vindo ! \n\n ~ Digite uma senha abaixo:", "Registrar", "Cancelar");
  174.                 }
  175.                 case 1:
  176.                 {
  177.                     SetPlayerLang(playerid, 1);
  178.                     if(DOF2_FileExists(Contas(playerid)))
  179.                         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  180.                     else
  181.                         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registering...", "{FFFFFF} ~ Welcome ! \n\n ~ Enter a password below:", "Register", "Cancel");
  182.  
  183.                 }
  184.                 case 2:
  185.                 {
  186.                     SetPlayerLang(playerid, 2);
  187.                     if(DOF2_FileExists(Contas(playerid)))
  188.                         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Inicio de sesión...", "{FFFFFF} ~ Bienvenido de nuevo ! \n\n ~ Ingrese su contraseña abajo:", "Iniciar", "Cancelar");
  189.                     else
  190.                         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registrando...", "{FFFFFF} ~ Bienvenido ! \n\n ~ Ingrese un contraseña abajo:", "Registrar", "Cancelar");
  191.                 }
  192.             }
  193.         }
  194.     }
  195.    
  196.     if(dialogid == DIALOG_LOGIN)
  197.     {
  198.         if(response)
  199.         {
  200.             if(GetPlayerLang(playerid) == 0 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logando...", "{FFFFFF} ~ Bem-vindo de volta ! \n\n ~ Digite sua senha abaixo:", "Logar", "Cancelar");
  201.             if(GetPlayerLang(playerid) == 1 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  202.             if(GetPlayerLang(playerid) == 2 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Inicio de sesión...", "{FFFFFF} ~ Bienvenido de nuevo ! \n\n ~ Ingrese su contraseña abajo:", "Iniciar", "Cancelar");
  203.  
  204.             if(!strcmp(DOF2_GetString(Contas(playerid),"Senha"), inputtext))
  205.             {
  206.                 SpawnPlayer(playerid);
  207.                 CarregarDados(playerid);
  208.                    
  209.                 SendClientMessageLang(playerid, 0x00FF00FF, "Logado com sucesso , dados carregados !", "Logged successfully loaded dice!", "Usuario dados cargados correctamente!");
  210.             }
  211.             else
  212.             {
  213.                 if(GetPlayerLang(playerid) == 0)
  214.                 {
  215.                     SendClientMessage(playerid, 0xFF0000FF, "( ERRO ): Senha incorreta , tente novamente !");
  216.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logando...", "{FFFFFF} ~ Bem-vindo de volta ! \n\n ~ Digite sua senha abaixo:", "Logar", "Cancelar");
  217.                 }
  218.                 else if(GetPlayerLang(playerid) == 1)
  219.                 {
  220.                     SendClientMessage(playerid, 0xFF0000FF, "( ERROR ): Incorrect password, please try again !");
  221.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Logging...", "{FFFFFF} ~ Welcome back ! \n\n ~ Enter your password below:", "Log in", "Cancel");
  222.                 }
  223.                 else if(GetPlayerLang(playerid) == 2)
  224.                 {
  225.                     SendClientMessage(playerid, 0xFF0000FF, "( ERROR ): Contraseña incorrecta, por favor intente de nuevo !");
  226.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Inicio de sesión...", "{FFFFFF} ~ Bienvenido de nuevo ! \n\n ~ Ingrese su contraseña abajo:", "Iniciar", "Cancelar");
  227.                 }
  228.             }
  229.         }
  230.         else Kick(playerid);
  231.     }
  232.  
  233.     if(dialogid == DIALOG_REGISTER)
  234.     {
  235.         if(response)
  236.         {
  237.             if(GetPlayerLang(playerid) == 0 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registrando...", "{FFFFFF} ~ Bem-vindo ! \n\n ~ Digite uma senha abaixo:", "Registrar", "Cancelar");
  238.             if(GetPlayerLang(playerid) == 1 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registering...", "{FFFFFF} ~ Welcome ! \n\n ~ Enter a password below:", "Register", "Cancel");
  239.             if(GetPlayerLang(playerid) == 2 && !strlen(inputtext))return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registrando...", "{FFFFFF} ~ Bienvenido ! \n\n ~ Ingrese un contraseña abajo:", "Registrar", "Cancelar");
  240.            
  241.             DOF2_CreateFile(Contas(playerid));
  242.             DOF2_SetString(Contas(playerid), "Senha", inputtext);
  243.             DOF2_SetInt(Contas(playerid), "Morreu", 0);
  244.             DOF2_SetInt(Contas(playerid), "Matou", 0);
  245.             DOF2_SetInt(Contas(playerid), "Grana", 1000);
  246.             DOF2_SetInt(Contas(playerid), "Level", 1);
  247.             DOF2_SetInt(Contas(playerid), "Pele", SKIN_INICIAL);
  248.             DOF2_SaveFile();
  249.  
  250.             SpawnPlayer(playerid);
  251.             GivePlayerMoney(playerid, 1000);
  252.             SetPlayerScore(playerid, 1);
  253.             SetPlayerSkin(playerid, SKIN_INICIAL);
  254.             pLogado[playerid] = true;
  255.  
  256.             SendClientMessageLang(playerid, 0x00FF00FF, "Registrado com sucesso , você recebeu R$1000 e 1 Level.", "Successfully registered, you will receive R$1000 and Level 1.", "Éxito registrado, recibirá 1.000 libras y el nivel 1.");
  257.             SendClientMessageLang(playerid, 0x00FF00FF, "Use: {FFFFFF}/comandos{00FF00} para ver todos os comandos do servidor.", "Use: {FFFFFF}/commands{00FF00} to see all server commands.", "Uso: {FFFFFF}/comandos{00FF00} para ver todos los comandos del servidor.");
  258.         }
  259.         else Kick(playerid);
  260.     }
  261.    
  262.     if(dialogid == DIALOG_MIDIOMA)
  263.     {
  264.         if(response)
  265.         {
  266.             if(GetPlayerLang(playerid) == 0)
  267.             {
  268.                 SetPlayerLang(playerid, 1);
  269.                 SendClientMessage(playerid, 0x00FF00FF, "Language changed successfully !");
  270.             }
  271.             else if(GetPlayerLang(playerid) == 1)
  272.             {
  273.                 SetPlayerLang(playerid, 0);
  274.                 SendClientMessage(playerid, 0x00FF00FF, "Idioma trocado com sucesso !");
  275.             }
  276.             else if(GetPlayerLang(playerid) == 2)
  277.             {
  278.                 SetPlayerLang(playerid, 0);
  279.                 SendClientMessage(playerid, 0x00FF00FF, "Idioma trocado com sucesso !");
  280.             }
  281.         }
  282.         else
  283.         {
  284.             if(GetPlayerLang(playerid) == 0)
  285.             {
  286.                 SetPlayerLang(playerid, 2);
  287.                 SendClientMessage(playerid, 0x00FF00FF, "Idioma cambiado correctamente !");
  288.             }
  289.             else if(GetPlayerLang(playerid) == 1)
  290.             {
  291.                 SetPlayerLang(playerid, 2);
  292.                 SendClientMessage(playerid, 0x00FF00FF, "Idioma cambiado correctamente !");
  293.             }
  294.             else if(GetPlayerLang(playerid) == 2)
  295.             {
  296.                 SetPlayerLang(playerid, 1);
  297.                 SendClientMessage(playerid, 0x00FF00FF, "Language changed successfully !");
  298.             }
  299.         }
  300.     }
  301.     return 1;
  302. }
  303.  
  304.  
  305.  
  306. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  307. /*             Funções             */
  308. /* ~•~•~•~•~•~•~•~•~•~•~•~•~•~•~•~ */
  309. Nome(playerid)
  310. {
  311.     new nome[MAX_PLAYER_NAME];
  312.     GetPlayerName(playerid, nome, sizeof nome);
  313.     return nome;
  314. }
  315.  
  316. Contas(playerid)
  317. {
  318.     new pasta[64], nome[MAX_PLAYER_NAME];
  319.     GetPlayerName(playerid, nome, sizeof nome);
  320.     format(pasta, sizeof pasta, PASTA_USERS, nome);
  321.     return pasta;
  322. }
  323.  
  324. SalvarDados(playerid)
  325. {
  326.     DOF2_SetInt(Contas(playerid), "Morreu", pDados[playerid][Morreu]);
  327.     DOF2_SetInt(Contas(playerid), "Matou", pDados[playerid][Matou]);
  328.     DOF2_SetInt(Contas(playerid), "Grana", GetPlayerMoney(playerid));
  329.     DOF2_SetInt(Contas(playerid), "Level", GetPlayerScore(playerid));
  330.     DOF2_SetInt(Contas(playerid), "Pele", GetPlayerSkin(playerid));
  331.     DOF2_SaveFile();
  332.    
  333.     pLogado[playerid] = false;
  334. }
  335.  
  336. CarregarDados(playerid)
  337. {
  338.     pDados[playerid][Morreu] = DOF2_GetInt(Contas(playerid), "Morreu");
  339.     pDados[playerid][Matou] = DOF2_GetInt(Contas(playerid), "Matou");
  340.     GivePlayerMoney(playerid, DOF2_GetInt(Contas(playerid), "Grana"));
  341.     SetPlayerScore(playerid, DOF2_GetInt(Contas(playerid), "Level"));
  342.     SetPlayerSkin(playerid, DOF2_GetInt(Contas(playerid), "Pele"));
  343.  
  344.     pLogado[playerid] = true;
  345. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement