SA-MP Forums Archive
sscanf / dcmd help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: sscanf / dcmd help (/showthread.php?tid=222422)



sscanf / dcmd help - Unknown123 - 07.02.2011

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.



Re: sscanf / dcmd help - Hiddos - 07.02.2011

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

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



Re: sscanf / dcmd help - Unknown123 - 07.02.2011

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



Re: sscanf / dcmd help - HyperZ - 07.02.2011

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;
}



Re: sscanf / dcmd help - Unknown123 - 07.02.2011

ok, Thanks