SA-MP Forums Archive
sscanf problem - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: sscanf problem (/showthread.php?tid=242051)



sscanf problem - legodude - 19.03.2011

pawn Код:
dcmd_setcmdlevel(playerid,params[]) {
    if(PlayerInfo[playerid][Level] >= CheckLevel("setcmdlevel"))
    {
        new cmdname[30],str[128],lvl;
        if(sscanf(params,"s[30]i",cmdname,lvl))
        {
            SendClientMessage(playerid, red, "USAGE: /setcmdlevel [command] [level]");
            return 1;
        }
        else if(CommandExist(cmdname))
        {
            for(new i;i<217;i++)
            {
                if(YHash(cmdname, false)==Cmds[i][Unique])
                {
                    Cmds[i][Level]=lvl;
                }
            }
            format(str,sizeof(str),"The required level from %s is set to %i",cmdname,lvl);
            SendClientMessage(playerid,blue,str);
            return 1;
        }
        else
        {
            format(str,sizeof(str),"Command %s is not found",cmdname);
            SendClientMessage(playerid,blue,str);
            return 1;
        }
    } else LevelError(playerid,"setcmdlevel");
    return 1;
}
when i follow the right syntax it says unknown command. but when i dont follow the syntax it says the error speciefied in the sendclientmessage. help please? it acts not the way it must act


Re: sscanf problem - Biesmen - 19.03.2011

Try this:

pawn Код:
dcmd_setcmdlevel(playerid, params[]
{
    if(PlayerInfo[playerid][Level] >= CheckLevel("setcmdlevel"))
    {
        new cmdname[30], str[128], lvl;
        if(sscanf(params, "s[30]i", cmdname, lvl)) return SendClientMessage(playerid, red, "USAGE: / setcmdlevel [command] [level]");
       
        if(CommandExist(cmdname))
        {
            for(new i;i<217;i++)
            {
                if(YHash(cmdname, false)==Cmds[i][Unique])
                {
                    Cmds[i][Level]=lvl;
                }
            }
            format(str,sizeof(str),"The required level from %s is set to %i",cmdname,lvl);
            SendClientMessage(playerid,blue,str);
        } else {
            format(str,sizeof(str),"Command %s is not found",cmdname);
            SendClientMessage(playerid,blue,str);
            return 1;
        }
    } else return LevelError(playerid,"setcmdlevel");
return 1;
}