I think this should work for you as a template.
// Take the exact amount of ingredients
void TakeExactItems(object oPC, string sTag, int nItems);
// Get the exact amount of ingredients
int GetItemCount(object oPC, string sTag);
void main()
{
// Set up our variables
object oPC = GetPCSpeaker();
string sReagent1 = "reagent1", sReagent2 = "reagent2", sReagent3 = "reagent3", sBlueprint1 = "item1", sBlueprint2 = "item2";
int nReagent1 = 1, nReagent2 = 2, nReagent3 = 4, nGold = 50;
// Check for gold
if (GetGold(oPC) < nGold)
{
FloatingTextStringOnCreature("Not enough gold", oPC, FALSE);
return;
}
// Check all ingredients
if (GetItemCount(oPC, sReagent1) < nReagent1)
{
FloatingTextStringOnCreature("Not enough of reagent 1", oPC, FALSE);
return;
}
if (GetItemCount(oPC, sReagent2) < nReagent2)
{
FloatingTextStringOnCreature("Not enough of reagent 2", oPC, FALSE);
return;
}
if (GetItemCount(oPC, sReagent3) < nReagent3)
{
FloatingTextStringOnCreature("Not enough of reagent 3", oPC, FALSE);
return;
}
// Take the gold
TakeGoldFromCreature(nGold, oPC, TRUE);
// Take the ingredients
TakeExactItems(oPC, sReagent1, nReagent1);
TakeExactItems(oPC, sReagent2, nReagent2);
TakeExactItems(oPC, sReagent3, nReagent3);
// 90% chance for blueprint 1, 10% for blueprint2
if (Random(10))
{
CreateItemOnObject(sBlueprint1, oPC);
}
else
{
CreateItemOnObject(sBlueprint2, oPC);
}
}
// Take the exact amount of ingredients
void TakeExactItems(object oPC, string sTag, int nItems)
{
int nTaken, nStackSize;
object oItem = GetFirstItemInInventory(oPC);
while (GetIsObjectValid(oItem) && nTaken < nItems)
{
if (GetTag(oItem) == sTag)
{
nStackSize = GetItemStackSize(oItem);
if (nStackSize > nItems - nTaken)
{
SetItemStackSize(oItem, nStackSize - nItems + nTaken);
return;
}
else
{
DestroyObject(oItem);
nTaken += nStackSize;
}
}
oItem = GetNextItemInInventory(oPC);
}
}
// Get the exact amount of ingredients
int GetItemCount(object oPC, string sTag)
{
int nCount;
object oItem = GetFirstItemInInventory(oPC);
while (GetIsObjectValid(oItem))
{
if (GetTag(oItem) == sTag)
{
nCount += GetItemStackSize(oItem);
}
oItem = GetNextItemInInventory(oPC);
}
return nCount;
}
Can include the secondary functions in a library if you want.