Two or three parameters with sscanf or zcmd
#1

Hi dear,

i have tried a lot of methods but I cant find the right one.

How can I ask for more parameters? For example (the first parameter with strcmp works, but sscanf under the "car" or "buy" parameter want work correctly) :

pawn Код:
CMD:command(playerid, params[])
{
    if(isnull(params)) {
        return SendClientMessage(playerid, -1, "USAGE: /command [name]");
    }
     
    else if(!strcmp(params, "car", true)) {
// here I want another thing like this:
    new carid, reason[64]
    if (!sscanf(params2, "ds[64]", carid,reason))
    {
        new string[64];
        format(string,sizeof(string),"Carid %d spawned, reason: %s",carid,reason);
    } else SendClientMessage(playerid,-1,"USAGE: /command car [carid] [reason for spawning]");
    }
    else if(!strcmp(params, "buy", true)) {
    new buyid, reason[64]
    if (!sscanf(params2, "ds[64]", carid,reason))
    {
        new string[64];
        format(string,sizeof(string),"Bought %d fishes, reason: %s",carid,reason);
    } else SendClientMessage(playerid,-1,"USAGE: /command buy [ammount] [reason for buying fishes]");
    }
    return 1;
}
I tried it with sscanf... But it will not work on this method. Whats wrong? :S

Thanks for help.
Reply
#2

Using optional parameters, check the sscanf documentation.
Reply
#3

Create an string array and use it in sscanf.

pawn Код:
new ExString[CountOfString], Ex2String[CountOf2String];
sscanf(params, "s[CountOfString]s[CountOf2String]", ExString, Ex2String);

if(strcmp(ExString, "Bla", true) == 0)
{
if(strcmp(Ex2String, "BlaBla") == 0)
{
//
}
}
Reply
#4

And if I want to ask for a username? Same thing?
I mean it like this:

pawn Код:
if(strcmp(Username, "WhatShouldITypeInHere?") == 0)
{
Reply
#5

String compare.. it will check is it the same as "Username" array. You can do this simply in normal sscanf with if statement if you want to make it with one parameter. If more then just do this what i done in earlier post. if(strcmp(ExString for the first thing (i.e. comparename) and in the second type player name - if(strcmp(ExString2 is the same as ExString3. So it should look like that:

/command CompareNames YourName

edit://
I've made this code for example only.

pawn Код:
#include        <a_samp>
#include        <zcmd>
#include        <sscanf2>


CMD:command(playerid, params[])
{
    if(isnull(params))
    {
        SendClientMessage(playerid, -1, "Type: /command [CompareNames] [CompareName]");
        SendClientMessage(playerid, -1, "This script will comapare your name to the name which you typed!");
        return true;
    }
   
    new param[64], param2[64];
    sscanf(params, "s[64]s[64]", param, param2);

    if(strcmp(param, "CompareNames", true) == 0)
    {
        if(strcmp(PlayerName(playerid), param2) == 0)
        {
            SendClientMessage(playerid, -1, "Hey! Your name is the same as mine! Huh..");
        }
       
        else
        {
            SendClientMessage(playerid, -1, "My name is different.. get lost.");
        }
    }
    return true;
}

stock PlayerName(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    return pName;
}
Not tested, but should work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)