• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Reciepe

Level 17
Joined
Apr 27, 2008
Messages
2,455
JASS:
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 :
JASS:
            set bj_lastCreatedItem = CreateItem(itemResult, GetUnitX(u), GetUnitY(u) )
            call UnitAddItem(u, bj_lastCreatedItem)
with this :

JASS:
            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 :cry:
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
  • Arrays start at 0
  • You can replace CreateItem then UnitAddItem with UnitAddItemById
  • ==false can be replaced with not
  • This isn't particularly useful, seeing as it doesn't even manage the recipes; it just checks if you have one that you have to pass right then and there, and if you have it it combines the items.
  • There are lots of wasted variables, such as the integer array 'slot'
  • Unoptimized in general (I'm not going to bother continuing, as it would cause large parts of the code to be rewritten)

Sorry, but this is rather poorly optimized and not particularly useful. Additionally, there are many that are optimized better, as well as more useful (because they handle the recipes completely, as opposed to simply combinations) out there.

~Graveyarded.
 
Top