ScavengeSurvive icon indicating copy to clipboard operation
ScavengeSurvive copied to clipboard

Additem problem

Open kolor4do opened this issue 3 years ago • 1 comments

When using /additem 9mm u 10, a 9mm with 99999 bullets is born. Is there something wrong with either this code or am I typing it wrong?

` new query[32], specifiers[32], data[64];

if(sscanf(params, "s[32]S()[32]S()[64]", query, specifiers, data))
{
	ChatMsg(playerid, YELLOW, " >  Usage: /additem [itemid/itemname] [extradata format specifiers] [extradata array, comma separated]");
	ChatMsg(playerid, YELLOW, " >  Example: `/additem gascan df 1, 4.5` create a petrol can with an integer and a float in extradata.");
	return 1;
}

// if the "query" is not an integer type, search for the name
new ItemType:type = INVALID_ITEM_TYPE;
if(sscanf(query, "d", _:type))
{
	new itemname[MAX_ITEM_NAME];
	for(new ItemType:i; i < MAX_ITEM_TYPE; i++)
	{
		GetItemTypeUniqueName(i, itemname);

		if(strfind(itemname, query, true) != -1)
		{
			type = i;
			break;
		}
	}

	if(type == INVALID_ITEM_TYPE)
	{
		for(new ItemType:i; i < MAX_ITEM_TYPE; i++)
		{
			GetItemTypeName(i, itemname);

			if(strfind(itemname, query, true) != -1)
			{
				type = i;
				break;
			}
		}
	}
	if(type == INVALID_ITEM_TYPE)
	{
		ChatMsg(playerid, RED, " >  Invalid item type from string: '%s'", query);
		return 1;
	}
}
if(type == INVALID_ITEM_TYPE)
{
	ChatMsg(playerid, RED, " >  Invalid item type from integer: '%d'", _:type);
	return 1;
}

new
	exdata[32],
	exdatalen = strlen(specifiers);
if(exdatalen > 0)
{
	// generate a sscanf enum specifier format
	new sscanf_format[32];
	format(sscanf_format, sizeof sscanf_format, "p<,>e<%s>", specifiers);

	// parse the extra data using the generated sscanf format string
	if(strlen(data) && sscanf(data, sscanf_format, exdata))
	{
		ChatMsg(playerid, YELLOW, " >  Format of exdata did not match specifier: '%s'", sscanf_format);
		return 1;
	}
}

// create the item and hydrate its extradata array.
new
	typemaxsize,
	Item:itemid,
	Float:x,
	Float:y,
	Float:z,
	Float:r;

GetItemTypeArrayDataSize(type, typemaxsize);

GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, r);

itemid = CreateItem(type,
	x + (0.5 * floatsin(-r, degrees)),
	y + (0.5 * floatcos(-r, degrees)),
	z - ITEM_FLOOR_OFFSET, .rz = r);

if(exdatalen > 0)
{
	SetItemArrayData(itemid, exdata, typemaxsize);`

kolor4do avatar Jun 12 '21 22:06 kolor4do

I think the extradata layout for ammo uses the first element as the ammunition type (hollow point, etc) and the second element for the amount. Check weapons/ammo scripts as I forgot.

Southclaws avatar Jun 30 '21 10:06 Southclaws