A command with parameters.
#1

Hey people, I'm just wondering, how could I make a command with double parameters? Let me explain what i want exactly:

I want a /vehicle command, followed by more parameters ... like: park, get, sell, scrap, etc etc ..

So, here's what i got at the moment:
pawn Код:
YCMD:vehicle(playerid[], params, help)
{
       if(strcmp(params, "list", false) == 0)
    {
                // BLA BLA
        }
        if(strcmp(params, "get", false) == 0)
    {
                // BLA BLA
        }
        if(strcmp(params, "sell", false) == 0)
    {
                // BLA BLA
        }
Now, in the 'sell' parameter, how can I make two more parameters, for [playerid] and [price]:
/v sell [PlayerID] [Price] ??

I tried with sscanf, like:
pawn Код:
YCMD:vehicle(playerid, params, help)
{
       else if(strcmp(params, "sell", false) == 0)
    {
        if(!IsPlayerInAnyVehicle(playerid))
            return SendClientMessage(playerid, -1, ""You're not in a vehicle.");

        pvID = GetPlayerVehicleID(playerid);
        if(sscanf(params, "ui", pID, price))
            return SendClientMessage(playerid, -1, "Use: /vehicle sell [playerid] [ price]");
}
And it doesn't work ...
Reply
#2

Well, that's exactly what I need. Every 'option' has its own parameters.

So, you're saying something like:

pawn Код:
if(sscanf(params[1], params[2], "ui", pID, price))
            return SendClientMessage(playerid, -1, "Use: /vehicle sell [playerid] [ price]");
Well, that doesn't work ... Maybe I misunderstood you ?
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
No, you just didn't read. I said "params[4]", not "params[1]" or "params[2]"!
Well, yea ... Tested it with params[4] but it didn't work.

How's it supposed to work?
Reply
#4

BUMP. I still need help here ... Problem's not fixed yet. Thanks again.
Reply
#5

want to know how to make this too, I can't do that
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
Can I see your current attempt?
pawn Код:
YCMD:vehicle(PARAMS)
{
    #pragma unused help
    else if(strcmp(params, "sell", false) == 0)
    {
        if(!IsPlayerInAnyVehicle(playerid))
            return SendClientMessage(playerid, -1, ""CRE"Eroare"CWH": Trebuie sa fii intr-o masina sa o poti vinde.");

        pvID = GetPlayerVehicleID(playerid);

        if(!strmatch(V_DATA[pvID][vOwner], pName(playerid)))
            return SendClientMessage(playerid, -1, ""CRE"Eroare"CWH": Masina nu iti apartine, nu o poti vinde.");

        #if USE_PLAYER_SSCANF
        if(sscanf(params[4], "ui", "sell", pID, price))
            return SendClientMessage(playerid, -1, ""CRE"Utilizare"CWH": /vehicle sell [PlayerID / Nume] [Pretul]");

        #else
        if(sscanf(params[4], "ii", pID, price))
            return SendClientMessage(playerid, -1, ""CRE"Utilizare"CWH": /vehicle sell  [PlayerID / Nume] [Pretul]");
        #endif

        if(!IsPlayerConnected(pID))
            return SendClientMessage(playerid, -1, ""CRE"Eroare"CWH": Playerul selectat nu este conectat.");

        GetPlayerPos(pID, Pos[0], Pos[1], Pos[2]);
        if(!IsPlayerInRangeOfPoint(playerid, 3.0, Pos[0], Pos[1], Pos[2]))
            return SendClientMessage(playerid, -1, "Nu esti destul de aproape de playerul selectat.");

        if(price < 0)
            return SendClientMessage(playerid, -1, ""CRE"Eroare"CWH": Nu poti introduce valori negative.");

        SetPVarInt(pID, "BuyingCar", pvID);
        SetPVarInt(pID, "BuyingPrice", price);
        SetPVarInt(pID, "Seller", playerid + 1);
        format(str, sizeof str, "%s a oferit sa-ti vanda %s pentru %i$.", pName(playerid), VehicleNames[GetVehicleModel(pvID) - 400], price);
        SendClientMessage(pID, -1, str);
        format(str, sizeof str, "Ai oferit spre vanzare %s pentru %i$ lui %s.", VehicleNames[GetVehicleModel(pvID) - 400], price, pName(pID));
        SendClientMessage(playerid, -1, str);
        return 1;
    }

Here it is. Sorry for responding so late ...

There's the "USE_PLAYER_SSCANF" define, because sscanf is bugged for 0.3d linux ... so when it'll be fixed, I don't want to rewrite all the commands.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)