Guest User

Untitled

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