sscanf within sscanf
#1

I'm trying to make an /import command, but will something like this work?
pawn Код:
CMD:import(playerid, params[])
{
    new string[128], weapon[32], amount, drugs[32];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You need to login first before using any command.");
    if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
    if(sscanf(params, "s[32]", weapon))
    {
        SCM(playerid, COLOR_WHITE, "USAGE: /import [weapon/drugs]");
        return 1;
    }
    if(!strcmp(params, "weapon", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
            if(sscanf(params, "s[32]d", weapon, amount))
            {
                SCM(playerid, COLOR_WHITE, "USAGE: /import [weapon] [amount]");
                return 1;
            }
        }
    }
    if(!strcmp(params, "drugs", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
            if(sscanf(params, "s[32]d", drugs, amount))
            {
                SCM(playerid, COLOR_WHITE, "USAGE: /import [drugs] [amount]");
                return 1;
            }
        }
    }
    return 1;
}
Reply
#2

Well, test it out!
Reply
#3

It can be way shorter. You first check if SSCANF works. if not, you just get the values of both and then compare. That way you dont have to execute SSCANF twice
Reply
#4

It ain't working, could you show me an example of how you make it shorter please?
Reply
#5

These are two types of command processors so you can not use the both command processors in a same script.
Reply
#6

Quote:
Originally Posted by TaLhA XIV
Посмотреть сообщение
These are two types of command processors so you can not use the both command processors in a same script.
He isn't? I guess you are looking at the strcmp, but that is just a string compare function which is just for the parameters.

@ OP: Call sscanf once. In Pseudo code:

Код:
if RETURN VALUE from sscanf == empty
   call error
else
   put all values in the variables (I thought it does that automatically by the last call)
   if is the player in an organisation
       do your action
Reply
#7

Do it this way:

pawn Код:
CMD:import(playerid, params[])
{
    new string[128], weapon[32], amount, drugs[32];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You need to login first before using any command.");
    if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
    if(sscanf(params, "s[32]d", weapon, amount))
    {
        SCM(playerid, COLOR_WHITE, "USAGE: /import [weapon/drugs] [amount]");
        return 1;
    }
    if(!strcmp(params, "weapon", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
        }
    }
    if(!strcmp(params, "drugs", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
        }
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Do it this way:

pawn Код:
CMD:import(playerid, params[])
{
    new string[128], weapon[32], amount, drugs[32];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You need to login first before using any command.");
    if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
    if(sscanf(params, "s[32]d", weapon, amount))
    {
        SCM(playerid, COLOR_WHITE, "USAGE: /import [weapon/drugs] [amount]");
        return 1;
    }
    if(!strcmp(params, "weapon", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
        }
    }
    if(!strcmp(params, "drugs", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
        }
    }
    return 1;
}
Okay, and how can i make it like choose a gun which you wanna import?
Reply
#9

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Do it this way:

pawn Код:
CMD:import(playerid, params[])
{
    new string[128], weapon[32], amount, drugs[32];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You need to login first before using any command.");
    if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
    if(sscanf(params, "s[32]d", weapon, amount))
    {
        SCM(playerid, COLOR_WHITE, "USAGE: /import [weapon/drugs] [amount]");
        return 1;
    }
    if(!strcmp(params, "weapon", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
        }
    }
    if(!strcmp(params, "drugs", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
        }
    }
    return 1;
}
Reverse the string compare and the family compare. You will only need one family comparation for that then. Saves you some code and it is more maintainable.
Reply
#10

I tried this, but it isn't working out.
pawn Код:
CMD:import(playerid, params[])
{
    new option[32];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You need to login first before using any command.");
    if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
    if(sscanf(params, "s[32]", option))
    {
        SCM(playerid, COLOR_WHITE, "USAGE: /import [weapon/drugs]");
        return 1;
    }
    if(!strcmp(params, "weapon", true))
    {
        new weapon1[32], weapon2[32];
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
            if(sscanf(params, "s[32]s[32]", weapon1, weapon2))
            {
                SCM(playerid, COLOR_WHITE, "USAGE: /import [weapon] [weaponname]");
                return 1;
            }
            if(!strcmp(weapon2, "deagle", true))
            {
                SCM(playerid, COLOR_FADE2, "YOU'VE IMPORTED A DEAGLE");
                return 1;
            }
        }
    }
    if(!strcmp(params, "drugs", true))
    {
        if(!PlayerInfo[playerid][pFam]) return SendClientMessage(playerid, COLOR_GREY, "ERROR: You have to be in a offical organisation.");
        {
       
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)