Hi, I made a trunk system a few days ago like this:
And when the action was store then it was like this:
Today I thought that "extra" thing doesn't look too nice so I found sscanf's quiet specifiers and I made this command:
So basically when you store an apple you need to specifiy the quantity, but when you store a weapon you don't. The problem is that when you store for example 5 apples into the trunk it stores "apple 5" into item here
so that's an invalid item name and I also get a string buffer overflow when the size of item is smaller.
Is it possible to ignore the number after the item at this line so I could use it later for quantity or is the first way better? Hopefully it's understandable what I just explained.
Code:
new action[6], extra[32];
if (sscanf(params, "s[6]S()[32]", action, extra))
return SendClientMessage(playerid, COLOR_GREY, "USAGE: /trunk [open/close/view/store/get]");
Code:
new item[10], amount;
if (sscanf(extra, "s[10]D(0)", item, amount))
{
SendClientMessage(playerid, COLOR_GREY, "USAGE: /trunk store [item]");
SendClientMessage(playerid, COLOR_GREY, "ITEMS: marijuana, cocaine, crack, ecstasy, heroin, weapon, armor.");
return 1;
}
Code:
CMD:trunk(playerid, params[])
{
new action[7];
if (sscanf(params, "s[7]", action))
return SendClientMessage(playerid, COLOR_GREY, "USAGE: /trunk [action]");
if (!strcmp(action, "store", true))
{
new item[10];
if (sscanf(params, "{s[7]}s[10]", item))
return SendClientMessage(playerid, COLOR_GREY, "USAGE: /trunk store [item]");
if (!strcmp(item, "apple", true))
{
new quantity;
if (sscanf(params, "{s[7]s[10]}d", quantity))
return SendClientMessage(playerid, COLOR_GREY, "USAGE: /trunk store apple [quantity]");
new message[24];
format(message, sizeof(message), "quantity: %d", quantity);
SendClientMessage(playerid, -1, message);
}
else if (!strcmp(item, "weapon", true))
{
SendClientMessage(playerid, -1, "done");
}
else SendClientMessage(playerid, -1, "invalid item");
}
return 1;
}
Code:
if (sscanf(params, "{s[7]}s[10]", item))
return SendClientMessage(playerid, COLOR_GREY, "USAGE: /trunk store [item]");
Is it possible to ignore the number after the item at this line so I could use it later for quantity or is the first way better? Hopefully it's understandable what I just explained.