Sscanf warning: Strings without a length are deprecated, please add a destination size.
#1

Hello guys, so i'm not good at sscanf, and can't figure out what i've done wrong. But whenever i make a pm, i get this error in my server log: scanf warning: Strings without a length are deprecated, please add a destination size.
Well I do know that i need to add a string some where, but where exactly?

Could anyone help? Thanks.

Code:

PHP код:
CMD:pm(playeridparams[])
{
    new 
pIDtext[210], string[230];
    if(
sscanf(params"us"pIDtext)) return SendClientMessage(playeridERROR_COLOR"USAGE: /pm (nick/id) (message) - Enter a valid Nick / ID");
    if(!
IsPlayerConnected(pID)) return SendClientMessage(playeridERROR_COLOR"Player is not connected.");
    if(
pID == playerid) return SendClientMessage(playeridERROR_COLOR"You cannot PM yourself.");
    
format(stringsizeof(string), "%s (%d) is not accepting private messages at the moment."GetName(pID), pID);
    if(
PlayerInfo[pID][NoPM] == 1) return SendClientMessage(playeridERROR_COLORstring);
    
format(stringsizeof(string), "PM to %s: %s"GetName(pID), text);
    
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
    
format(stringsizeof(string), "PM from %s: %s"GetName(playerid), text);
    
SendClientMessage(pIDCOLOR_LIGHTBLUEstring);
    
PlayerInfo[pID][Last] = playerid;
    return 
1;
}
CMD:r(playeridparams[])
{
    new 
text[128], string[128];
    if(
sscanf(params"s"text)) return SendClientMessage(playeridERROR_COLOR"USAGE: /r (message) - Enter your message");
    new 
pID PlayerInfo[playerid][Last];
    if(!
IsPlayerConnected(pID)) return SendClientMessage(playeridERROR_COLOR"Player is not connected.");
    if(
pID == playerid) return SendClientMessage(playeridERROR_COLOR"You cannot PM yourself.");
    
format(stringsizeof(string), "%s (%d) is not accepting private messages at the moment."GetName(pID), pID);
    if(
PlayerInfo[pID][NoPM] == 1) return SendClientMessage(playeridERROR_COLORstring);
    
format(stringsizeof(string), "PM to %s: %s"GetName(pID), text);
    
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
    
format(stringsizeof(string), "PM from %s: %s"GetName(playerid), text);
    
SendClientMessage(pIDCOLOR_LIGHTBLUEstring);
    
PlayerInfo[pID][Last] = playerid;
    return 
1;

Reply
#2

For strings in sscanf, you should add the lenght in square brackets after "s" specifier. For example:
pawn Код:
if(sscanf(params, "us[100]", pID, text))
You don't need sscanf at the command /r since it uses only one parameter and that's string. You can use isnull to return the usage and params as "text".
Reply
#3

if(sscanf(params, "us[210]", pID, text))
Same principle for the other/s.

NOTE: I just used 210 because you did, but that's not necessary.
Reply
#4

pawn Код:
CMD:pm(playerid, params[])
{
    new pID, text[210], string[230],string2[250],string3[250];
    if(sscanf(params, "us[110]", pID, text)) return SendClientMessage(playerid, ERROR_COLOR, "USAGE: /pm (nick/id) (message) - Enter a valid Nick / ID");
    if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, ERROR_COLOR, "Player is not connected.");
    if(pID == playerid) return SendClientMessage(playerid, ERROR_COLOR, "You cannot PM yourself.");
    format(string, sizeof(string), "%s (%d) is not accepting private messages at the moment.", GetName(pID), pID);
    if(PlayerInfo[pID][NoPM] == 1) return SendClientMessage(playerid, ERROR_COLOR, string);
    format(string2, sizeof(string2), "PM to %s: %s", GetName(pID), text);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string2);
    format(string3, sizeof(string3), "PM from %s: %s", GetName(playerid), text);
    SendClientMessage(pID, COLOR_LIGHTBLUE, string3);
    PlayerInfo[pID][Last] = playerid;
    return 1;
}
CMD:r(playerid, params[])
{
    new text[128], string[128],string2[128],string3[128];
    if(sscanf(params, "us[110]", text)) return SendClientMessage(playerid, ERROR_COLOR, "USAGE: /r (message) - Enter your message");
    new pID = PlayerInfo[playerid][Last];
    if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, ERROR_COLOR, "Player is not connected.");
    if(pID == playerid) return SendClientMessage(playerid, ERROR_COLOR, "You cannot PM yourself.");
    format(string, sizeof(string), "%s (%d) is not accepting private messages at the moment.", GetName(pID), pID);
    if(PlayerInfo[pID][NoPM] == 1) return SendClientMessage(playerid, ERROR_COLOR, string);
    format(string2, sizeof(string2), "PM to %s: %s", GetName(pID), text);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string2);
    format(string3, sizeof(string3), "PM from %s: %s", GetName(playerid), text);
    SendClientMessage(pID, COLOR_LIGHTBLUE, string3);
    PlayerInfo[pID][Last] = playerid;
    return 1;
}
Reply
#5

Thank you very much guys, really apperciated!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)