Andi_Evandy

VBMail_Fix

Aug 26th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.08 KB | None | 0 0
  1. /*
  2.     Name: VBMail
  3.     Description: Email system
  4.     Author: ViniBorn
  5.     Contact : [email protected]
  6.     Country : Brazil
  7.  
  8.  
  9.     ***        ***   ***   *****     ***   ***   *** ***       *****      ********    ******    ***
  10.      ***      ***    ***   *** ***   ***   ***   ***   **    ***   ***    ***  ***    *** ***   ***
  11.       ***    ***     ***   ***  ***  ***   ***   *** **      ***   ***    *** ***     ***  ***  ***
  12.        ***  ***      ***   ***   *** ***   ***   ***   **    ***   ***    ***  ***    ***   *** ***
  13.         ******       ***   ***    ******   ***   *** ****      *****      ***   ***   ***    ******
  14.        
  15.        
  16.        
  17.        
  18.        
  19.         Do not remove the credits.
  20.         Your name is valuable, do not mess it.
  21.  
  22.  
  23.         Comments:
  24.  
  25.         - The default directory for saving e-mail is: scriptfiles / emails. Create e-mail folder.
  26.  
  27.         - The default directory for user accounts is: scriptfiles / users. Modify the Players defines, according to
  28.           where the accounts are saved on your server.
  29.  
  30.         - The inbox each player has a capacity of 10 emails.
  31.        
  32.        
  33.         Updates :
  34.  
  35.         * 20/08/11
  36.  
  37.             - New method for reading email using DIALOG_STYLE_LIST
  38.             - Indication of e-mails (Read) or (not read)
  39.  
  40.  
  41. */
  42.  
  43. #include <a_samp>
  44. #include <Dini>
  45.  
  46. #define Local      "emails/%s.ini"     // Directory of emails
  47.  
  48. new Receiver[MAX_PLAYERS][32];
  49. static const Status[2][14] = {
  50. {"(Read) - "},
  51. {"(Not read) - "}
  52. };
  53. new Emails[][10] = {
  54. "1",
  55. "2",
  56. "3",
  57. "4",
  58. "5",
  59. "6",
  60. "7",
  61. "8",
  62. "9",
  63. "10"
  64. };
  65.  
  66. public OnFilterScriptInit()
  67. {
  68.     print("\n--------------------------------------");
  69.     print(" E-mail system       By: ViniBorn");
  70.     print("    - Do not remove the credits -    ");
  71.     print("--------------------------------------\n");
  72.     return 1;
  73. }
  74.  
  75. public OnFilterScriptExit()
  76. {
  77.     print("\n\tE-mail system finished.");
  78.     return 1;
  79. }
  80.  
  81. public OnPlayerCommandText(playerid, cmdtext[])
  82. {
  83.     if (strcmp("/buypc", cmdtext, true, 10) == 0)
  84.     {
  85.         if(GetPlayerMoney(playerid) < 2000) return SendClientMessage(playerid, 0xAFAFAFAA,"You don't have this amount.");
  86.         new email[32];
  87.         format(email,32,Local,Player(playerid));
  88.         if(dini_Exists(email)) return SendClientMessage(playerid, 0xAFAFAFAA,"You already have a computer.");
  89.         dini_Create(email);
  90.         for(new i = 0;i < sizeof(Emails); i++) dini_Set(email, Emails[i], "Empty");
  91.         GameTextForPlayer(playerid, "Cost : $ 2.000", 5000, 1);
  92.         GivePlayerMoney(playerid, -2000);
  93.         PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  94.         SendClientMessage(playerid, 0xAFAFAFAA, "Now you can use /email.");
  95.         return 1;
  96.     }
  97.     if(strcmp("/email", cmdtext, true, 10) == 0)
  98.     {
  99.         new email[32];
  100.         format(email, 32, Local, Player(playerid));
  101.         if(!dini_Exists(email)) return SendClientMessage(playerid, 0xAFAFAFAA,"You don't have a computer.");
  102.         new listitems[] = "Read\nSend\nDelete";
  103.         ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "My email : ", listitems,"Select","Exit");
  104.  
  105.         return 1;
  106.     }
  107.     return 0;
  108. }
  109.  
  110. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  111. {
  112.     if(dialogid == 225)
  113.     {
  114.         if(!response)
  115.             return 0;
  116.         else
  117.         {
  118.             new str[128], email[32], string[1024];
  119.             format(email,32,Local,Player(playerid));
  120.             switch (listitem)
  121.             {
  122.                 case 0:
  123.                 {
  124.                     for(new i=0;i<sizeof(Emails);i++)
  125.                     {
  126.                         format(str,128,"{C2A2DA}%d - %s\n",strval(Emails[i]),dini_Get(email,Emails[i]));
  127.                         strcat(string, str);
  128.                     }
  129.                     ShowPlayerDialog(playerid, 226, DIALOG_STYLE_LIST, "Inbox : ", string,"Select","Back");
  130.                 }
  131.                 case 1: ShowPlayerDialog(playerid, 227,DIALOG_STYLE_INPUT,"E-mail","Enter the receiver's name:","Send","Back");
  132.                 case 2: ShowPlayerDialog(playerid, 228,DIALOG_STYLE_INPUT,"E-mail","Enter the number of e-mail:","Delete","Back");
  133.             }
  134.         }
  135.     }
  136.     else if(dialogid == 226)//Read
  137.     {
  138.         if(!response)
  139.         {
  140.             new listitems[] = "Read\nSend\nDelete";
  141.             ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "My email : ", listitems,"Select","Exit");
  142.         }
  143.         else MyEmail(playerid,listitem);
  144.     }
  145.     else if(dialogid == 227)//Send (receiver)
  146.     {
  147.         if(!response)
  148.         {
  149.             new listitems[] = "Read\nSend\nDelete";
  150.             ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "My email : ", listitems,"Select","Exit");
  151.         }
  152.         else
  153.         {
  154.             new file[64];
  155.             new giveid = ReturnUser(inputtext);
  156.             format(file, 32, Local, Player(giveid));
  157.             if(!dini_Exists(file)) return SendClientMessage(playerid,0xAA3333AA,"[ERROR] The account doesn't exist.");
  158.             new str[128];
  159.             format(str,128,"You are about to send an email to %s. Enter your message.", inputtext);
  160.             SendClientMessage(playerid, 0xFFD700AA,str);
  161.             format(Receiver[playerid],32,inputtext);
  162.             return ShowPlayerDialog(playerid,229,DIALOG_STYLE_INPUT,"E-mail","Enter your message:","Send","Back");
  163.         }
  164.     }
  165.     else if(dialogid == 228)//Delete
  166.     {
  167.         if(!response)
  168.         {
  169.             new listitems[] = "Read\nSend\nDelete";
  170.             ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "My email : ", listitems,"Select","Exit");
  171.         }
  172.         else
  173.         {
  174.             new n;
  175.             n = strval(inputtext);
  176.  
  177.             new email[32];
  178.             format(email,32,Local,Player(playerid));
  179.             dini_Set(email,Emails[n-1],"Empty");
  180.         }
  181.     }
  182.     else if(dialogid == 229)//Send (message)
  183.     {
  184.         if(response)
  185.         {
  186.             SendClientMessage(playerid,0xFFD700AA,"E-mail successfully sent.");
  187.             SendEmail(playerid,inputtext);
  188.         }
  189.     }
  190.     else if(dialogid == 230)//Show e-mail
  191.     {
  192.         if(response)
  193.         {
  194.             new listitems[] = "Read\nSend\nDelete";
  195.             ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "My email : ", listitems,"Select","Exit");
  196.         }
  197.     }
  198.     return 1;
  199. }
  200.  
  201. stock MyEmail(playerid,number)
  202. {
  203.     new email[32],email2[128];
  204.     format(email,32,Local,Player(playerid));
  205.  
  206.     if(strcmp(dini_Get(email,Emails[number]),"Empty",true)==0)
  207.         return ShowPlayerDialog(playerid, 225, DIALOG_STYLE_LIST, "My email : ", "Read\nSend\nDelete","Select","Exit");
  208.  
  209.     format(email2,128,"%s",dini_Get(email,Emails[number]));
  210.     if(email2[1] == 'N')
  211.     {
  212.         strdel(email2,0,14);
  213.         dini_Set(email,Emails[number],email2);
  214.         format(email2,128,"%s%s",Status[0],dini_Get(email,Emails[number]));
  215.         dini_Set(email,Emails[number],email2);
  216.     }
  217.     ShowPlayerDialog(playerid, 230, DIALOG_STYLE_MSGBOX, "Inbox", email2, "Back", "Exit");
  218.     return 1;
  219. }
  220.  
  221. stock SendEmail(playerid,const string[])
  222. {
  223.     new email[32],str[128];
  224.     format(email,32,Local,Receiver[playerid]);
  225.     if(!dini_Exists(email))
  226.     {
  227.         for(new i=0;i<sizeof(Emails);i++) dini_Set(email,Emails[i],"Empty");
  228.     }
  229.     else
  230.     {
  231.         format(str,128,"%s %s - Sender : %s",Status[1],string,Player(playerid));
  232.         for(new i=0;i<sizeof(Emails);i++)
  233.             if(strcmp(dini_Get(email,Emails[i]),"Empty",true)==0)
  234.             {
  235.                 new giveid = ReturnUser(Receiver[playerid]);
  236.                 if(IsPlayerConnected(giveid)) GameTextForPlayer(giveid, "You received a new e-mail.", 5000, 5);
  237.                 dini_Set(email,Emails[i],str);
  238.                 return 1;
  239.             }
  240.         return SendClientMessage(playerid,0xAA3333AA,"[ERROR] The inbox is full.");
  241.     }
  242.     return 1;
  243. }
  244.  
  245. stock Player(playerid)
  246. {
  247.     new pname[MAX_PLAYER_NAME];
  248.     GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
  249.     return pname;
  250. }
  251.  
  252. stock IsNumeric(const string[])
  253. {
  254.     for (new i = 0, j = strlen(string); i < j; i++)
  255.         if(string[i] > '9' || string[i] < '0') return 0;
  256.  
  257.     return 1;
  258. }
  259.  
  260. stock ReturnUser(PlayerName[])
  261. {
  262.     if(IsNumeric(PlayerName))
  263.         return strval(PlayerName);
  264.     else
  265.     {
  266.         new found=0, id;
  267.         for(new i=0; i <= MAX_PLAYERS; i++)
  268.         {
  269.             if(IsPlayerConnected(i))
  270.             {
  271.                 new foundname[MAX_PLAYER_NAME];
  272.                 GetPlayerName(i, foundname, MAX_PLAYER_NAME);
  273.                 new namelen = strlen(foundname);
  274.                 new bool:searched=false;
  275.                 for(new pos=0; pos <= namelen; pos++)
  276.                 {
  277.                     if(searched != true)
  278.                     {
  279.                         if(strfind(foundname,PlayerName,true) == pos)
  280.                         {
  281.                             found++;
  282.                             id = i;
  283.                         }
  284.                     }
  285.                 }
  286.             }
  287.         }
  288.         if(found == 1)
  289.             return id;
  290.         else
  291.             return INVALID_PLAYER_ID;
  292.     }
  293. }
Advertisement
Add Comment
Please, Sign In to add comment