Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Automated Message filterscript 3.0

By: Biesmen on Apr 5th, 2012  |  syntax: PAWN  |  size: 5.21 KB  |  views: 170  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //=========================================================================//
  2. //* Automatic Client Message Sender Filterscript
  3. //* Version: 3.0
  4. //=========================================================================//
  5. //* Created by:
  6. //* Biesmen
  7. //                      http://forum.sa-mp.com/member.php?u=52068
  8. //=========================================================================//
  9.  
  10. #include <a_samp>
  11. #include <sscanf2> // SSCANF by Y_Less
  12.  
  13. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  14.  
  15.  
  16. forward MessageTimer();
  17.  
  18. new Lines[20][256],
  19.         MessageTime = 1,
  20.         MessageTimerS,
  21.         MaxLines,
  22.         NextLine;
  23.  
  24. stock WriteFileLine()
  25. {
  26.         new cline = 0;
  27.         new File:name = fopen("messages.txt", io_write);
  28.         while(cline != MaxLines)
  29.         {
  30.             cline++;
  31.                 fwrite(name, Lines[cline]);
  32.         }
  33.         fclose(name);
  34.         return 1;
  35. }
  36.  
  37. stock ReadLines()
  38. {
  39.         new str[256], dlines = 0;
  40.         new File:Messages = fopen("messages.txt", io_read);
  41.         while(fread(Messages, str, sizeof(str)))
  42.         {
  43.                 dlines++;
  44.                 format(Lines[dlines],256,"%s",str);
  45.         }
  46.         MessageTime = strval(Lines[1]);
  47.         MaxLines = dlines;
  48.         fclose(Messages);
  49.         return 1;
  50. }
  51.  
  52. ////////////////////////////////
  53. // Created by Ryder`         //
  54. ///////////////////////////////
  55. stock ColouredText(text[])
  56. {
  57.     new
  58.         pos = -1,
  59.         string[(128 + 16)]
  60.     ;
  61.     strmid(string, text, 0, 128, (sizeof(string) - 16));
  62.  
  63.     while((pos = strfind(string, "#", true, (pos + 1))) != -1)
  64.     {
  65.         new
  66.             i = (pos + 1),
  67.             hexCount
  68.         ;
  69.         for( ; ((string[i] != 0) && (hexCount < 6)); ++i, ++hexCount)
  70.         {
  71.             if(!(('a' <= string[i] <= 'f') || ('A' <= string[i] <= 'F') || ('0' <= string[i] <= '9')))
  72.             {
  73.                 break;
  74.             }
  75.         }
  76.         if((hexCount == 6) && !(hexCount < 6))
  77.         {
  78.             string[pos] = '{';
  79.             strins(string, "}", i);
  80.         }
  81.     }
  82.     return string;
  83. }
  84. ////////////////////////////////
  85.  
  86. public OnFilterScriptInit()
  87. {
  88.         ReadLines();
  89.         MessageTimerS = SetTimer("MessageTimer", MessageTime*1000, true);
  90.         print("\n--------------------------------------");
  91.         print(" Automatic Client Message sender");
  92.         print(" Created by: Biesmen");
  93.         print("--------------------------------------\n");
  94.         return 1;
  95. }
  96.  
  97. public OnFilterScriptExit()
  98. {
  99.         return 1;
  100. }
  101.  
  102. public MessageTimer()
  103. {
  104.     new rand;
  105.     if(NextLine == 0)
  106.     {
  107.         rand = random(MaxLines);
  108.         if(strlen(Lines[rand]) == 0) return MessageTimer();
  109.         if(strcmp(Lines[rand], Lines[1], true) == 0) return MessageTimer();
  110.         }
  111.         else
  112.         {
  113.             rand = NextLine;
  114.             NextLine = 0;
  115.         }
  116.         SendClientMessageToAll(0xFFFFFFAA, Lines[rand]);
  117.         printf("%s", Lines[rand]);
  118.         return 1;
  119. }
  120.  
  121. public OnPlayerCommandText(playerid, cmdtext[])
  122. {
  123.         dcmd(nextline, 8, cmdtext);
  124.         dcmd(setline, 7, cmdtext);
  125.         dcmd(messagetime, 11, cmdtext);
  126.  
  127.         if (strcmp("/toggletimer", cmdtext, true) == 0)
  128.         {
  129.             if(IsPlayerAdmin(playerid))
  130.             {
  131.                         if(MessageTimerS != 0)
  132.                         {
  133.                            KillTimer(MessageTimerS);
  134.                            MessageTimerS = 0;
  135.                            SendClientMessage(playerid, 0xFF8040FF, "The Message Timer has been deactivated.");
  136.                         }
  137.                         else
  138.                         {
  139.                             MessageTimerS = SetTimer("MessageTimer", MessageTime*1000, true);
  140.                                 SendClientMessage(playerid, 0xFF8040FF, "The Message Timer has been activated.");
  141.                         }
  142.                 }
  143.                 return 1;
  144.         }
  145.         return 0;
  146. }
  147.  
  148. dcmd_nextline(playerid, params[])
  149. {
  150.         new line, str[128];
  151.         if(IsPlayerAdmin(playerid))
  152.         {
  153.             if(sscanf(params, "i", line)) return SendClientMessage(playerid, 0xFF8040FF, "USAGE: /nextline [line]");
  154.             if(line > MaxLines-1 || line < 1) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: This line doesn't exist!");
  155.             NextLine = line+1;
  156.                 format(str, sizeof(str), "Next line to be announced is Line %i", line);
  157.                 SendClientMessage(playerid, 0xFFC68CFF, str);
  158.         }
  159.         return 1;
  160. }
  161.  
  162. dcmd_setline(playerid, params[])
  163. {
  164.         new line, message[256];
  165.         if(IsPlayerAdmin(playerid))
  166.         {
  167.                 if(sscanf(params, "is[256]", line, message)) return SendClientMessage(playerid, 0xFF8040FF, "USAGE: /setline [line] [message]");
  168.                 if(strlen(message) > 256) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: Message too long!");
  169.                 if(line > MaxLines-1 || line < 1) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: This line doesn't exist!");
  170.                 message = ColouredText(message);
  171.                 format(Lines[line+1], 256, "%s\r\n", message);
  172.                 WriteFileLine();
  173.                 format(message, sizeof(message), "[LINE %i]{FF8040} has changed into: %s", line, message);
  174.                 SendClientMessage(playerid, 0xFFC68CFF, message);
  175.         }
  176.         return 1;
  177. }
  178.  
  179. dcmd_messagetime(playerid, params[])
  180. {
  181.         new string[53], time;
  182.         if(IsPlayerAdmin(playerid))
  183.         {
  184.                 if(sscanf(params, "i", time)) return SendClientMessage(playerid, 0xFF8040FF, "USAGE: /messagetime [seconds]");
  185.                 KillTimer(MessageTimerS);
  186.                 MessageTime = time;
  187.                 MessageTimerS = SetTimer("MessageTimer", MessageTime*1000, true);
  188.                 format(string, sizeof(string), "The messages will now display once every %i seconds", MessageTime);
  189.                 SendClientMessage(playerid, 0xFF8040FF, string);
  190.                 format(Lines[1], 256, "%i\r\n", time);
  191.                 WriteFileLine();
  192.         }
  193.         return 1;
  194. }