sscanf / dcmd help
#1

This is my code

pawn Код:
dcmd_cm(playerid, params[])
{
    if(gTeam[playerid] == TEAM_COPP)
    {
        new message[128];
        if(sscanf(params, "s", message)) SendClientMessage(playerid, COLOR_USAGE, "USAGE: /cm (message)");

        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i) && gTeam[playerid] == TEAM_COP)
            {
                new playername[MAX_PLAYER_NAME], string[128];
                GetPlayerName(i, playername, sizeof(playername));

                format(string, sizeof(string), "cop radio: %s(%d) %s", playername, i, message);
                SendClientMessage(i, COLOR_TEAMCHAT, string);

                format(string, sizeof(string), "cop radio: %s(%d) %s", playername, i, message);
                printf("%s", string);
                return 1;
            }
        }
        return 1;
    }
    return 0;
}
And this is my warning.
Код:
sscanf warning: Strings without a length are deprecated, please add a destination size.
Reply
#2

In the plugin version, you need to post the amount of cells in a string, so:

pawn Код:
if(sscanf(params, "s[128]", message))
Reply
#3

ohh thanks,

pawn Код:
new message;
if(sscanf(params, "s[128]", message)) SendClientMessage(playerid, COLOR_USAGE, "USAGE: /cm (message)");
But there is another problem now

if i type "/cm" i get this
USAGE: /cm (message)
cop radio: Unknown(0)


and if i type "/cm Hi There." i get this
cop radio: Unknown(0) Hi There.
SERVER: Unknown Command
Reply
#4

Fixed:
pawn Код:
dcmd_cm(playerid, params[])
{
    if(gTeam[playerid] == TEAM_COPP)
    {
        new message[128];
        if(sscanf(params, "s[128]", message)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: /cm (message)");

        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i) && gTeam[playerid] == TEAM_COP)
            {
                new playername[MAX_PLAYER_NAME], string[128];
                GetPlayerName(i, playername, sizeof(playername));

                format(string, sizeof(string), "cop radio: %s(%d) %s", playername, i, message);
                SendClientMessage(i, COLOR_TEAMCHAT, string);

                format(string, sizeof(string), "cop radio: %s(%d) %s", playername, i, message);
                printf("%s", string);
            }
        }
        return 1;
    }
    return 0;
}
Reply
#5

ok, Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)