CMD:motd(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 4) return SCM(pid, COLOR_GREY, ERROR);
new string[128], message[128];
if(sscanf(params,"s[128]", message)) return SCM(pid,COLOR_WHITE, "USAGE: /motd [message]");
format(string,sizeof(string), "[Server MOTD]: {FFFFFF}%s", message);
ServerInfo[sMOTD] = string;
new INI:file = INI_Open("Server/server.ini");
INI_SetTag(file, "data");
INI_WriteString(file, "MOTD", string);
INI_Close(file);
SCM(pid,COLOR_GREEN, "You have successfully set the message of the day.");
return 1;
}
//Sending MOTD under onplayerconnect
if(strlen(ServerInfo[sMOTD]) == 0) return SCM(pid,COLOR_GREY, "No MOTD has been set.");
SCM(pid,COLOR_LIGHTGREEN, ServerInfo[sMOTD]);
new string[128];
format(string,sizeof(string), "[Server MOTD]: {FFFFFF}%s", ServerInfo[sMOTD]);
SCM(pid,COLOR_LIGHTGREEN, string);
// DEVELOPMENT SCRIPT
// ** INCLUDES
#include <a_samp>
#include <zcmd>
// ** DEFINES
// *** GENERAL
#define MOTD_PATH "motd.ini"
// *** FUNCTIONS
#define function%0(%1) forward%0(%1); public%0(%1)
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
// *** DIALOGS
#define DIALOG_SET_MOTD 0
// ** MAIN
main()
{
print("Loaded \"motd.amx\".");
}
// ** CALLBACKS:
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
new string[144];
GetINIString(MOTD_PATH, string);
if(isnull(string))
{
SendClientMessage(playerid, -1, "MOTD: No message of the day has been set yet.");
}
else
{
new message[160];
format(message, sizeof(message), "MOTD: %s", string);
SendClientMessage(playerid, -1, message);
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_SET_MOTD:
{
if(!response) return 1;
else if(response)
{
WriteNIString(MOTD_PATH, inputtext);
SendClientMessage(playerid, -1, "You have successfully set the message of the day.");
}
}
}
return 1;
}
// ** COMMANDS
CMD:setmotd(playerid, params[])
{
new string[144];
format(string, sizeof(string), "Please enter the new message of the day below.");
ShowPlayerDialog(playerid, DIALOG_SET_MOTD, DIALOG_STYLE_INPUT, "{FF00FF}Message of the Day", string, "Submit", "Close");
return 1;
}
// ** FUNCTIONS
function GetINIString(file[], result[])
{
new File:inifile, line[512];
inifile = fopen(file, io_read);
if(!inifile)
{
printf("Fatal Error: Couldn't open \"%s\"!", file);
return 0;
}
while(fread(inifile, line)) format(result, sizeof(line), "%s", line);
fclose(inifile);
return 0;
}
function WriteNIString(file[], string[])
{
new File:inifile;
inifile = fopen(file, io_write);
if(!inifile)
{
printf("Fatal Error: Couldn't open \"%s\"!", file);
return 0;
}
fwrite(inifile, string);
fclose(inifile);
return 0;
}
Use this on OnPlayerConnect.
PHP код:
|
Simple mistake is a simple mistake. Thought I could make it work with a SCM. Thank you. And would parsing the file be necessary?
|
Thank you for ignoring me, I appreciate it!
You clearly don't need to save whatever is in the file in to a variable, just get the content to show directly from the file when a player joins and show it to them. Also supports manual editions. Take the code I posted previously as an example & a reference. |