function Reciepe
takes unit u,
integer item1,
integer item2,
integer item3,
integer item4,
integer item5,
integer item6,
integer itemResult
returns boolean local integer array uItem
local integer array rItem
local integer array slot
local boolean array b
local boolean array slotFull
local integer inc = 0
local integer inc2 = 0
local integer count = 0
local boolean check =
true set rItem
[1
] = item1
set rItem
[2
] = item2
set rItem
[3
] = item3
set rItem
[4
] = item4
set rItem
[5
] = item5
set rItem
[6
] = item6
loop exitwhen inc == 7
set inc = inc + 1
if rItem
[inc
] == 0
then set b
[inc
] =
true else set b
[inc
] =
false endif endloop set inc = 0
loop set inc = inc + 1
exitwhen inc == 7
set uItem
[inc
] = GetItemTypeId
(UnitItemInSlot
(u,inc-1
)) endloop set inc = 0
loop exitwhen inc == 7
set inc = inc + 1
loop set inc2 = inc2 + 1
exitwhen inc2 == 7
or b
[inc
] ==
true if rItem
[inc
] == uItem
[inc2
] and not slotFull
[inc2
] then set b
[inc
] =
true set slot
[count
] = inc2 - 1
set slotFull
[inc2
] =
true set count = count + 1
endif endloop set inc2 = 0
endloop set inc = 0
loop set inc = inc + 1
exitwhen inc == 7
if b
[inc
] ==
false then set check =
false endif endloop set inc = 0
if check
then loop exitwhen count == 0
set count = count - 1
call RemoveItem
( UnitItemInSlot
(u,slot
[count
]) ) endloop set bj_lastCreatedItem = CreateItem
(itemResult, GetUnitX
(u
), GetUnitY
(u
) ) call UnitAddItem
(u, bj_lastCreatedItem
) endif return check
endfunction
Description : it's for combine objects in one of your choice
How to use ? :
u is your unit whith an inventory
item1 ...
item 6 are integers (item type in gui), you can use rawcode 'xxxx', just use the shortcut Ctrl+d in the object editot for see it in the object editor.
Even if you don't want 6 items to combine you must use 6 integers, but use 0 if you don't want to use an other one.
the order with 0 and rawcodes doesn't matter
finally
itemResult is the combine item
PS : i use bj_lastCreatedItem for the result item so you can use the last created item in gui, but if you don't want this juste replace these lines :
set bj_lastCreatedItem = CreateItem(itemResult, GetUnitX(u), GetUnitY(u) )
call UnitAddItem(u, bj_lastCreatedItem)
with this :
call UnitAddItem(u, CreateItem(itemResult, GetUnitX(u), GetUnitY(u)))
and maybe UnitAddItem is useless because i think that create an item to an unit position give to it, but i can't test now, my cd is broken and i must reinstall war3
