SA-MP Forums Archive
problem with sscanf optionaler parameter - 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: problem with sscanf optionaler parameter (/showthread.php?tid=494805)



problem with sscanf optionaler parameter - WhiteKinG - 14.02.2014

I have a problem,
he does not printet all.

server_log.txt:
PHP код:
1
2
3

My Code:
PHP код:
ocmd:stats(playerid,params[])
{
    new 
pID;
    print(
"1");
    if(
sscanf(params,"U(-1)",pID)) SCM(playerid,grau,"Admin: /stats [playerid/name]."), print("1.5");
    print(
"2");
    if(
pID==-1pID=playerid;
    print(
"3");
    new 
str[300];
    print(
"4");
        
format(str,sizeof(str),"Level: %d            Money: %d\n",Player[pID][Level],Player[pID][Money]);
    print(
"5");
    
printf("%s \nlength: %d",str,strlen(str));
    print(
"6");
    
ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"caption",str,"OK","");
    print(
"end");




Re: problem with sscanf optionaler parameter - Blademaster680 - 14.02.2014

What exactly are you trying to do?


AW: problem with sscanf optionaler parameter - WhiteKinG - 14.02.2014

if i typing ingame /stats then come a dialog with my playerid,
but if i typing ingame /stats anothername then come a dialog with his name.

i hope you understand what i mean.
english


Re: problem with sscanf optionaler parameter - CuervO - 14.02.2014

It might be because the optional parameter is never set (hence why 1.5 is not printed) and why it fails after the fourth check, since it would be trying to access the array at -1.
I don't really know if U (userid) can be set to -1 as default, try 65535 (INVALID_PLAYER_ID)

Are you sure you have the sscanf plugin? Update the plugin and the includes itself.


Re: problem with sscanf optionaler parameter - Konstantinos - 14.02.2014

pawn Код:
ocmd:stats(playerid,params[])
{
    new pID;
    if(!sscanf(params,"r",pID))
    {
        if (!IsPlayerConnected(pID)) return SCM(playerid,grau,"Invalid player.");
        new str[64];
        format(str,sizeof(str),"Level: %d            Money: %d\n",Player[pID][Level],Player[pID][Money]);
        ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"caption",str,"OK","");
    }
    else
    {
        if (!strlen(params))
        {
            new str[64];
            format(str,sizeof(str),"Level: %d            Money: %d\n",Player[playerid][Level],Player[playerid][Money]);
            ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"caption",str,"OK","");
        }
        else SCM(playerid,grau,"Admin: /stats [playerid/name].")
    }
    return 1;
}