Multi parameter command question
#1

Hello, I have been working on a command that consists of multi parameters my concern is if I can store an integer inside a string or use something else, I am kind of confused about it so i'd appreciate if you could tell me if I use strcmp or something else to check if a player wrote that integer.

Here is my code
pawn Код:
CMD:fedit(playerid,params[]) //This is the family edit command
{
    new ranks[10], motd[50], option[10];
    if(pInfo[playerid][USER_FACTION] < 1 && pInfo[playerid][USER_FACTIONRANK] < 10)
    {
        SendClientMessage(playerid, -1, "You have no permission to use this command.");
        return 1;
    }
    if(pInfo[playerid][USER_FACTION] > 0 && pInfo[playerid][USER_FACTIONRANK] == 10)
    {
        if(sscanf(params, "s[10]", option))
        {
            SendClientMessage(playerid, -1, "[USAGE]: /fedit (facname | rank (1-10) | motd)");
            return 1;
        }
        if(!strcmp(option, "facname", true))
        {
            new Query[256], string[256], factionname[50];
            format(factionname, 50, "%s", params);
            if(strlen(factionname) <= 50)
            {
                fInfo[pInfo[playerid][USER_FACTION]][FNAME] = factionname;
                format(Query, sizeof(Query), "UPDATE factioninfo SET fname = '%s' WHERE fid = %d", fInfo[pInfo[playerid][USER_FACTION]][FNAME], fInfo[pInfo[playerid][USER_FACTION]][FID]);
                db_query(FDatabase, Query);
                format(string, sizeof(string), "You have changed the faction name to %s.", fInfo[pInfo[playerid][USER_FACTION]][FNAME]);
                SendClientMessage(playerid, -1, string);
                return 1;
            }
        }
        if(!strcmp(option, "rank", true))
        {
            new Query[256], string[256], rankname[10], rank;
            if(sscanf(params, "ds[50]", rank, rankname))
            {
                SendClientMessage(playerid, -1, "[USAGE]: /fedit rank (rank number) (rank name)."
                return 1;
            }
            format(rankname, 10, "%s", params);
            if(!strcmp(rank, "1", true)) // this is the line I am confused on.
            {
           
    }
    return 1;
}
Reply
#2

You used 'd' in sscanf, it will be converted to in integer therefore you only need to do "rank == 1"

Also your code wont work like that because if you do "if(sscanf(params, "s[10]", option))"
It will put the whole string into options, no matter if there is a space behind (last 's' gets the remaining string)

pawn Код:
MD:fedit(playerid,params[]) {
    if(pInfo[playerid][USER_FACTION] < 1 || pInfo[playerid][USER_FACTIONRANK] < 10) {
        return SendClientMessage(playerid, -1, "You have no permission to use this command.");
    }
    new
        option[10]
    ;
    if(sscanf(params, "s[10]S[128]", option, params)) {
        return SendClientMessage(playerid, -1, "[USAGE]: /fedit (facname | rank (1-10) | motd)");
    }
    if(!strcmp(option, "facname", true)) {
        if(strlen(params) > 50) {
            return SendClientMessage(playerid, -1, "Faction name to long");
        }
        new
            string[256],
            idx = pInfo[playerid][USER_FACTION]
        ;
    fInfo[idx][FNAME][0] = EOS;

        strcat(fInfo[idx][FNAME], params, 50);
        format(string, sizeof string, "UPDATE factioninfo SET fname = '%s' WHERE fid = %d", params, fInfo[idx][FID]);
        db_query(FDatabase, Query);
        format(string, sizeof string, "You have changed the faction name to %s.", params);
        return SendClientMessage(playerid, -1, string);
    }
    if(!strcmp(option, "rank", true)) {
        new
            rankname[50],
            rank
        ;
        if(sscanf(params, "ds[50]", rank, rankname)) {
            return SendClientMessage(playerid, -1, "[USAGE]: /fedit rank (rank number) (rank name)."
        }
        switch(rank) {
            case 1: {
                // ...
            }
        }
        // ...
    }
    return true;
}
Reply
#3

I'd personally use something like the one below instead the whole 'option' thing.
pawn Код:
new tmp_name[50], rank;
if (!sscanf(params, "'facname's[50]", tmp_name))
{
    // code for "/fedit facname <name>"
}
else if (!sscanf(params, "'rank'is[50]", rank, tmp_name))
{
    // code for "/fedit rank <rank> <name>"
}
else .. send usage..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)