SA-MP Forums Archive
What have I done wrong? [sscanf2] - 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: What have I done wrong? [sscanf2] (/showthread.php?tid=454291)



What have I done wrong? [sscanf2] - Hargrave - 28.07.2013

Hey everyone!

I am a newbie scripter and started making a gamemode from scratch yesterday. I have made some commands et cetera and suddenly I found out that I used sscanf and not sscanf2 since someone mentioned it. I just changed to sscanf2 and nothing wrong happened, no warnings or errors in the pawno compiler so I thought everything was okey.

Suddenly I saw on the sa-mp.exe that it said

Quote:

[12:29:50] sscanf warning: 'z' is deprecated, consider using 'S' instead.
[12:29:50] sscanf warning: No default value found.
[12:29:50] sscanf warning: Strings without a length are deprecated, please add a destination size.
[12:52:51] sscanf warning: 'z' is deprecated, consider using 'S' instead.
[12:52:51] sscanf warning: No default value found.
[12:52:51] sscanf warning: Strings without a length are deprecated, please add a destination size.
[12:53:45] sscanf warning: 'z' is deprecated, consider using 'S' instead.
[12:53:45] sscanf warning: No default value found.
[12:53:45] sscanf warning: Strings without a length are deprecated, please add a destination size.

I think I fixed "sscanf warning: 'z' is deprecated, consider using 'S' instead." since I used(CTRL+F) and searched for sscanf and then edited the z to s instead e.g uz to us.

By the way do I have to edit the sscanf text on the commands to sscanf2? Anyone who knows how to solve this problem?

Seems like the S problem is fixed, but I have still got the "sscanf warning: Strings without a length are deprecated, please add a destination size" error


Re: What have I done wrong? [sscanf2] - NotIntegrated - 28.07.2013

The placeholder z would be a string, and you provided us with no code so we can't tell you why you are getting those errors. I'm assuming you forgot to set the string size, maybe this post will help you.

And no, you do not need to change it to sscanf2 in the code.


Re: What have I done wrong? [sscanf2] - Konstantinos - 28.07.2013

You have to include to your mode the sscanf2 but the syntax is sscanf. It finds 'z' instead of 'S' so I'm about to ask you. Do you open your file through pawno.exe or by double clicking on the file?


Re: What have I done wrong? [sscanf2] - Hargrave - 28.07.2013

Quote:
Originally Posted by _Zeus
Посмотреть сообщение
You have to include to your mode the sscanf2 but the syntax is sscanf. It finds 'z' instead of 'S' so I'm about to ask you. Do you open your file through pawno.exe or by double clicking on the file?
Through pawno.exe

This is the codes that seems like using sscanf when I search up sscanf.

pawn Код:
CMD:dance(playerid, params[])
{
    new animid;
    if(sscanf(params, "i", animid)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /dance [1-4]");
    if(animid < 1 || animid > 4) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /dance [1-4]");
    switch(animid)
    {
        case 1: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE1);
        case 2: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE2);
        case 3: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE3);
        case 4: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE4);
    }
    return 1;
}
pawn Код:
CMD:kick(playerid,params[])
{
    new id,name1[MAX_PLAYER_NAME], reason[35],name2[MAX_PLAYER_NAME], string[128];
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY,"You are not authorized to use this command.");
    if(sscanf(params,"us",id,reason)) return SendClientMessage(playerid, COLOR_GREY,"USAGE: /kick [playerid/partofname] [reason]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_GREY,"Invalid player id");
    else
    {
        GetPlayerName(playerid,name1,sizeof(name1));
        GetPlayerName(id,name2,sizeof(name2));
        format(string, sizeof(string),"AdmCmd: %s was kicked by %s, reason: %s",name2,name1,reason);
        SendClientMessageToAll(COLOR_LIGHTRED,string);
        Kick(id);
    }
    return 1;
}
And yes after I use /kick I get the warning (got the warning with z before, but after I changed it to s it got fixed. But still the other warning)

pawn Код:
CMD:goto(playerid, params[])
{
    new ID;
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY,"You are not authorized to use this command");
    else if(sscanf(params, "u", ID)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /goto [partofname/playerid]");
    else if(!IsPlayerConnected(ID)) SendClientMessage(playerid, COLOR_GREY, "Player is not connected.");
    else
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(ID, x, y, z);
        SetPlayerPos(playerid, x+1, y+1, z);
    }
    return 1;
}
pawn Код:
CMD:gethere(playerid,params[])
{
    new targetid, Float:x, Float:y, Float:z;
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY,"You are not authorized to use this command");
    else if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /gethere [playerid/partofname]");
    else if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_GREY, "That player is not connected");
    else
    {
        GetPlayerPos(playerid, x, y, z);
        SetPlayerPos(targetid, x, y+0.5, z+0.5);
    }
    return 1;
}
pawn Код:
CMD:makeadmin(playerid, params[])
{
    new pID, value;
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY, " you are not authorized to use this command!");
    else if (sscanf(params, "ui", pID, value)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /makeadmin [playerid/partofname] [level 1-1338]");
    else if (value < 0 || value > 10) return SendClientMessage(playerid, COLOR_GREY, "Unknown level.");
    else if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY,"Invalid player id");
    else
    {
        new pName[MAX_PLAYER_NAME], tName[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        GetPlayerName(pID, tName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "You have promoted %s to admin level %i", tName, value);
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "You have been promoted to admin level %i by %s", value, pName);
        SendClientMessage(pID, COLOR_LIGHTRED, string);
        PlayerInfo[pID][pAdmin] = value;
    }
    return 1;
}
pawn Код:
CMD:mute(playerid,params[])
{
    new id,time,name1[MAX_PLAYER_NAME],reason[35],name2[MAX_PLAYER_NAME], string[128];
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY,"You are not authorized to use this command.");
    if(sscanf(params,"uis", id, time, reason)) return SendClientMessage(playerid, COLOR_GREY,"USAGE: /mute [playerid/partofname] [minutes] [reason]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_GREY,"Invalid player id");
    else
    {
        PlayerInfo[id][pMuted] = 1;
        PlayerInfo[id][pMuteTime] = time*60;
        GetPlayerName(playerid,name1,sizeof(name1));
        GetPlayerName(id,name2,sizeof(name2));
        format(string, sizeof(string), "AdmCmd: %s was silenced by %s for %d minute(s), reason: %s",name2 ,name1,time,reason);
        SendClientMessageToAll(COLOR_LIGHTRED,string);
    }
    return 1;
}
pawn Код:
CMD:warn(playerid, params[])
{
    new id, sendername[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], reason[35], string[128];
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY,"You are not authorized to use this command.");
    if(sscanf(params,"us",id,reason)) return SendClientMessage(playerid, COLOR_GREY,"Usage: /warn [playerid/partofname] [reason]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_GREY,"Invalid player id");
    else
    {
        if(PlayerInfo[id][pWarns] >= 10)
        {
            format(string, sizeof(string), "AdmCmd: %s was banned by %s (10 warnings) reason %s", name, sendername, reason);
            SendClientMessageToAll(COLOR_LIGHTRED, string);
            new plrIP[16];
            GetPlayerIp(id,plrIP, sizeof(plrIP));
            SendClientMessage(id,COLOR_LIGHTBLUE,"|___________[BAN INFO]___________|");
            format(string, sizeof(string), "Your name: %s.",name);
            SendClientMessage(id, COLOR_WHITE, string);
            format(string, sizeof(string), "Your ip is: %s.",plrIP);
            SendClientMessage(id, COLOR_WHITE, string);
            format(string, sizeof(string), "You were banned by: %s.",sendername);
            SendClientMessage(id, COLOR_WHITE, string);
            format(string, sizeof(string), "You were banned for: %s.",reason);
            SendClientMessage(id, COLOR_WHITE, string);
            SendClientMessage(id,COLOR_LIGHTBLUE,"|___________[BAN INFO]___________|");
            Ban(id);
        }
        PlayerInfo[id][pWarns] += 1;
        GetPlayerName(playerid, sendername, sizeof(sendername));
        sendername[strfind(sendername,"_")] = ' ';
        GetPlayerName(id, name, sizeof(name));
        format(string, sizeof(string), "You were warned by %s, reason: %s", sendername, reason);
        SendClientMessage(id, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "AdmCmd: %s was warned by %s, reason %s", name, sendername, reason);
        SendClientMessageToAll(COLOR_LIGHTRED,string);
    }
    return 1;
}



Re: What have I done wrong? [sscanf2] - Konstantinos - 28.07.2013

Just remember that whenever you're using 's' specifier, you need to use the lenght as well.

For example:
pawn Код:
if(sscanf(params,"us",id,reason))
becomes:
pawn Код:
if(sscanf(params,"us[35]",id,reason))



Re: What have I done wrong? [sscanf2] - NotIntegrated - 28.07.2013

You need to assign a length to "s", since it is a string.
Код:
if(sscanf(params,"us[128]",id,reason))
Edit: He beat me to it.


Re: What have I done wrong? [sscanf2] - Hargrave - 28.07.2013

Quote:
Originally Posted by NotIntegrated
Посмотреть сообщение
You need to assign a length to "s", since it is a string.
Код:
if(sscanf(params,"us[128]",id,reason))
Edit: He beat me to it.
Oh thank you, but anyways on the lenght on for example kick, what does it do with the command if I for example set the lenght as 1?


Re: What have I done wrong? [sscanf2] - Konstantinos - 28.07.2013

Quote:
Originally Posted by Hargrave
Посмотреть сообщение
Oh thank you, but anyways on the lenght on for example kick, what does it do with the command if I for example set the lenght as 1?
Why do you want to do that? The reason will store the size you gave and if you exceed that lenght, another warning will come up: sscanf warning: String buffer overflow


Re: What have I done wrong? [sscanf2] - Hargrave - 28.07.2013

Quote:
Originally Posted by _Zeus
Посмотреть сообщение
Why do you want to do that? The reason will store the size you gave and if you exceed that lenght, another warning will come up: sscanf warning: String buffer overflow
Oh so I may just write in e.g 128 and if I not sue more than 128 characters, it won't give warning. So it is better using higher lenght instead of short lenght?

And that is just if s is there? or what since I have another one with just "u" shall I add anything to it? Like lenght?


Re: What have I done wrong? [sscanf2] - Konstantinos - 28.07.2013

Quote:
Originally Posted by Hargrave
Посмотреть сообщение
Oh so I may just write in e.g 128 and if I not sue more than 128 characters, it won't give warning. So it is better using higher lenght instead of short lenght?

And that is just if s is there? or what since I have another one with just "u" shall I add anything to it? Like lenght?
Well, I use 64 lenght for reasons and I have no problem so far. It's your decision though.

No, you don't need to. Only on 's', use lenght and on arrays the size. More details can be found on the original thread of Sscanf.