/say message cuts off
#1

Alrighty then, I have a /say command for admins, but the problem is that when I enter more than 117 characters to the message, it won't appear in the server. This is the command, how can I fix it?

pawn Код:
COMMAND:say(playerid, params[])
{
    if(isPlayerAdmin(playerid) >= 1)
    {
        new message[256];
        if(!sscanf(params, "s[256]", message))
        {
            new adminname[MAX_PLAYER_NAME+1];
            GetPlayerName(playerid, adminname, sizeof(adminname));
            format(message, sizeof(message), "Administrator %s (%d): %s", adminname, playerid, message);
            return SendClientMessageToAll(0xB8860BAA, message);
        }
        else SendClientMessage(playerid, -1, "USAGE: /say <message>");
    }
    else SendClientMessage(playerid, 0xFFFF0000, "ERROR: Insufficient permission!");
    return 1;
}
If possible, I'd like to know how to cut it off to two lines if string is long.
Reply
#2

I found out that it was too long after formatting it so I shortened 'Administrator' to 'Admin' and it works now, but problem is I want it to work no matter what, even cut the string off to two lines. Is that possible?
Reply
#3

Quote:
Originally Posted by arad55
Посмотреть сообщение
I found out that it was too long after formatting it so I shortened 'Administrator' to 'Admin' and it works now, but problem is I want it to work no matter what, even cut the string off to two lines. Is that possible?
hmm u can make it on 2 client messages if it needs larger string (untested)
Reply
#4

Код:
COMMAND:say(playerid, params[])
{
    if(isPlayerAdmin(playerid) >= 1)
    {
        new message[556];
        if(!sscanf(params, "s[556]", message))
        {
            new adminname[MAX_PLAYER_NAME+1];
            GetPlayerName(playerid, adminname, sizeof(adminname));
            format(message, sizeof(message), "Administrator %s (%d): %s", adminname, playerid, message);
            return SendClientMessageToAll(0xB8860BAA, message);
        }
        else SendClientMessage(playerid, -1, "USAGE: /say <message>");
    }
    else SendClientMessage(playerid, 0xFFFF0000, "ERROR: Insufficient permission!");
    return 1;
}
Reply
#5

pawn Код:
COMMAND:say(playerid, params[])
{
    if(!isPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFF0000, "ERROR: Insufficient permission!");
    new message[124];
    if(sscanf(params, "s[124]", message)) return SendClientMessage(playerid, -1, "USAGE: /say <message>");
    new adminname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, adminname, sizeof(adminname));
    if(strlen(message) > 77)
    {
        new fstr[128];
        strmid(fstr, message, 0, 76);
        format(fstr, sizeof(fstr), "Administrator %s (%d): %s", adminname, playerid, fstr);
        format(message, sizeof(message), "%s", message[76]);
        SendClientMessageToAll(0xB8860BAA, fstr);
    }
    else format(message, sizeof(message), "Administrator %s (%d): %s", adminname, playerid, message);
    SendClientMessageToAll(0xB8860BAA, message);
    return 1;
}
Reply
#6

Adding to message will not do anything.
SendClientMessage has a limit, 128 characters.

Also, don't use 256 has the size of message.
Reply
#7

Thanks, anyways I managed to do it by another tutorial by now
Using this stock:

pawn Код:
#define EX_SPLITLENGTH 118


stock SendClientMessageEx(playerid, color, final[])
{
    #pragma unused playerid, color
    new buffer[EX_SPLITLENGTH+5];
    new len = strlen(final);
    if(len>EX_SPLITLENGTH)
    {
        new times = (len/EX_SPLITLENGTH);
        for(new i = 0; i < times+1; i++)
        {
            strdel(buffer, 0, EX_SPLITLENGTH+5);
            if(len-(i*EX_SPLITLENGTH)>EX_SPLITLENGTH)
            {
                strmid(buffer, final, EX_SPLITLENGTH*i, EX_SPLITLENGTH*(i+1));
                format(buffer, sizeof(buffer), "%s ...", buffer);
            }
            else
            {
                strmid(buffer, final, EX_SPLITLENGTH*i, len);
            }
            //SendClientMessage(playerid, color, buffer);
        }
    }
    else
    {
        //SendClientMessage(playerid, color, final);
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)