Advertisement
Biesmen

Automated Message filterscript 1.0 [OUTDATED]

Oct 11th, 2011
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.52 KB | None | 0 0
  1. //Automatic Client Message sender filterscript
  2. //Created by: Biesmen
  3. //http://forum.sa-mp.com/member.php?u=52068
  4. ////////////////////////////////////////////
  5. //// You can change the maximum lines to more if needed. You'll only have to change "#define MAX_LINES <your number>"
  6.  
  7. #include <a_samp>
  8. #include <sscanf2> // SSCANF by Y_Less
  9.  
  10. #define MAX_LINES 10
  11. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  12.  
  13.  
  14.  
  15. forward MessageTimer();
  16.  
  17. new Lines[MAX_LINES][256];
  18. new TIME_FOR_EACH_MESSAGE = 60; //Time in seconds
  19. new MessageTimerS;
  20.  
  21. stock ReadFileLine(File:name)
  22. {
  23.     new str[256];
  24.     for(new linez = 0; linez != 1; linez++)
  25.     {
  26.         fread(name, str);
  27.     }
  28.     return str;
  29. }
  30.  
  31. stock ReadLines()
  32. {
  33.     new File:Messages = fopen("messages.txt", io_read);
  34.     for(new dlines = 0; dlines < MAX_LINES; dlines++)
  35.     {
  36.         format(Lines[dlines],256,"%s",ReadFileLine(Messages));
  37.     }
  38.     fclose(Messages);
  39. }
  40.  
  41. public OnFilterScriptInit()
  42. {
  43.     ReadLines();
  44.     MessageTimerS = SetTimer("MessageTimer", TIME_FOR_EACH_MESSAGE*1000, true);
  45.     print("\n--------------------------------------");
  46.     print(" Automatic Client Message sender");
  47.     print(" Created by: Biesmen");
  48.     print("--------------------------------------\n");
  49.     return 1;
  50. }
  51.  
  52. public OnFilterScriptExit()
  53. {
  54.     return 1;
  55. }
  56.  
  57. public MessageTimer()
  58. {
  59.     new rand = random(MAX_LINES);
  60.     SendClientMessageToAll(0xFFFFFFAA, Lines[rand]);
  61.     print(Lines[rand]);
  62.     return 1;
  63. }
  64.  
  65. public OnPlayerCommandText(playerid, cmdtext[])
  66. {
  67.     dcmd(setline, 7, cmdtext);
  68.     dcmd(messagetime, 11, cmdtext);
  69.     if (strcmp("/toggletimer", cmdtext, true) == 0)
  70.     {
  71.         if(IsPlayerAdmin(playerid))
  72.         {
  73.             if(MessageTimerS != 0)
  74.             {
  75.                KillTimer(MessageTimerS);
  76.                MessageTimerS = 0;
  77.                SendClientMessage(playerid, 0xFF8040FF, "The Message Timer has been deactivated.");
  78.             }
  79.             else
  80.             {
  81.                 MessageTimerS = SetTimer("MessageTimer", TIME_FOR_EACH_MESSAGE*1000, true);
  82.                 SendClientMessage(playerid, 0xFF8040FF, "The Message Timer has been activated.");
  83.             }
  84.         }
  85.         return 1;
  86.     }
  87.     return 1;
  88. }
  89.  
  90. dcmd_setline(playerid, params[])    //This will NOT save the lines in messages.txt! It will only save the variable.
  91. {                                   //The next version you will be able to save it in messages.txt
  92.     new line, message[256];
  93.     if(IsPlayerAdmin(playerid))
  94.     {
  95.         if(sscanf(params, "is[256]", line, message)) return SendClientMessage(playerid, 0xFF8040FF, "USAGE: /setline [line] [message]");
  96.         if(strlen(message) > 256) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: Message too long!");
  97.         if(line > MAX_LINES+1 || line < 1) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: This line doesn't exist!");
  98.         format(Lines[line-1], 256, "%s", message);
  99.         format(message, sizeof(message), "[LINE %i]{FF8040} has changed into: %s", line, message);
  100.         SendClientMessage(playerid, 0xFFC68CFF, message);
  101.     }
  102.     return 1;
  103. }
  104.  
  105. dcmd_messagetime(playerid, params[])
  106. {
  107.     new string[53], time;
  108.     if(IsPlayerAdmin(playerid))
  109.     {
  110.         if(sscanf(params, "i", time)) return SendClientMessage(playerid, 0xFF8040FF, "USAGE: /messagetime [seconds]");
  111.         KillTimer(MessageTimerS);
  112.         TIME_FOR_EACH_MESSAGE = time;
  113.         MessageTimerS = SetTimer("MessageTimer", TIME_FOR_EACH_MESSAGE*1000, true);
  114.         format(string, sizeof(string), "The messages will now display once every %i seconds", TIME_FOR_EACH_MESSAGE);
  115.         SendClientMessage(playerid, 0xFF8040FF, string);
  116.     }
  117.     return 1;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement