problem with sscanf optionaler parameter
#1

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");

Reply
#2

What exactly are you trying to do?
Reply
#3

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
Reply
#4

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.
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)