Help with a command! (/v get [ID])
#1

Why doesn't this work with sscanf? The command works in itself but when I put it in this column nothing happens when I type the command.

The command is /v get [id]. All the other commands without another sscanf sub-thingy works..
If I make the command like /vget [ID], it works perfectly. Anyone got any ideas?

This doesn't work.
pawn Код:
CMD:v(playerid, params[])
{
    new
    command[28];

    if(sscanf(params, "s[28]", command)) return SendClientMessage(playerid, COLOR_GREEN, "[Usage:] /v (lock, get, park, lights, sell, givekeys, buy, eject, ejectall, find, clearmods, trunk, trunkinfo, enter, exit)");
    if(!strcmp(command, "get", true))
    {
        new vehicleid;
        if(sscanf(params, "d", vehicleid)) return SendClientMessage(playerid, COLOR_GREY, "[Usage:] /v get [ID]. Check /v list for your vehicle ID.");
        // rest of the code, I assure you it works.
        return 1;
    }
    return 1;
}
This works.
pawn Код:
COMMAND:vget(playerid, params[])
{
        new vehicleid;
        if(sscanf(params, "d", vehicleid)) return SendClientMessage(playerid, COLOR_GREY, "[Usage:] /v get [ID]. Check /v list for your vehicle ID.");
        // rest of the code
        return 1;
}
Reply
#2

You need to ignore the string (command) in the second use of sscanf:
Код:
CMD:v(playerid, params[])
{
    new command[128];
    if(sscanf(params, "s[128]", command)) return SendClientMessage(playerid, COLOR_GREEN, "[Usage:] /v (lock, get, park, lights, sell, givekeys, buy, eject, ejectall, find, clearmods, trunk, trunkinfo, enter, exit)");
    if(strcmp(command, "get", true, 3) == 0)
    {
        new vehicleid;
        if(sscanf(params, "{s[]}i", vehicleid)) return SendClientMessage(playerid, COLOR_GREY, "[Usage:] /v get [ID]. Check /v list for your vehicle ID.");
        return 1;
    }
    return 1;
}
Reply
#3

Well, you need to add the "command"-array to the other sscanf as well, but you can just use params instead of creating a new array.
pawn Код:
#define isnull(%1) \
    ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

CMD:v(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, COLOR_GREEN, "[Usage:] /v (lock, get, park, lights, sell, givekeys, buy, eject, ejectall, find, clearmods, trunk, trunkinfo, enter, exit)");
    if(!strcmp(params, "get", true, 3))
    {
        new vehicleid;
        if(sscanf(params, "s[128]d", params, vehicleid)) return SendClientMessage(playerid, COLOR_GREY, "[Usage:] /v get [ID]. Check /v list for your vehicle ID.");
        // Code
    return 1;
    }
    return 1;
}
Reply
#4

@SickAttack Still not working. It displays nothing when I type /v get, when I type /v get 71 for example it displays the [Usage:] message just as it did before.
Reply
#5

Quote:
Originally Posted by Chrillzen
Посмотреть сообщение
@SickAttack Still not working. It displays nothing when I type /v get, when I type /v get 71 for example it displays the [Usage:] message just as it did before.
I edited the command, have another look at it.
Reply
#6

None of them working. :/ It just gives me "You are not close to a vehicle." Which is from another part of the /v command. It also messed up the other parts in the command such as /v park, /v lock, etc.
Reply
#7

Then there could be something wrong with that piece of code, show us it.
You can also use SendClientMessage to send the vehicleid you entered, to be sure if the sscanf is the problem or not.
Reply
#8

Edit: Fixed!
Reply
#9

You're using both "command" and "params", just use params.
And i also think you need the counter, like
pawn Код:
if(!strcmp(params, "get", true, 3))
Instead of just
pawn Код:
if(!strcmp(params, "get", true))
Reply
#10

Well, it works for me (you should put the array size on quite sections though, sscanf gives you a warning in the console - even though it still works):
pawn Код:
CMD:testing(playerid, params[])
{
    new string[144], command[128];
    if(sscanf(params, "s[128]", command)) return SendClientMessage(playerid, -1, "[Usage:] /v (lock, get, park, lights, sell, givekeys, buy, eject, ejectall, find, clearmods, trunk, trunkinfo, enter, exit)");
   
    if(strcmp(command, "get", true, 3) == 0)
    {
        new vehicleid;
        if(sscanf(params, "{s[128]}i", vehicleid)) return SendClientMessage(playerid, -1, "[Usage:] /v get [ID]. Check /v list for your vehicle ID.");
        format(string, sizeof(string), "Command: %s - Vehicle id: %d", command, vehicleid);
        SendClientMessage(playerid, -1, string);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)