Guest User

[FS]VBMail[BlogDoSamp]

a guest
Jul 28th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.44 KB | None | 0 0
  1. /*
  2.  
  3.     Nome: VBMail
  4.         Descrição: Sistema de email
  5.         Autor: ViniBorn
  6.         Contato : [email protected]
  7.  
  8.  
  9.         ***        ***   ***   *****     ***   ***   *** ***       *****      ********    ******    ***
  10.          ***      ***    ***   *** ***   ***   ***   ***   **    ***   ***    ***  ***    *** ***   ***
  11.           ***    ***     ***   ***  ***  ***   ***   *** **      ***   ***    *** ***     ***  ***  ***
  12.            ***  ***      ***   ***   *** ***   ***   ***   **    ***   ***    ***  ***    ***   *** ***
  13.         ******       ***   ***    ******   ***   *** ****      *****      ***   ***   ***    ******
  14.        
  15.        
  16.        
  17.        
  18.        
  19.         Não retire os créditos.
  20.         Seu nome é valioso, não suje-o.
  21.        
  22.        
  23.         Observações :
  24.        
  25.         - O diretório padrão para salvar os emails é : scriptfiles/emails.  Crie a pasta emails.
  26.        
  27.         - O diretório padrão para contas de usuários é : scriptfiles/users.  Modifique a define Players, de acordo com
  28.                 o local onde são salvas as contas do seu servidor.
  29.                
  30.                 - A caixa de entrada de cada jogador tem capacidade de 10 emails.
  31.                
  32.                
  33.                 Atualizações :
  34.                
  35.                 * 20/08/11
  36.                
  37.                         - Novo método para leitura de emails utilizando DIALOG_STYLE_LIST
  38.                         - Indicação de e-mails (Lido) ou (Não lido)
  39.  
  40.  
  41. */
  42.  
  43. #include <a_samp>
  44. #include <Dini>
  45.  
  46. #define Local      "/emails/%s.ini"     // Diretório dos emails
  47. #define Players    "/users/%s.ini"      // Diretório das contas
  48.  
  49. new Destinatario[MAX_PLAYERS][32];
  50. static const Status[2][14] = {
  51. {"(Lido) - "},
  52. {"(Não lido) - "}
  53. };
  54. new Emails[][10] = {
  55. "1",
  56. "2",
  57. "3",
  58. "4",
  59. "5",
  60. "6",
  61. "7",
  62. "8",
  63. "9",
  64. "10"
  65. };
  66.  
  67. public OnFilterScriptInit()
  68. {
  69.         print("\n\n--------------------------------------");
  70.         print(" Sistema de e-mail       By: ViniBorn");
  71.         print("  -      Não retire os créditos      -");
  72.         print("--------------------------------------\n");
  73.         return 1;
  74. }
  75.  
  76. public OnFilterScriptExit()
  77. {
  78.     print("\n\tSistema de e-mail descarregado.");
  79.         return 1;
  80. }
  81.  
  82. public OnPlayerCommandText(playerid, cmdtext[])
  83. {
  84.         if (strcmp("/comprarpc", cmdtext, true, 10) == 0)
  85.         {
  86.             if(GetPlayerMoney(playerid) < 2000)
  87.                 return SendClientMessage(playerid, 0xAFAFAFAA,"Você não possui esta quantia.");
  88.  
  89.         new email[32];
  90.             format(email,32,Local,Player(playerid));
  91.  
  92.             if(dini_Exists(email))
  93.                         return SendClientMessage(playerid, 0xAFAFAFAA,"Você já possui um computador.");
  94.  
  95.         dini_Create(email);
  96.  
  97.         for(new i=0;i<sizeof(Emails);i++)
  98.             dini_Set(email,Emails[i],"Vazio");
  99.  
  100.                 GameTextForPlayer(playerid, "Custo : R$ 2.000", 5000, 1);
  101.                 GivePlayerMoney(playerid, -2000);
  102.                 PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  103.                 SendClientMessage(playerid, 0xAFAFAFAA, "Agora você pode usar /email.");
  104.  
  105.                 return 1;
  106.         }
  107.         if(strcmp("/email", cmdtext, true, 10) == 0)
  108.         {
  109.             new email[32];
  110.             format(email,32,Local,Player(playerid));
  111.  
  112.         if(!dini_Exists(email))
  113.                         return SendClientMessage(playerid, 0xAFAFAFAA,"Você não possui um computador.");
  114.  
  115.             new listitems[] = "Caixa de entrada\nEnviar\nApagar";
  116.             ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "Meu email : ", listitems,"Selecionar","Sair");
  117.  
  118.             return 1;
  119.         }
  120.         return 0;
  121. }
  122.  
  123. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  124. {
  125.     if(dialogid == 225)
  126.         {
  127.             if(!response)
  128.                 return 0;
  129.                 else
  130.                 {
  131.                     new str[128], email[32], string[1024];
  132.                     format(email,32,Local,Player(playerid));
  133.                     switch (listitem)
  134.                         {
  135.                         case 0:
  136.                                 {
  137.                                         for(new i=0;i<sizeof(Emails);i++)
  138.                                         {
  139.                                                 format(str,128,"{C2A2DA}%d - %s\n",strval(Emails[i]),dini_Get(email,Emails[i]));
  140.                                                 strcat(string, str);
  141.                                         }
  142.                                     ShowPlayerDialog(playerid, 226, DIALOG_STYLE_LIST, "Caixa de entrada : ", string,"Selecionar","Voltar");
  143.                             }
  144.                             case 1:     ShowPlayerDialog(playerid, 227,DIALOG_STYLE_INPUT,"E-mail","Digite o nome do destinatário:","Enviar","Voltar");
  145.                             case 2: ShowPlayerDialog(playerid, 228,DIALOG_STYLE_INPUT,"E-mail","Digite número do e-mail:","Apagar","Voltar");
  146.                         }
  147.                 }
  148.         }
  149.     else if(dialogid == 226)//Ler
  150.         {
  151.             if(!response)
  152.             {
  153.                 new listitems[] = "Caixa de entrada\nEnviar\nApagar";
  154.                 ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "Meu email : ", listitems,"Selecionar","Sair");
  155.         }
  156.                 else
  157.                 MeuEmail(playerid,listitem);
  158.         }
  159.         else if(dialogid == 227)//Enviar (destinatário)
  160.         {
  161.             if(!response)
  162.             {
  163.                 new listitems[] = "Caixa de entrada\nEnviar\nApagar";
  164.                 ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "Meu email : ", listitems,"Selecionar","Sair");
  165.         }
  166.                 else
  167.                 {
  168.                 new file[64];
  169.                         format(file, sizeof(file), Players,inputtext);
  170.                         if(dini_Exists(file))
  171.                         {
  172.                             new giveid = ReturnUser(inputtext);
  173.                             format(file,32,Local,Player(giveid));
  174.                            
  175.                             if(!dini_Exists(file))
  176.                                         return SendClientMessage(playerid, 0xAA3333AA,"[ERRO] O jogador não possui um computador.");
  177.  
  178.                         new str[128];
  179.                                 format(str,128,"Você está prestes a enviar um e-mail para %s. Digite a mensagem.", inputtext);
  180.                             SendClientMessage(playerid, 0xFFD700AA,str);
  181.                             format(Destinatario[playerid],32,inputtext);
  182.                             return ShowPlayerDialog(playerid,229,DIALOG_STYLE_INPUT,"E-mail","Digite a mensagem:","Enviar","Voltar");
  183.                 }
  184.                         else
  185.                         SendClientMessage(playerid,0xAA3333AA,"[ERRO] A conta não existe.");
  186.                 }
  187.         }
  188.         else if(dialogid == 228)//Apagar
  189.         {
  190.             if(!response)
  191.             {
  192.                 new listitems[] = "Caixa de entrada\nEnviar\nApagar";
  193.                 ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "Meu email : ", listitems,"Selecionar","Sair");
  194.         }
  195.                 else
  196.                 {
  197.                 new n;
  198.                         n = strval(inputtext);
  199.  
  200.                     new email[32];
  201.                     format(email,32,Local,Player(playerid));
  202.                         dini_Set(email,Emails[n-1],"Vazio");
  203.                 }
  204.         }
  205.         else if(dialogid == 229)//Enviar (mensagem)
  206.         {
  207.             if(response)
  208.             {
  209.                 SendClientMessage(playerid,0xFFD700AA,"E-mail enviado com sucesso ");
  210.                         EnviarEmail(playerid,inputtext);
  211.                 }
  212.         }
  213.         else if(dialogid == 230)//Exibir e-mail
  214.         {
  215.             if(response)
  216.             {
  217.                 new listitems[] = "Caixa de entrada\nEnviar\nApagar";
  218.                 ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "Meu email : ", listitems,"Selecionar","Sair");
  219.         }
  220.         }
  221.         return 1;
  222. }
  223.  
  224. stock MeuEmail(playerid,numero)
  225. {
  226.     new email[32],email2[128];
  227.     format(email,32,Local,Player(playerid));
  228.  
  229.     if(strcmp(dini_Get(email,Emails[numero]),"Vazio",true)==0)
  230.         return ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "Meu email : ", "Caixa de entrada\nEnviar\nApagar","Selecionar","Sair");
  231.  
  232.     format(email2,128,"%s",dini_Get(email,Emails[numero]));
  233.     if(email2[1] == 'N')
  234.     {
  235.                 strdel(email2,0,14);
  236.                 dini_Set(email,Emails[numero],email2);
  237.                 format(email2,128,"%s%s",Status[0],dini_Get(email,Emails[numero]));
  238.                 dini_Set(email,Emails[numero],email2);
  239.         }
  240.     ShowPlayerDialog(playerid, 230, DIALOG_STYLE_MSGBOX, "VBMail", email2, "Voltar", "Sair");
  241.     return 1;
  242. }
  243.  
  244. stock EnviarEmail(playerid,const string[])
  245. {
  246.         new email[32],str[128];
  247.     format(email,32,Local,Destinatario[playerid]);
  248.     if(!dini_Exists(email))
  249.     {
  250.             for(new i=0;i<sizeof(Emails);i++)
  251.             dini_Set(email,Emails[i],"Vazio");
  252.     }
  253.     else
  254.     {
  255.         format(str,128,"%s %s - Remetente : %s",Status[1],string,Player(playerid));
  256.                 for(new i=0;i<sizeof(Emails);i++)
  257.                 if(strcmp(dini_Get(email,Emails[i]),"Vazio",true)==0)
  258.                 {
  259.                     new giveid = ReturnUser(Destinatario[playerid]);
  260.                     if(IsPlayerConnected(giveid))
  261.                         GameTextForPlayer(giveid, "Voce recebeu um novo e-mail.", 5000, 5);
  262.                         dini_Set(email,Emails[i],str);
  263.                         return 1;
  264.                         }
  265.  
  266.         return SendClientMessage(playerid,0xAA3333AA,"[ERRO] A caixa de entrada está lotada.");
  267.         }
  268.         return 1;
  269. }
  270.  
  271. stock Player(playerid)
  272. {
  273.         new pname[MAX_PLAYER_NAME];
  274.         GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
  275.         return pname;
  276. }
  277.  
  278. stock IsNumeric(const string[])
  279. {
  280.         for (new i = 0, j = strlen(string); i < j; i++)
  281.             if(string[i] > '9' || string[i] < '0') return 0;
  282.  
  283.         return 1;
  284. }
  285.  
  286. stock ReturnUser(PlayerName[])
  287. {
  288.         if(IsNumeric(PlayerName))
  289.             return strval(PlayerName);
  290.         else
  291.         {
  292.                 new found=0, id;
  293.                 for(new i=0; i <= MAX_PLAYERS; i++)
  294.                 {
  295.                         if(IsPlayerConnected(i))
  296.                         {
  297.                                 new foundname[MAX_PLAYER_NAME];
  298.                                 GetPlayerName(i, foundname, MAX_PLAYER_NAME);
  299.                                 new namelen = strlen(foundname);
  300.                                 new bool:searched=false;
  301.                         for(new pos=0; pos <= namelen; pos++)
  302.                                 {
  303.                                         if(searched != true)
  304.                                         {
  305.                                                 if(strfind(foundname,PlayerName,true) == pos)
  306.                                                 {
  307.                                         found++;
  308.                                                         id = i;
  309.                                                 }
  310.                                         }
  311.                                 }
  312.                         }
  313.                 }
  314.                 if(found == 1)
  315.                         return id;
  316.                 else
  317.                         return INVALID_PLAYER_ID;
  318.         }
  319. }
Advertisement
Add Comment
Please, Sign In to add comment