SA-MP Forums Archive
SSCANF warning. - 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)
+--- Thread: SSCANF warning. (/showthread.php?tid=427561)



SSCANF warning. - lean1337 - 02.04.2013

Hello, this is giving me : sscanf warning: Strings without a length are deprecated, please add a destination size.

pawn Код:
LEANCMD:(createacc)
    {
        new
            sP[MAX_PLAYER_NAME + 1],
            sV[34 + 1],
            fString[256];
           
           
        if(!(PlayerInfo[playerid][pAdmin] >= 3)) return SCM(playerid, COLOR_GREY,"You are not authorized to use this command");
        if(sscanf(params, "s", sP)) return SendClientMessage(playerid, -1, "USAGE: /createacc [NAME_SURNAME]");
        if(strlen(sP) < 3 || strlen(sV) > MAX_PLAYER_NAME) return SendClientMessage(playerid, -1, "ERROR: Invalid name lenghth");
        new sendername[MAX_PLAYER_NAME], string[256];
        GetPlayerName(playerid, sendername, sizeof(sendername));
        format(fString, sizeof fString, "Users/%s.ini", sP);
        new INI:File = INI_Open(fString);
        INI_SetTag(File, "data");
        INI_WriteInt(File,"Password",udb_hash("changeit"));
        INI_WriteInt(File, "Cash", 0);
        INI_WriteInt(File, "Admin", 0);
        INI_WriteInt(File, "Kills", 1);
        INI_WriteInt(File, "Deaths", 1);
        INI_WriteInt(File, "Skin", 266);
        INI_WriteInt(File, "Logs", 1);
        INI_WriteInt(File, "Banned", 0);
        INI_WriteInt(File, "Crim", 0);
        INI_WriteInt(File, "Pw", 0);
        INI_Close(File);

        SendClientMessage(playerid, -1, "Account created!");
        format(string,sizeof(string), "AdmWarn: Admin[%i] %s has created an account with the name: %s",PlayerInfo[playerid][pAdmin], sendername, sP);
        SendAdminMessage(COLOR_YELLOW, string);
        format(string,sizeof(string),"[%d-%d-%d] AdmWarn: Admin[%i] %s has created an account with the name: %s",GetDay(),GetMonth(),GetYear(),PlayerInfo[playerid][pAdmin],sendername, sP);
        Log("/logs/Accounts.txt",string);
        return 1;
    }

I tryed with this if(sscanf(params, "s[37]", sP)) return SendClientMessage(playerid, -1, "USAGE: /createacc [NAME_SURNAME]");

but then when I do /createacc Test_Test it gives me an error

The command works fine but I want to get rid of the warning.


Re: SSCANF warning. - iggy1 - 02.04.2013

Quote:
Originally Posted by lean1337
Посмотреть сообщение
I tryed with this if(sscanf(params, "s[37]", sP)) return SendClientMessage(playerid, -1, "USAGE: /createacc [NAME_SURNAME]");

but then when I do /createacc Test_Test it gives me an error
Please post the error, because that is the correct way to declare a size for the string.


Re: SSCANF warning. - lean1337 - 02.04.2013

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Please post the error, because that is the correct way to declare a size for the string.
I mean, its giving me an error in game, unknown command. The command is not recognized.


Re: SSCANF warning. - Hanger - 02.04.2013

You must declare the size of the array where you will store the string!
I am not sure, but you cannot use -1 colour param. in SendClientMessage
Код:
// MAX_PLAYER_NAME = 24 + 1 = 25
if(sscanf(params, "s[25]", sP)) return SendClientMessage(playerid, 0x00000000, "USAGE: /createacc [NAME_SURNAME]");
Edit:
Also You copy much:
Код:
if(strlen(sP) < 3 || strlen(sV) > MAX_PLAYER_NAME) // sP ???



Re: SSCANF warning. - lean1337 - 02.04.2013

Quote:
Originally Posted by Hanger
Посмотреть сообщение
You must declare the size of the array where you will store the string!
I am not sure, but you cannot use -1 colour param. in SendClientMessage
Код:
// MAX_PLAYER_NAME = 24 + 1 = 25
if(sscanf(params, "s[25]", sP)) return SendClientMessage(playerid, 0x00000000, "USAGE: /createacc [NAME_SURNAME]");
Edit:
Also You copy much:
Код:
if(strlen(sP) < 3 || strlen(sV) > MAX_PLAYER_NAME) // sP ???
Some guy made the command for me a while ago. Also you can use -1 in SendClientMessage. Anyway, im gonna try 25 when i get home from school.


Re: SSCANF warning. - Konstantinos - 02.04.2013

Quote:
Originally Posted by Hanger
Посмотреть сообщение
you cannot use -1 colour param. in SendClientMessage
-1 is defined as 0xFFFFFFFF.

It should be:
pawn Код:
new
    sP[ 24 ]
;
if(sscanf(params, "s[24]", sP)) return SendClientMessage( .. );
// rest
Change string's lenght to 128 from 256 and fString's lenght to 64 from 256 as well. Too much waste!


Re: SSCANF warning. - lean1337 - 02.04.2013

Quote:
Originally Posted by Dwane
Посмотреть сообщение
-1 is defined as 0xFFFFFFFF.

It should be:
pawn Код:
new
    sP[ 24 ]
;
if(sscanf(params, "s[24]", sP)) return SendClientMessage( .. );
// rest
Change string's lenght to 128 from 256 and fString's lenght to 64 from 256 as well. Too much waste!
Thanks, works.