deffo14863

Automessages using dialog by Nicki (deffo)

Apr 1st, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.42 KB | None | 0 0
  1. /*
  2. ||============================================================================||
  3. ||   Nicki's (a.k.a. Viky (samp forum deffo) ) filterscript for automessages  ||
  4. ||============================================================================||
  5. */
  6.  
  7. #include <a_samp>
  8. #include <sscanf2>
  9.  
  10. #define FILTERSCRIPT
  11. #define M_COLOR                 0x710000FF  //message color for user/admin
  12. #define AUTOMSGS_DIALOG         2000        //Dialog ID
  13. #define TIMEGAP                 59          //Time gap between automessages in seconds
  14. #define MAX_STRING_SIZE         129         //Maximum input size (cannot be increased due to samp limit)
  15.  
  16. new gVar2=0;
  17.  
  18. stock function_F1(playerid)
  19. {
  20.     new File:fptr3=fopen("automsgs.txt",io_read);
  21.     new string3[MAX_STRING_SIZE];
  22.     new string4[1600];
  23.     fread(fptr3,string3,sizeof(string3));
  24.     new tm;
  25.     sscanf(string3,"i",tm);
  26.     strcat(string4,"1. ",sizeof(string4));
  27.     new j=1;
  28.     new sj[3];
  29.     while(fread(fptr3,string3,sizeof(string3)))
  30.     {
  31.         strcat(string4,string3,sizeof(string4));
  32.         j++;
  33.         valstr(sj,j);
  34.         if(j>tm)
  35.         break;
  36.         else
  37.         {
  38.             strcat(string4,sj,sizeof(string4));
  39.             strcat(string4,". ",sizeof(string4));
  40.         }
  41.     }
  42.     fclose(fptr3);
  43.     strcat(string4,"\nTo edit or add, enter automessage as [number] [message]. Do not separate [no.] and [message] by a dot, just separate [no.] and [message] by a space.\nFor deleting an automessage, just enter the number of automessage followed by a space, without any message (yes you have to insert the space).",sizeof(string4));
  44.     ShowPlayerDialog(playerid, AUTOMSGS_DIALOG, DIALOG_STYLE_INPUT,"Auto Messages", string4, "Enter", "Cancel");
  45. }
  46.  
  47. forward function_F2();
  48. public function_F2()
  49. {
  50.     new File:fptr2=fopen("automsgs.txt",io_read);
  51.     new ch[3];
  52.     fread(fptr2,ch);
  53.     new tm;
  54.     sscanf(ch,"i",tm);
  55.     if(gVar2>tm)
  56.     gVar2=1;
  57.     gVar2++;
  58.     new i=1;
  59.     new string5[MAX_STRING_SIZE];
  60.     while(fread(fptr2,string5,sizeof(string5)))
  61.     {
  62.         i++;
  63.         if(i==gVar2)
  64.         break;
  65.     }
  66.     SendClientMessageToAll(-1,string5);
  67.     fclose(fptr2);
  68. }
  69.  
  70. public OnFilterScriptInit()
  71. {
  72.     print("\n-------------------------------------------------");
  73.     print(" Nicki's (deffo) automessage filter script loaded ");
  74.     print("---------------------------------------------------\n");
  75.     gVar2=1;
  76.     SetTimer("function_F2", TIMEGAP*1000 , true);
  77.     return 1;
  78. }
  79.  
  80. public OnPlayerCommandText(playerid, cmdtext[])
  81. {
  82.     if (strcmp("/automsgs", cmdtext, true) == 0)
  83.     {
  84.         if(IsPlayerAdmin(playerid))
  85.         {
  86.             function_F1(playerid);
  87.             return 1;
  88.         }
  89.         else
  90.         return 0;
  91.     }
  92.     return 0;
  93. }
  94.  
  95. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  96. {
  97.     switch(dialogid)
  98.     {
  99.         case AUTOMSGS_DIALOG:
  100.         {
  101.             if(response)
  102.             {
  103.                 new string8[MAX_STRING_SIZE];
  104.                 new val;
  105.                 new tm;
  106.                 new string7[1600];
  107.                 new File:fptr4=fopen("automsgs.txt",io_read);
  108.                 sscanf(inputtext,"i",val);
  109.                 fread(fptr4,string8);
  110.                 sscanf(string8,"i",tm);
  111.                 if(!inputtext[2] || !inputtext[3])
  112.                 {
  113.                     if(tm<=2)
  114.                     {
  115.                         SendClientMessage(playerid,M_COLOR,">>Error: There should be atleast two automessages!");
  116.                     }
  117.                     else
  118.                     {
  119.                         if(val>tm)
  120.                         {
  121.                             SendClientMessage(playerid,M_COLOR,">>Error: Invalid number entered!");
  122.                         }
  123.                         else
  124.                         {
  125.                             tm--;
  126.                             valstr(string8,tm);
  127.                             strcat(string8,"\0",sizeof(string8));
  128.                             strcat(string8,"\n",sizeof(string8));
  129.                             strcat(string7,string8,sizeof(string7));
  130.                             new i=1;
  131.                             while(fread(fptr4,string8,sizeof(string8)))
  132.                             {
  133.                                 if(i!=val)
  134.                                 strcat(string7,string8,sizeof(string7));
  135.                                 i++;
  136.                             }
  137.                             SendClientMessage(playerid,M_COLOR,">>Automessage was successfully deleted.");
  138.                             fclose(fptr4);
  139.                             new File:fptr5=fopen("automsgs.txt",io_write);
  140.                             fwrite(fptr5,string7);
  141.                             fclose(fptr5);
  142.                         }
  143.                     }
  144.                 }
  145.                 else
  146.                 {
  147.                     if(val>9)
  148.                     {
  149.                         return SendClientMessage(playerid,M_COLOR,">>Error: You can add only upto 9 automessages.");
  150.                     }
  151.                     else if(val>tm)
  152.                     {
  153.                         tm++;
  154.                         valstr(string8,tm);
  155.                         strcat(string8,"\0",sizeof(string8));
  156.                         strcat(string8,"\n",sizeof(string8));
  157.                         strcat(string7,string8,sizeof(string7));
  158.                         while(fread(fptr4,string8,sizeof(string8)))
  159.                         {
  160.                             strcat(string7,string8,sizeof(string7));
  161.                         }
  162.                         sscanf(inputtext,"{i}p<`>s[129]",string8);
  163.                         strcat(string7,string8,sizeof(string7));
  164.                         strcat(string7,"\n",sizeof(string7));
  165.                         SendClientMessage(playerid,M_COLOR,">>Automessage was successfully added.");
  166.                     }
  167.                     else
  168.                     {
  169.                         strcat(string7,string8,sizeof(string7));
  170.                         new i=1;
  171.                         while(fread(fptr4,string8,sizeof(string8)))
  172.                         {
  173.                             if(i==val)
  174.                             {
  175.                                 sscanf(inputtext,"{i}p<`>s[129]",string8);
  176.                                 strcat(string7,string8,sizeof(string7));
  177.                                 strcat(string7,"\n",sizeof(string7));
  178.                             }
  179.                             else
  180.                             strcat(string7,string8,sizeof(string7));
  181.                             i++;
  182.                         }
  183.                         SendClientMessage(playerid,M_COLOR,">>Automessage was successfully edited.");
  184.                     }
  185.                     fclose(fptr4);
  186.                     new File:fptr5=fopen("automsgs.txt",io_write);
  187.                     fwrite(fptr5,string7);
  188.                     fclose(fptr5);
  189.                 }
  190.             }
  191.         }
  192.     }
  193.     return 0;
  194. }
Advertisement
Add Comment
Please, Sign In to add comment