Issue with server MOTD not loading/showing
#1

I created a /motd you can set, and it will display when players connect. But some some reason, it writes to the server file correctly - but doesn't show for players. Only "MOTD" shows, and not the saved string. I'm not sure if I need to parse the file, or what. And if I do - would it go under onplayerconnect, and what would the .extra parameter be?


pawn Код:
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]);
Reply
#2

Use this on OnPlayerConnect.

PHP код:
new string[128];
format(string,sizeof(string), "[Server MOTD]: {FFFFFF}%s"ServerInfo[sMOTD]);
SCM(pid,COLOR_LIGHTGREENstring); 
Always use format if you got what ever like, number(%d), chars(%s) etc
Reply
#3

Simply simple as simply using simple things, simply created with simple code.

pawn Код:
// 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;
}






Reply
#4

Quote:
Originally Posted by Meller
Посмотреть сообщение
Use this on OnPlayerConnect.

PHP код:
new string[128];
format(string,sizeof(string), "[Server MOTD]: {FFFFFF}%s"ServerInfo[sMOTD]);
SCM(pid,COLOR_LIGHTGREENstring); 
Always use format if you got what ever like, number(%d), chars(%s) etc
Simple mistake is a simple mistake. Thought I could make it work with a SCM. Thank you. And would parsing the file be necessary?
Reply
#5

Quote:
Originally Posted by rangerxxll
Посмотреть сообщение
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.
Reply
#6

Quote:
Originally Posted by Kevln
Посмотреть сообщение
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.
I try one solution at a time, and if they don't work, I move on to the next post. I'm not ignoring you bud. I'm reading over your post now.
Reply
#7

Kevln, No offence but, The most people take the first response slash their script but an update.
Anyways, You're welcome rangerxxll.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)