Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=========================================================================//
- //* Automatic Client Message Sender Filterscript
- //* Version: 4.0
- //* ==========================
- //* UPDATE NOTES 3.0 - 4.0:
- //* ==========================
- //* ADDITIONS/MODIFICATIONS
- //* ==========================
- //* Commands removed (except /nextline), replaced them with a dialog. Type /messages to open the dialog.
- //* Completely dynamic:
- //* Dialog Control Center (DCC)
- //* Lines can be edited in the DCC
- //* Lines can be added/removed in the DCC
- //* The delay between sending messages can be configured in the DCC
- //* You can toggle the "filterscript" in the DCC
- //* The filterscript creates messages.txt automatically
- //* ==========================
- //* FIXES
- //* ==========================
- //* Fixed the filterscript from repeating the same line
- //=========================================================================//
- //* 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
- #define SendDialogMessage(%1,%2,%3) ShowPlayerDialog(%1, 8763, DIALOG_STYLE_MSGBOX, %2, %3, "Ok", "")
- #define MAX_LINES 20 // Available text lines: 19 (1 is used for the timer)
- #define MAX_CHARACTERS 128 // Max characters in a line
- #define MESSAGE_FILE "messages.txt"
- forward MessageTimer();
- new Lines[MAX_LINES+1][MAX_CHARACTERS],
- MessageTime = 1,
- MessageTimerS,
- MaxLines,
- NextLine = 0,
- PreviousLine;
- new pChosenLine[MAX_PLAYERS];
- stock WriteFileLine()
- {
- new cline = 0;
- new File:aFile = fopen(MESSAGE_FILE, io_write);
- while(cline != MaxLines)
- {
- cline++;
- fwrite(aFile, Lines[cline]);
- }
- fclose(aFile);
- return 1;
- }
- stock ReadLines()
- {
- new str[MAX_CHARACTERS],
- dlines,
- File:aFile;
- if(!fexist(MESSAGE_FILE)) // If MESSAGE_FILE doesn't exist
- {
- aFile = fopen(MESSAGE_FILE, io_write); // Creates messages.txt
- fwrite(aFile, "300"); // Sets the time per messages to 5 minutes by default.
- fclose(aFile);
- ReadLines();
- }
- else // If MESSAGE_FILE exists
- {
- aFile = fopen(MESSAGE_FILE, io_read);
- while(fread(aFile, str))
- {
- dlines++;
- format(Lines[dlines], MAX_CHARACTERS,"%s",str);
- }
- MessageTime = strval(Lines[1]);
- MaxLines = dlines;
- fclose(aFile);
- }
- return 1;
- }
- isNumeric(const string[])
- {
- for (new i = 0, j = strlen(string); i < j; i++)
- {
- if (string[i] > '9' || string[i] < '0') return 0;
- }
- return 1;
- }
- stock LinesLeft()
- {
- return MAX_LINES - MaxLines;
- }
- stock MessageStatus()
- {
- new str[180];
- if(MessageTimerS != 0 )
- {
- str = "{FFFFFF}Add new line\nModify existing lines\nChange the message display time\nTurn the messages {FF0000}off";
- }
- else
- {
- str = "{FFFFFF}Add new line\nModify existing lines\nChange the message display time\nTurn the messages {00CD00}on";
- }
- return str;
- }
- public OnFilterScriptInit()
- {
- ReadLines();
- MessageTimerS = SetTimer("MessageTimer", MessageTime*1000, true);
- print("\n--------------------------------------");
- print(" Automatic Client Message sender");
- print(" Version: 4.0");
- print(" Created by: Biesmen");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- KillTimer(MessageTimerS);
- return 1;
- }
- public MessageTimer()
- {
- new rand = random(MaxLines+1);
- if(MaxLines == 1)
- {
- MessageTime = 300;
- SendClientMessageToAll(0xEE7621FF, "This server is using Automated Messages for the first time. Please configure the filterscript by logging in as rcon admin and type /messages");
- print("This server is using Automated Messages for the first time. Please configure the filterscript by entering the game, logging in as rcon admin and type /messages");
- return 1;
- }
- if(NextLine == 0)
- {
- if(rand == 1 || rand == 0) return MessageTimer();
- if(rand == PreviousLine && MaxLines != 2) return MessageTimer();
- }
- else
- {
- rand = NextLine;
- NextLine = 0;
- }
- SendClientMessageToAll(0xFFFFFFAA, Lines[rand]);
- PreviousLine = rand;
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(nextline, 8, cmdtext);
- if(strcmp("/messages", cmdtext, true) == 0)
- {
- if(IsPlayerAdmin(playerid))
- {
- ShowPlayerDialog(playerid, 1994, DIALOG_STYLE_LIST, "Automated Messages - Select your choice", MessageStatus(), "Select", "Exit");
- }
- return 1;
- }
- return 0;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- new LineList[(MAX_LINES+1)*MAX_CHARACTERS],
- str[180];
- if(dialogid == 1994) // /messages will open this dialog
- {
- format(LineList, sizeof LineList, "{FFFFFF}%s\n", Lines[2]);
- if(!response) return 1;
- if(listitem == 0)
- {
- if(LinesLeft() <= 0) { format(str, sizeof str, "{FFFFFF}You have got {CD0000}%i lines{FFFFFF} left!\n{CD0000}Please remove some lines or increase MAX_LINES!", LinesLeft()); }
- else { format(str, sizeof str, "{FFFFFF}You have got {00BFFF}%i lines{FFFFFF} left!\n", LinesLeft()); }
- ShowPlayerDialog(playerid, 1995, DIALOG_STYLE_INPUT, "Automated Messages - Add a new line", str, "Add", "Back");
- }
- if(listitem == 1)
- {
- for(new i = 3; i < MaxLines+1; i++)
- {
- // strins(Lines[i], "\n", 0); // Adding the \n command }
- strcat(LineList, Lines[i]);// } I do believe this isn't a very smart way. However, I think it is the only way. Whenever a new line has been made
- // strdel(Lines[i], 0, 1); // Removing the \n command } it will remove the "\n" command, or else you will see a space before the string when the Timer calls the string.
- }
- ShowPlayerDialog(playerid, 1996, DIALOG_STYLE_LIST, "Automated Messages - Modify existing lines", LineList, "Modify", "Back");
- }
- if(listitem == 2)
- {
- format(str, sizeof str, "{FFFFFF}Modify the message display time. Current interval in seconds: {00BFFF}%d{FFFFFF} seconds", MessageTime);
- ShowPlayerDialog(playerid, 1999, DIALOG_STYLE_INPUT, "Automated Messages - Modify the message display time", str, "Done", "Cancel");
- }
- if(listitem == 3)
- {
- if(MessageTimerS != 0)
- {
- KillTimer(MessageTimerS);
- MessageTimerS = 0;
- SendDialogMessage(playerid, "Automated Messages - Message Timer Status", "{FFFFFF}The Message Timer has been {FF0000}deactivated");
- }
- else
- {
- MessageTimerS = SetTimer("MessageTimer", MessageTime*1000, true);
- SendDialogMessage(playerid, "Automated Messages - Message Timer Status", "{FFFFFF}The Message Timer has been {00CD00}activated");
- }
- }
- }
- if(dialogid == 1995) // Add new line dialog
- {
- if(!response)
- {
- ShowPlayerDialog(playerid, 1994, DIALOG_STYLE_LIST, "Automated Messages - Select your choice", MessageStatus(), "Select", "Exit");
- return 1;
- }
- if(strlen(inputtext) > MAX_CHARACTERS)
- {
- format(str, sizeof str, "{CD0000}ERROR: You have exceeded the amount of max characters. Max characters: {00BFFF}%i\n{FFFFFF}You have got {00BFFF}%i lines{FFFFFF} left!\n", MAX_CHARACTERS, LinesLeft());
- ShowPlayerDialog(playerid, 1995, DIALOG_STYLE_INPUT, "Automated Messages - Add a new line", str, "Add", "Back");
- return 1;
- }
- if(strlen(inputtext) < 1)
- {
- format(str, sizeof str, "{CD0000}ERROR: Please enter at least {00BFFF}1{CD0000} character!\n{FFFFFF}You have got {00BFFF}%i lines{FFFFFF} left!\n", LinesLeft());
- ShowPlayerDialog(playerid, 1995, DIALOG_STYLE_INPUT, "Automated Messages - Add a new line", str, "Add", "Back");
- return 1;
- }
- MaxLines = MaxLines+1;
- format(Lines[MaxLines], MAX_CHARACTERS+4, "%s\r\n", inputtext); //+4 to ignore "\r\n"
- WriteFileLine();
- // strdel(Lines[MaxLines], 0, 2);
- format(str, 40+MAX_CHARACTERS, "{FFFFFF}You created a new line: {FF8040}%s", Lines[MaxLines]);
- SendDialogMessage(playerid, "Automated Messages - New line added", str);
- }
- if(dialogid == 1996) // Modify existing lines dialog
- {
- if(!response)
- {
- ShowPlayerDialog(playerid, 1994, DIALOG_STYLE_LIST, "Automated Messages - Select your choice", MessageStatus(), "Select", "Exit");
- return 1;
- }
- pChosenLine[playerid] = listitem+2;
- ShowPlayerDialog(playerid, 1997, DIALOG_STYLE_LIST, "Automated Messages - Modify Existing Line", "Edit line\nRemove line", "Select", "Back");
- }
- if(dialogid == 1997) // Selected a line to modify
- {
- if(!response)
- {
- ShowPlayerDialog(playerid, 1994, DIALOG_STYLE_LIST, "Automated Messages - Select your choice", MessageStatus(), "Select", "Exit");
- return 1;
- }
- if(listitem == 0) return ShowPlayerDialog(playerid, 1998, DIALOG_STYLE_INPUT, "Automated Messages - Modify a line", "{FFFFFF}Modify the line into:", "Done", "Cancel");
- if(listitem == 1)
- {
- format(str, sizeof str, "%s", Lines[pChosenLine[playerid]]);
- format(Lines[pChosenLine[playerid]], 5, "\r\n"); //I'm basically doing this so strdel won't remove any line after the line that has been removed. I've tried
- strdel(Lines[pChosenLine[playerid]], 0, 5); //to remove "Lines[pChosenLine[playerid]], 0, strlen(Lines[pChosenLine[playerid]])", however it will remove any line after this one.
- WriteFileLine();
- format(str, sizeof str, "{FFFFFF}You have successfully removed the line: {FF8040}%s", str);
- SendDialogMessage(playerid, "Automated Messages - Line removed", str);
- SendClientMessage(playerid, 0xFFC68CFF, "The filterscript is now reloading.");
- KillTimer(MessageTimerS);
- ReadLines();
- MessageTimerS = SetTimer("MessageTimer", MessageTime*1000, true);
- }
- }
- if(dialogid == 1998)
- {
- if(!response)
- {
- ShowPlayerDialog(playerid, 1994, DIALOG_STYLE_LIST, "Automated Messages - Select your choice", MessageStatus(), "Select", "Exit");
- return 1;
- }
- if(strlen(inputtext) > MAX_CHARACTERS)
- {
- format(str, sizeof str, "{CD0000}ERROR: You have exceeded the amount of max characters. Max characters: {00BFFF}%i\n{FFFFFF}Modify the line into:\n", MAX_CHARACTERS);
- ShowPlayerDialog(playerid, 1998, DIALOG_STYLE_INPUT, "Automated Messages - Modify a line", str, "Done", "Cancel");
- return 1;
- }
- if(strlen(inputtext) < 1)
- {
- ShowPlayerDialog(playerid, 1998, DIALOG_STYLE_INPUT, "Automated Messages - Modify a line", "{CD0000}ERROR: Please enter at least {00BFFF}1{CD0000} character!\n{FFFFFF}Modify the line into:", "Done", "Cancel");
- return 1;
- }
- format(Lines[pChosenLine[playerid]], MAX_CHARACTERS+4, "%s\r\n", inputtext);
- WriteFileLine();
- format(str, 40+MAX_CHARACTERS, "{FFFFFF}You have successfully modified the line into: {FF8040}%s", Lines[pChosenLine[playerid]]);
- SendDialogMessage(playerid, "Automated Messages - Line modified", str);
- }
- if(dialogid == 1999)
- {
- if(!response)
- {
- ShowPlayerDialog(playerid, 1994, DIALOG_STYLE_LIST, "Automated Messages - Select your choice", MessageStatus(), "Select", "Exit");
- return 1;
- }
- if(isNumeric(inputtext))
- {
- KillTimer(MessageTimerS);
- MessageTime = strval(inputtext);
- MessageTimerS = SetTimer("MessageTimer", MessageTime*1000, true);
- format(str, sizeof str, "{FFFFFF}The messages will now display once every {00BFFF}%i{FFFFFF} seconds", MessageTime);
- SendDialogMessage(playerid, "Automated Messages - Message Time modified", str);
- format(Lines[1], 11, "%i\r\n", MessageTime);
- WriteFileLine();
- }
- else
- {
- format(str, 180, "{CD0000}ERROR: Only use numbers! \n{FFFFFF}Modify the message display time. Current interval in seconds: {00BFFF}%d{FFFFFF} seconds", MessageTime);
- ShowPlayerDialog(playerid, 1999, DIALOG_STYLE_INPUT, "Automated Messages - Modify the message display time", str, "Done", "Cancel");
- }
- }
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement