Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Automatic Client Message sender filterscript
- //Created by: Biesmen
- //http://forum.sa-mp.com/member.php?u=52068
- ////////////////////////////////////////////
- //// You can change the maximum lines to more if needed. You'll only have to change "#define MAX_LINES <your number>"
- #include <a_samp>
- #include <sscanf2> // SSCANF by Y_Less
- #define MAX_LINES 10
- #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
- forward MessageTimer();
- new Lines[MAX_LINES][256];
- new TIME_FOR_EACH_MESSAGE = 60; //Time in seconds
- new MessageTimerS;
- stock ReadFileLine(File:name)
- {
- new str[256];
- for(new linez = 0; linez != 1; linez++)
- {
- fread(name, str);
- }
- return str;
- }
- stock ReadLines()
- {
- new File:Messages = fopen("messages.txt", io_read);
- for(new dlines = 0; dlines < MAX_LINES; dlines++)
- {
- format(Lines[dlines],256,"%s",ReadFileLine(Messages));
- }
- fclose(Messages);
- }
- public OnFilterScriptInit()
- {
- ReadLines();
- MessageTimerS = SetTimer("MessageTimer", TIME_FOR_EACH_MESSAGE*1000, true);
- print("\n--------------------------------------");
- print(" Automatic Client Message sender");
- print(" Created by: Biesmen");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public MessageTimer()
- {
- new rand = random(MAX_LINES);
- SendClientMessageToAll(0xFFFFFFAA, Lines[rand]);
- print(Lines[rand]);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(setline, 7, cmdtext);
- dcmd(messagetime, 11, cmdtext);
- if (strcmp("/toggletimer", cmdtext, true) == 0)
- {
- if(IsPlayerAdmin(playerid))
- {
- if(MessageTimerS != 0)
- {
- KillTimer(MessageTimerS);
- MessageTimerS = 0;
- SendClientMessage(playerid, 0xFF8040FF, "The Message Timer has been deactivated.");
- }
- else
- {
- MessageTimerS = SetTimer("MessageTimer", TIME_FOR_EACH_MESSAGE*1000, true);
- SendClientMessage(playerid, 0xFF8040FF, "The Message Timer has been activated.");
- }
- }
- return 1;
- }
- return 1;
- }
- dcmd_setline(playerid, params[]) //This will NOT save the lines in messages.txt! It will only save the variable.
- { //The next version you will be able to save it in messages.txt
- new line, message[256];
- if(IsPlayerAdmin(playerid))
- {
- if(sscanf(params, "is[256]", line, message)) return SendClientMessage(playerid, 0xFF8040FF, "USAGE: /setline [line] [message]");
- if(strlen(message) > 256) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: Message too long!");
- if(line > MAX_LINES+1 || line < 1) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: This line doesn't exist!");
- format(Lines[line-1], 256, "%s", message);
- format(message, sizeof(message), "[LINE %i]{FF8040} has changed into: %s", line, message);
- SendClientMessage(playerid, 0xFFC68CFF, message);
- }
- return 1;
- }
- dcmd_messagetime(playerid, params[])
- {
- new string[53], time;
- if(IsPlayerAdmin(playerid))
- {
- if(sscanf(params, "i", time)) return SendClientMessage(playerid, 0xFF8040FF, "USAGE: /messagetime [seconds]");
- KillTimer(MessageTimerS);
- TIME_FOR_EACH_MESSAGE = time;
- MessageTimerS = SetTimer("MessageTimer", TIME_FOR_EACH_MESSAGE*1000, true);
- format(string, sizeof(string), "The messages will now display once every %i seconds", TIME_FOR_EACH_MESSAGE);
- SendClientMessage(playerid, 0xFF8040FF, string);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement