Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=========================================================================//
- //* Automatic Client Message Sender Filterscript
- //* Version: 3.0
- //=========================================================================//
- //* Created by:
- //* Biesmen
- // http://forum.sa-mp.com/member.php?u=52068
- //=========================================================================//
- #include <a_samp>
- #include <sscanf2> // SSCANF by Y_Less
- #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
- forward MessageTimer();
- new Lines[20][256],
- MessageTime = 1,
- MessageTimerS,
- MaxLines,
- NextLine;
- stock WriteFileLine()
- {
- new cline = 0;
- new File:name = fopen("messages.txt", io_write);
- while(cline != MaxLines)
- {
- cline++;
- fwrite(name, Lines[cline]);
- }
- fclose(name);
- return 1;
- }
- stock ReadLines()
- {
- new str[256], dlines = 0;
- new File:Messages = fopen("messages.txt", io_read);
- while(fread(Messages, str, sizeof(str)))
- {
- dlines++;
- format(Lines[dlines],256,"%s",str);
- }
- MessageTime = strval(Lines[1]);
- MaxLines = dlines;
- fclose(Messages);
- return 1;
- }
- ////////////////////////////////
- // Created by Ryder` //
- ///////////////////////////////
- stock ColouredText(text[])
- {
- new
- pos = -1,
- string[(128 + 16)]
- ;
- strmid(string, text, 0, 128, (sizeof(string) - 16));
- while((pos = strfind(string, "#", true, (pos + 1))) != -1)
- {
- new
- i = (pos + 1),
- hexCount
- ;
- for( ; ((string[i] != 0) && (hexCount < 6)); ++i, ++hexCount)
- {
- if(!(('a' <= string[i] <= 'f') || ('A' <= string[i] <= 'F') || ('0' <= string[i] <= '9')))
- {
- break;
- }
- }
- if((hexCount == 6) && !(hexCount < 6))
- {
- string[pos] = '{';
- strins(string, "}", i);
- }
- }
- return string;
- }
- ////////////////////////////////
- public OnFilterScriptInit()
- {
- ReadLines();
- MessageTimerS = SetTimer("MessageTimer", MessageTime*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;
- if(NextLine == 0)
- {
- rand = random(MaxLines);
- if(strlen(Lines[rand]) == 0) return MessageTimer();
- if(strcmp(Lines[rand], Lines[1], true) == 0) return MessageTimer();
- }
- else
- {
- rand = NextLine;
- NextLine = 0;
- }
- SendClientMessageToAll(0xFFFFFFAA, Lines[rand]);
- printf("%s", Lines[rand]);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(nextline, 8, 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", MessageTime*1000, true);
- SendClientMessage(playerid, 0xFF8040FF, "The Message Timer has been activated.");
- }
- }
- return 1;
- }
- return 0;
- }
- dcmd_nextline(playerid, params[])
- {
- new line, str[128];
- if(IsPlayerAdmin(playerid))
- {
- if(sscanf(params, "i", line)) return SendClientMessage(playerid, 0xFF8040FF, "USAGE: /nextline [line]");
- if(line > MaxLines-1 || line < 1) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: This line doesn't exist!");
- NextLine = line+1;
- format(str, sizeof(str), "Next line to be announced is Line %i", line);
- SendClientMessage(playerid, 0xFFC68CFF, str);
- }
- return 1;
- }
- dcmd_setline(playerid, params[])
- {
- 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 > MaxLines-1 || line < 1) return SendClientMessage(playerid, 0xFF8040FF, "ERROR: This line doesn't exist!");
- message = ColouredText(message);
- format(Lines[line+1], 256, "%s\r\n", message);
- WriteFileLine();
- 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);
- MessageTime = time;
- MessageTimerS = SetTimer("MessageTimer", MessageTime*1000, true);
- format(string, sizeof(string), "The messages will now display once every %i seconds", MessageTime);
- SendClientMessage(playerid, 0xFF8040FF, string);
- format(Lines[1], 256, "%i\r\n", time);
- WriteFileLine();
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement