10.11.2010, 14:29
(
Последний раз редактировалось Lenny the Cup; 10.11.2010 в 15:01.
)
Hi,
I realized MOTDs have never been part of any SA-MP server I've heard of, so I decided to script a base. I haven't tried any of this code myself but it compiles and should work properly without any problems.
Requirements
It requires MySQL Plugin R5 by G-sTyLeZzZ.
Configuration
Make sure that the dialog IDs aren't used anywhere. If they are, just change the defines in my script to unused ones. Before you do anything else, look over the (very few) defines to make sure it all fits your needs. If you want to reconfigure this later, you have to do it also via MySQL which is a hassle. Also run the function MTD_SetupTable before using the script, and not more than once. This function sets up the table you're going to be using.
Please note
That this is just a base, you have to create the commands yourself and they will only be shown on your server if you use the callbacks provided.
If you have any requests or bug reports, please post them in this thread
Enjoy!
I realized MOTDs have never been part of any SA-MP server I've heard of, so I decided to script a base. I haven't tried any of this code myself but it compiles and should work properly without any problems.
Requirements
It requires MySQL Plugin R5 by G-sTyLeZzZ.
Configuration
Make sure that the dialog IDs aren't used anywhere. If they are, just change the defines in my script to unused ones. Before you do anything else, look over the (very few) defines to make sure it all fits your needs. If you want to reconfigure this later, you have to do it also via MySQL which is a hassle. Also run the function MTD_SetupTable before using the script, and not more than once. This function sets up the table you're going to be using.
Please note
That this is just a base, you have to create the commands yourself and they will only be shown on your server if you use the callbacks provided.
If you have any requests or bug reports, please post them in this thread

pawn Код:
#define MAX_MOTDS 12 // Maximum amount of MOTDs to store ingame. 12 fills up the dialog list, which looks nice.
#define MAX_MOTD_TITLE 16 // Longest title allowed.
#define MAX_MOTD_TEXT 320 // Longest text allowed.
#define MOTD_DIALOG_EMPTY 1 // A free dialog ID that doesn't have any response.
#define MOTD_DIALOG_LIST 2 // A free dialog ID for the list of recent MOTDs
#define MAX_MOTD_DIALOG (MAX_MOTD_TITLE + MAX_MOTD_TEXT + 70) // Don't change this unless the dialog doesn't display all your text.
enum e_MOTD
{
motd_id,
motd_title[MAX_MOTD_TITLE],
motd_text[MAX_MOTD_TEXT],
motd_author[MAX_PLAYER_NAME],
motd_timestamp[20]
}
new MOTD[MAX_MOTDS][e_MOTD];
stock MOTD_SetupTable()
{
new
szQuery[280];
format(szQuery, 280, "CREATE TABLE `motd` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `title` VARCHAR( %d ) NOT NULL , `text` VARCHAR( %d ) NOT NULL , `author` VARCHAR( 24 ) NOT NULL , `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE = MYISAM", MAX_MOTD_TITLE, MAX_MOTD_TEXT);
mysql_query(szQuery);
}
stock MOTD_Clear()
{
for(new i; i < MAX_MOTDS; i++)
{
MOTD[i][motd_id] = -1;
format(MOTD[i][motd_title], MAX_MOTD_TITLE, "");
format(MOTD[i][motd_text], MAX_MOTD_TEXT, "");
format(MOTD[i][motd_author], MAX_PLAYER_NAME, "");
format(MOTD[i][motd_timestamp], 20, "");
}
}
stock MOTD_Load()
{
MOTD_Clear();
new
szQuery[89];
format(szQuery, 89, "SELECT `id`,`title`,`text`,`author`,`timestamp` FROM `motd` ORDER BY `id` DESC LIMIT %d", MAX_MOTDS);
mysql_query(szQuery);
mysql_store_result();
for(new i; mysql_fetch_row_format(" "); i++)
{
MOTD[i][motd_id] = mysql_fetch_int();
mysql_fetch_field_row(MOTD[i][motd_title], "title");
mysql_fetch_field_row(MOTD[i][motd_text], "text");
mysql_fetch_field_row(MOTD[i][motd_author], "author");
mysql_fetch_field_row(MOTD[i][motd_timestamp], "timestamp");
}
mysql_free_result();
}
stock MOTD_Add(title[], text[], author[])
{
new
szQuery[150];
format(szQuery, 150, "INSERT INTO `motd` (`title`,`text`,`author`) VALUES (`%s`,`%s`,`%s`)", title, text, author);
mysql_query(szQuery);
MOTD_Load();
}
stock MOTD_Show(playerid, motd)
{
new szDialog[MAX_MOTD_DIALOG];
format(szDialog, MAX_MOTD_DIALOG, "MOTD Title: %s\n\nMOTD Text:\n%s\n\nAuthor: %s\nTime: %s", MOTD[motd][motd_title], MOTD[motd][motd_text], MOTD[motd][motd_author], MOTD[motd][motd_timestamp]);
ShowPlayerDialog(playerid, MOTD_DIALOG_EMPTY, DIALOG_STYLE_MSGBOX, "Message of the day", szDialog, "OK", "Remind me");
}
stock MOTD_ListLast(playerid)
{
new
szDialog[(MAX_MOTD_TITLE+2)+1];
for(new i; i < MAX_MOTDS; i++)
{
if(!IsPlayerConnected(playerid) || MOTD[i][motd_id] == -1)
continue;
format(szDialog, (MAX_MOTD_TITLE+2)+1, "%s%s\n", szDialog, MOTD[i][motd_title]);
}
ShowPlayerDialog(playerid, MOTD_DIALOG_LIST, DIALOG_STYLE_LIST, "Last MOTDs", szDialog, "Select", "Cancel");
}
stock MOTD_OnDialogResponse(playerid, dialogid, listitem)
{
if(dialogid == MOTD_DIALOG_LIST)
{
MOTD_Show(playerid, listitem);
return 1;
}
return 0;
}