function Make_Item takes unit u returns nothing
//Add item types to udg_Items
//Change udg_ItemCount to the number of item types in udg_Items.
//This system works with item charges, if the charge is 0 then it adds 1.
//Thus allowing you to 'stack' items.
//Fake Recipie;
//
//if udg_ItemNum[0]>=2 and udg_ItemNum[1]>=1 then
// //remove checked items.
// set udg_ItemNum[0]=udg_ItemNum[0]-2
// set udg_ItemNum[1]=udg_ItemNum[1]-1
// //Add the items you want the recipie to give.
// set udg_ItemNum[3]=udg_ItemNum[3]+1
//elseif udg_ItemNum[3]>=1 and udg_ItemNum[0]>=1 then
// //remove checked items.
// set udg_ItemNum[0]=udg_ItemNum[0]-1
// set udg_ItemNum[3]=udg_ItemNum[3]-1
// //Add the items you want the recipie to give.
// set udg_ItemNum[4]=udg_ItemNum[4]+1
//endif
//
//Make sure all your item mats and items you get from the recipies to udg_Items.
//Items in a unit's invintory not on the udg_Items list will be ignored.
//This will not returned 'stacked' items, your stacking system should handle when a unit gains an item it already has to stack them.
local integer i=0
local integer I
local integer II
local item ii
//Count items...
loop
exitwhen i>udg_ItemCount
set udg_ItemNum[i]=0
set I=0
loop
exitwhen I>5
set ii=UnitItemInSlot(u,I)
if ii!=null then
if GetItemTypeId(ii)==udg_Items[i]then
set II=GetItemCharges(ii)
if II<=1then
set II=1
endif
set udg_ItemNum[i]=udg_ItemNum[i]+II
call RemoveItem(ii)
set II=0
endif
endif
set ii=null
set I=I+1
endloop
set i=i+1
endloop
//Recipes...
if udg_ItemNum[0]>=1 and udg_ItemNum[1]>=1 and udg_ItemNum[5]>=1 then
set udg_ItemNum[0]=udg_ItemNum[0]-1
set udg_ItemNum[1]=udg_ItemNum[1]-1
set udg_ItemNum[3]=udg_ItemNum[3]+1
elseif udg_ItemNum[0]>=1 and udg_ItemNum[2]>=1 and udg_ItemNum[5]>=1 then
set udg_ItemNum[0]=udg_ItemNum[0]-1
set udg_ItemNum[2]=udg_ItemNum[2]-1
set udg_ItemNum[4]=udg_ItemNum[4]+1
endif
//GUI Recipes...
call TriggerExecute(gg_trg_GUI_Recipes)
//Remake unused items...
set i=0
loop
exitwhen i>udg_ItemCount
loop
exitwhen udg_ItemNum[i]<=0
set udg_ItemNum[i]=udg_ItemNum[i]-1
call UnitAddItemById(u,udg_Items[i])
endloop
set udg_ItemNum[i]=0
set i=i+1
endloop
set ii=null
set u=null
endfunction