//This system takes multiple items and combines them to make 1 item
//It is advised that you do not touch ANYTHING below as it could cause SERIOUS instability with your map.
//You can remove this green text though.
//But you may use a few functions within the system to your pleasing >:D
library ItemRecipe initializer init
globals
public integer array ItemTypes
public integer ItemTypesAmount
endglobals
function GetItemAmount takes unit u, integer i returns integer
// function GetItemAmount takes unit, item type returns integer amount
// this function is used to get the amount of an item that a unit has
// example:
// Say a unit has 3 potions in it's inventory. One potion with 1 stack, and the other two potions with 2 stacks.
// so:
//Potion 1:1
//Potion 2:2
//Potion 3:2
// 1+2+2=5
// it takes all that and adds it up to make 5. The unit has 5 potions.
//(Note: Items with 0 stacks count as 1)
local integer R = 0
local integer I = 0
local integer ic
local item t
loop
exitwhen I > 5
set I = I + 1
set t = UnitItemInSlot( u, I - 1 )
if GetItemTypeId( t ) == i then
set ic = GetItemCharges( t )
if ic == 0 then
set R = R + 1
else
set R = R + ic
endif
endif
endloop
set t = null
return R
endfunction
function RemoveItemAmount takes unit u, integer i, integer a returns nothing
// function RemoveItemAmount takes unit, item type, amount removed returns nothing
// this will remove any amount of an item from a unit's inventory.
// if a unit has 5 potions and you remove 2, you will have 3 remaining.
local integer I = 0
local integer R = a
local integer ic
local item t
loop
exitwhen I > 5 or R < 1
set I = I + 1
set t = UnitItemInSlot( u, I - 1 )
if GetItemTypeId( t ) == i then
set ic = GetItemCharges( t )
if ic == 0 then
set R = R - 1
call RemoveItem( t )
elseif ic < R then
set R = R - ic
call RemoveItem( t )
else
call SetItemCharges( t, ic - R )
if ic - R == 0 then
call RemoveItem( t )
endif
set R = 0
endif
endif
endloop
set t = null
endfunction
function GetItemTypes takes unit u returns nothing
//This function will get all the item types a unit has in it's inventory and will return the amount (ItemTypesAmount)
//It also saves the item type in a array that you can loop through (ItemTypes[])
//If a unit has two of the same item the function will ignore the other item
local integer I = 0
local integer i
local item t
local integer it
set ItemTypesAmount = 0
loop
exitwhen I > 5
set I = I + 1
set t = UnitItemInSlot( u, I - 1 )
set it = GetItemTypeId( t )
set ItemTypes[I] = 0
set i = I
loop
exitwhen i < 1
set i = i - 1
if it == ItemTypes[i] then
set i = -1
endif
endloop
if i != -1 then
set ItemTypesAmount = ItemTypesAmount + 1
set ItemTypes[ItemTypesAmount] = it
endif
endloop
set t = null
endfunction
private function Pickup takes nothing returns nothing
local unit u = GetTriggerUnit( )
local integer i = 0
local integer ii
local integer iii
local integer in
local integer ti
call GetItemTypes( u )
loop
set i = i + 1
exitwhen udg_Recipe_ItemAmount_1[i] == 0
set in = 1
if udg_Recipe_ItemAmount_2[i] > 0 then
set in = 2
if udg_Recipe_ItemAmount_3[i] > 0 then
set in = 3
if udg_Recipe_ItemAmount_4[i] > 0 then
set in = 4
if udg_Recipe_ItemAmount_5[i] > 0 then
set in = 5
if udg_Recipe_ItemAmount_6[i] > 0 then
set in = 6
endif
endif
endif
endif
endif
set iii = 0
set ii = 0
if ItemTypesAmount >= in then
loop
set ii = ii + 1
exitwhen ii > ItemTypesAmount
set ti = GetItemAmount( u, ItemTypes[ii] )
if udg_Recipe_ItemType_1[i] == ItemTypes[ii] and ti >= udg_Recipe_ItemAmount_1[i] then
set iii = iii + 1
elseif udg_Recipe_ItemType_2[i] == ItemTypes[ii] and ti >= udg_Recipe_ItemAmount_2[i] then
set iii = iii + 1
elseif udg_Recipe_ItemType_3[i] == ItemTypes[ii] and ti >= udg_Recipe_ItemAmount_3[i] then
set iii = iii + 1
elseif udg_Recipe_ItemType_4[i] == ItemTypes[ii] and ti >= udg_Recipe_ItemAmount_4[i] then
set iii = iii + 1
elseif udg_Recipe_ItemType_5[i] == ItemTypes[ii] and ti >= udg_Recipe_ItemAmount_5[i] then
set iii = iii + 1
elseif udg_Recipe_ItemType_6[i] == ItemTypes[ii] and ti >= udg_Recipe_ItemAmount_6[i] then
set iii = iii + 1
endif
endloop
endif
if iii >= in then
call RemoveItemAmount( u, udg_Recipe_ItemType_1[i], udg_Recipe_ItemAmount_1[i] )
call RemoveItemAmount( u, udg_Recipe_ItemType_2[i], udg_Recipe_ItemAmount_2[i] )
call RemoveItemAmount( u, udg_Recipe_ItemType_3[i], udg_Recipe_ItemAmount_3[i] )
call RemoveItemAmount( u, udg_Recipe_ItemType_4[i], udg_Recipe_ItemAmount_4[i] )
call RemoveItemAmount( u, udg_Recipe_ItemType_5[i], udg_Recipe_ItemAmount_5[i] )
call RemoveItemAmount( u, udg_Recipe_ItemType_6[i], udg_Recipe_ItemAmount_6[i] )
call UnitAddItem( u, CreateItem( udg_Recipe_ItemMade[i], 0, 0 ) )
call DestroyEffect( AddSpecialEffectTarget( udg_Recipe_Effect, u, "origin" ) )
endif
endloop
set u = null
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
// Don't even be like "OH YOU HAVE A BJ!!!! 1/5"
// This is a friendly bj that only gets fired once :p
call TriggerAddAction( t, function Pickup )
set t = null
endfunction
endlibrary