sscanf quiet specifiers
#1

Hi, I made a trunk system a few days ago like this:
Код:
	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]");
And when the action was store then it was like this:
Код:
                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;
		}
Today I thought that "extra" thing doesn't look too nice so I found sscanf's quiet specifiers and I made this command:
Код:
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;
}
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
Код:
		if (sscanf(params, "{s[7]}s[10]", item))
			return SendClientMessage(playerid, COLOR_GREY, "USAGE: /trunk store [item]");
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.
Reply


Messages In This Thread
sscanf quiet specifiers - by GoldenLion - 21.06.2017, 13:49
Re: sscanf quiet specifiers - by Konstantinos - 21.06.2017, 14:00
Re: sscanf quiet specifiers - by GoldenLion - 21.06.2017, 18:59
Re: sscanf quiet specifiers - by GoldenLion - 21.06.2017, 21:05

Forum Jump:


Users browsing this thread: 1 Guest(s)