1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  5. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  6. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  7. The 13th Music Contest Poll is up! Vote for the best tracks in this symphony of frost and flame.
    Dismiss Notice
  8. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Recipe System

Submitted by Diablo-dk
This bundle is marked as approved. It works and satisfies the submission rules.
Recipe System

Enables easy item recipe creation, including the option to dissamble recipe items again.


System code:

Code (vJASS):

//=======================================================================================================
// Recipe System
// By Fredbrik(Diablo-dk)
//
//=======================================================================================================
//globals
//integer               RN=0 // Recipe number.
//trigger               RT=CreateTrigger() // Main recipe trigger.
//boolean               RC=true
//integer array         itemid1
//integer array         itemid2
//integer array         itemid3
//integer array         itemid4
//integer array         itemid5
//integer array         itemid6
//integer array         ic //item count
//integer array         output
//endglobals
//=======================================================================================================
// User changeable constants
//=======================================================================================================
constant function Recipe_Effect takes nothing returns string
    return "Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl" //An effect that comes whenever a recipe is made.
endfunction

constant function Recipe_AP takes nothing returns string
    return "origin" //Attachment point for Recipe_Effect()
endfunction
//=======================================================================================================
// This function will return the first item of entered Id in the unit's inventory.
function GetItem takes unit u, integer Id returns item
    local integer i=0
    local item it
    loop
        exitwhen i==6
        if GetItemTypeId(UnitItemInSlot(u,i)) == Id then
            return UnitItemInSlot(u,i)
        set i=5
        endif
        set i=i+1
    endloop
    return null
endfunction
//==============================
function HasItems takes unit u, integer i returns boolean
    local integer index=0
    local integer id=-1
    local integer b1=0
    local integer b2=0
    local integer b3=0
    local integer b4=0
    local integer b5=0
    local integer b6=0
    loop
        exitwhen index==6
        set id=GetItemTypeId(UnitItemInSlot(u,index))
        if id == 0 then
            set id=-1
        endif
        if id == udg_itemid1[i] and b1 == 0 then
            set b1=1
            set id=-1
        endif
        if id == udg_itemid2[i] and b2 == 0 then
            set b2=1
            set id=-1
        endif
        if id == udg_itemid3[i] and b3 == 0 then
            set b3=1
            set id=-1
        endif
        if id == udg_itemid4[i] and b4 == 0 then
            set b4=1
            set id=-1
        endif
        if id == udg_itemid5[i] and b5 == 0 then
            set b5=1
            set id=-1
        endif
        if id == udg_itemid6[i] and b6 == 0 then
            set b6=1
            set id=-1
        endif
        if b1+b2+b3+b4+b5+b6 == udg_ic[i] then
            return true
        endif
        set index=index+1
    endloop
    return false
endfunction
//=======================================================================================================
// User Functions:
// Recipe Creating:
//
//=======================================================================================================
function CreateRecipe takes integer i1,integer i2,integer i3,integer i4,integer i5,integer i6,integer output returns nothing
    set udg_RN=udg_RN+1
    set udg_itemid1[udg_RN]=i1
    set udg_itemid2[udg_RN]=i2
    set udg_ic[udg_RN]=2
    if i3 != 0 then
        set udg_itemid3[udg_RN]=i3
        set udg_ic[udg_RN]=udg_ic[udg_RN]+1
    endif
    if i4 != 0 then
        set udg_itemid4[udg_RN]=i4
        set udg_ic[udg_RN]=udg_ic[udg_RN]+1
    endif
    if i5 != 0 then
        set udg_itemid5[udg_RN]=i5
        set udg_ic[udg_RN]=udg_ic[udg_RN]+1
    endif
    if i6 != 0 then
        set udg_itemid6[udg_RN]=i6
        set udg_ic[udg_RN]=udg_ic[udg_RN]+1
    endif
    set udg_output[udg_RN]=output
endfunction
function CreateRecipe2 takes integer i1,integer i2,integer i3 returns nothing
    set udg_RN=udg_RN+1
    set udg_itemid1[udg_RN]=i1
    set udg_itemid2[udg_RN]=i2
    set udg_output[udg_RN]=i3
    set udg_ic[udg_RN]=2
endfunction

// Creates a recipe that requires 2 items to combine into a new item. i3 is the combined item.
// Example: call CreateRecipe2('I000','I001','I002')
function CreateRecipe3 takes integer i1,integer i2,integer i3,integer i4 returns nothing
    set udg_RN=udg_RN+1
    set udg_itemid1[udg_RN]=i1
    set udg_itemid2[udg_RN]=i2
    set udg_itemid3[udg_RN]=i3
    set udg_output[udg_RN]=i4
    set udg_ic[udg_RN]=3
endfunction

// The same as CreateRecipe2 except this requires 3 items to combine. i4 is the combined item.
function CreateRecipe4 takes integer i1,integer i2,integer i3,integer i4,integer i5 returns nothing
    set udg_RN=udg_RN+1
    set udg_itemid1[udg_RN]=i1
    set udg_itemid2[udg_RN]=i2
    set udg_itemid3[udg_RN]=i3
    set udg_itemid4[udg_RN]=i4
    set udg_output[udg_RN]=i5
    set udg_ic[udg_RN]=4
endfunction

// The same as CreateRecipe2 except this requires 4 items to combine. i5 is the combined item.
function CreateRecipe5 takes integer i1,integer i2,integer i3,integer i4,integer i5,integer i6 returns nothing
    set udg_RN=udg_RN+1
    set udg_itemid1[udg_RN]=i1
    set udg_itemid2[udg_RN]=i2
    set udg_itemid3[udg_RN]=i3
    set udg_itemid4[udg_RN]=i4
    set udg_itemid5[udg_RN]=i5
    set udg_output[udg_RN]=i6
    set udg_ic[udg_RN]=5
endfunction

// The same as CreateRecipe2 except this requires 5 items to combine. i6 is the combined item.
function CreateRecipe6 takes integer i1,integer i2,integer i3,integer i4,integer i5,integer i6,integer i7 returns nothing
    set udg_RN=udg_RN+1
    set udg_itemid1[udg_RN]=i1
    set udg_itemid2[udg_RN]=i2
    set udg_itemid3[udg_RN]=i3
    set udg_itemid4[udg_RN]=i4
    set udg_itemid5[udg_RN]=i5
    set udg_itemid6[udg_RN]=i6
    set udg_output[udg_RN]=i7
    set udg_ic[udg_RN]=6
endfunction

// The same as CreateRecipe2 except this requires 6 items to combine. i7 is the combined item.
//===================================================================================================
// This function disassembles a recipe item to its original components.

function DisItem takes unit u,item it returns boolean
    local integer c=GetItemUserData(it)
    local item array newitem
    local integer i=udg_ic[c]
    if it != null then
        if i <= 6-UnitInventoryCount(u)+1 and i > 0 then
            set udg_RC=false
            if udg_itemid2[c] != null then
                set newitem[1]=CreateItem(udg_itemid1[c],GetUnitX(u),GetUnitY(u))
                set newitem[2]=CreateItem(udg_itemid2[c],GetUnitX(u),GetUnitY(u))
                endif
            if udg_itemid3[c] != null then
                set newitem[3]=CreateItem(udg_itemid3[c],GetUnitX(u),GetUnitY(u))
                call UnitAddItem(u,newitem[3])
            endif
            if udg_itemid4[c] != null then
                set newitem[4]=CreateItem(udg_itemid4[c],GetUnitX(u),GetUnitY(u))
                call UnitAddItem(u,newitem[4])
            endif
            if udg_itemid5[c] != null then
                set newitem[5]=CreateItem(udg_itemid5[c],GetUnitX(u),GetUnitY(u))
                call UnitAddItem(u,newitem[5])
            endif
            if udg_itemid6[c] != null then
                set newitem[6]=CreateItem(udg_itemid6[c],GetUnitX(u),GetUnitY(u))
                call UnitAddItem(u,newitem[6])
            endif
            call RemoveItem(it)
            call UnitAddItem(u,newitem[1])
            call UnitAddItem(u,newitem[2])

        set newitem[1]=null
        set newitem[2]=null
        set newitem[3]=null
        set newitem[4]=null
        set newitem[5]=null
        set newitem[6]=null
        set udg_RC=true
        else
            return false
        endif
    endif
    return true
endfunction
//=======================================================================================================
//
//Main Recipe Function: Do not change unless you know what you are doing
//
//=======================================================================================================
function Recipe_Main takes nothing returns nothing
    local item it
    local integer i=0
    local unit u=GetManipulatingUnit()
    loop
        exitwhen i==udg_RN
        set i=i+1
        if udg_RC == true then
            if udg_ic[i] == 6 then
                if HasItems(u,i) then
                    call RemoveItem(GetItem(u,udg_itemid1[i]))
                    call RemoveItem(GetItem(u,udg_itemid2[i]))
                    call RemoveItem(GetItem(u,udg_itemid3[i]))
                    call RemoveItem(GetItem(u,udg_itemid4[i]))
                    call RemoveItem(GetItem(u,udg_itemid5[i]))
                    call RemoveItem(GetItem(u,udg_itemid6[i]))
                    call DestroyEffect(AddSpecialEffectTarget(Recipe_Effect(),u,Recipe_AP()))
                    set it=CreateItem(udg_output[i],GetUnitX(u),GetUnitY(u))
                    call SetItemUserData(it,i) //Used for disassembling.
                    call UnitAddItem(u,it)
                    set i=udg_RN
                endif
            elseif udg_ic[i] == 5 then
                if HasItems(u,i) then
                    call RemoveItem(GetItem(u,udg_itemid1[i]))
                    call RemoveItem(GetItem(u,udg_itemid2[i]))
                    call RemoveItem(GetItem(u,udg_itemid3[i]))
                    call RemoveItem(GetItem(u,udg_itemid4[i]))
                    call RemoveItem(GetItem(u,udg_itemid5[i]))
                    call DestroyEffect(AddSpecialEffectTarget(Recipe_Effect(),u,Recipe_AP()))
                    set it=CreateItem(udg_output[i],GetUnitX(u),GetUnitY(u))
                    call SetItemUserData(it,i) //Used for disassembling.
                    call UnitAddItem(u,it)
                    set i=udg_RN
                endif
            elseif udg_ic[i] == 4 then
                if HasItems(u,i) then
                    call RemoveItem(GetItem(u,udg_itemid1[i]))
                    call RemoveItem(GetItem(u,udg_itemid2[i]))
                    call RemoveItem(GetItem(u,udg_itemid3[i]))
                    call RemoveItem(GetItem(u,udg_itemid4[i]))
                    call DestroyEffect(AddSpecialEffectTarget(Recipe_Effect(),u,Recipe_AP()))
                    set it=CreateItem(udg_output[i],GetUnitX(u),GetUnitY(u))
                    call SetItemUserData(it,i) //Used for disassembling.
                    call UnitAddItem(u,it)
                    set i=udg_RN
                endif
            elseif udg_ic[i] == 3 then
                if HasItems(u,i) then
                    call RemoveItem(GetItem(u,udg_itemid1[i]))
                    call RemoveItem(GetItem(u,udg_itemid2[i]))
                    call RemoveItem(GetItem(u,udg_itemid3[i]))
                    call DestroyEffect(AddSpecialEffectTarget(Recipe_Effect(),u,Recipe_AP()))
                    set it=CreateItem(udg_output[i],GetUnitX(u),GetUnitY(u))
                    call SetItemUserData(it,i) //Used for disassembling.
                    call UnitAddItem(u,it)
                    set i=udg_RN
                endif
            elseif udg_ic[i] == 2 then
                if HasItems(u,i) then
                    call RemoveItem(GetItem(u,udg_itemid1[i]))
                    call RemoveItem(GetItem(u,udg_itemid2[i]))
                    call DestroyEffect(AddSpecialEffectTarget(Recipe_Effect(),u,Recipe_AP()))
                    set it=CreateItem(udg_output[i],GetUnitX(u),GetUnitY(u))
                    call SetItemUserData(it,i) //Used for disassembling.
                    call UnitAddItem(u,it)
                    set i=udg_RN
                endif
            endif
        endif
    endloop
    set it=null
    set u=null
endfunction
function InitRecipe takes nothing returns nothing
    set udg_RT=CreateTrigger()
    set udg_RC=true
    call TriggerRegisterAnyUnitEventBJ( udg_RT, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction(udg_RT,function Recipe_Main)
endfunction
//call this at map init.


//forced by WE
function InitTrig_Recipe takes nothing returns nothing
endfunction
// End Recipe

Requirements:

Recipe system has no specific requirements. Get quickly started by reading the manual included within the demo map.
Furthermore I made a small sample code to demonstrate how to use the system.

Author's note:

Please give proper credits, when using Recipe System in your map.

Changelog
Changelog:
version 1.22:
Fixed a bug in the implemention readme that would cause the system not to work correctly.

version 1.21:
Shortened a few functions.

version 1.2:
Fixed a bug that caused recipes with 2 or more of the same item to bug.

version 1.1:
Optimized code a bit.


Keywords:
recipe, itemrecipe
Contents

Recipe System (Map)

Reviews
Moderator
19:01, 2ndth Sep 2015 This resource has been re-approved by BPower. From moderator to user: Perfect if you need a simple item recipe system. It's very fail-safe and easy to setup. Keep in mind that the system manipulates ItemUserData. In case...
  1. johannesr

    johannesr

    Joined:
    Apr 24, 2005
    Messages:
    753
    Resources:
    2
    Maps:
    2
    Resources:
    2
    I dont understand how does the game understand which items it needs to combine the third item? Did u mean that i should replace itemid2 etc with the item id? And if so how do i know what the items id is?
     
  2. jonadrian619

    jonadrian619

    Joined:
    Oct 24, 2006
    Messages:
    121
    Resources:
    4
    Maps:
    1
    Tutorials:
    3
    Resources:
    4
    I'm going to use this for our insurrection map. Anywat it's cool!! Keep up the good work.
     
  3. Tan

    Tan

    Joined:
    Sep 25, 2007
    Messages:
    34
    Resources:
    0
    Resources:
    0
    Sorry this bugs and realy sucks.. don't use it
     
  4. Diablo-dk

    Diablo-dk

    Joined:
    Nov 10, 2004
    Messages:
    369
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Tan, can you explain why this sucks? And no, this isn't buggy.

    If you want to comment then atleast say something constructive.

    Consider this as a warning.
     
  5. Tan

    Tan

    Joined:
    Sep 25, 2007
    Messages:
    34
    Resources:
    0
    Resources:
    0
    Sorry I was sitting like 5 hours with your &quot;simple recipe&quot; system, coulden't get it to work! You need to explain better how to get it working...
    I use this simple recipe system right now: http://www.hiveworkshop.com/forums/showthread.php?t=35788
    The only thing that's bad with it that you can't do a recipe that needs two of the same things for. If you can explain how to get yours working I will use it Diablo-dk...
     
  6. Tan

    Tan

    Joined:
    Sep 25, 2007
    Messages:
    34
    Resources:
    0
    Resources:
    0
    I got it working now, and it's great.. :) You should put in where you can find the map header to..
     
  7. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    pwnazar

    damn need to fill post T_T
     
  8. Arvedui

    Arvedui

    Joined:
    Oct 27, 2007
    Messages:
    1,347
    Resources:
    0
    Resources:
    0
    This really is awesome, once I finally understood it everything worked. It's amazing.
     
  9. Own4k1ll4

    Own4k1ll4

    Joined:
    Feb 3, 2008
    Messages:
    10
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Omg this is very usefully in RPG-maps...
     
  10. Succubus

    Succubus

    Joined:
    Feb 13, 2007
    Messages:
    4
    Resources:
    0
    Resources:
    0
    why i cant use custom items?
    Only standard items are working
     
  11. CyberDuelX16

    CyberDuelX16

    Joined:
    May 23, 2008
    Messages:
    1,360
    Resources:
    0
    Resources:
    0
    Ive tried it , its ok but ive seen better. Keep up the good work!
     
  12. ECCLESIASTES

    ECCLESIASTES

    Joined:
    Nov 6, 2008
    Messages:
    18
    Resources:
    0
    Resources:
    0
    omg i'm very creative right now :grin:
     
  13. unclenig

    unclenig

    Joined:
    Oct 14, 2008
    Messages:
    4
    Resources:
    0
    Resources:
    0
    Thanks diablo-dk. Helped me a lot.
     
  14. unclenig

    unclenig

    Joined:
    Oct 14, 2008
    Messages:
    4
    Resources:
    0
    Resources:
    0
    What... It was working fine before and I made like 3 recipes + tested. I just woke up the next morning and I couldn't save ~ it says the functions are undeclared although i copied everything. How to fix this anyone? XP
    EDIT: Oh nvm! It's working again. Good work diablo-dk +rep
     
    Last edited: Dec 23, 2008
  15. bin

    bin

    Joined:
    Feb 5, 2009
    Messages:
    1
    Resources:
    0
    Resources:
    0
    Do you know how to create spell like invoker?
     
  16. Geed

    Geed

    Joined:
    Sep 12, 2008
    Messages:
    5
    Resources:
    0
    Resources:
    0
    How can i implement custom items ? and especially items with a colour code. because the item id says something like: l015:fmld (e.g.). but it doesn't work .

    I solved it now, cause only the first 4 letters counts. so it's:

    I015
     
  17. bReathl3sS

    bReathl3sS

    Joined:
    Dec 18, 2007
    Messages:
    205
    Resources:
    0
    Resources:
    0
    hey diablo-dk
    i tried your system and it works very good except for the small lags appearing when first mixing an item, but i think that cant be fixed.
    and i got one question:
    the item disassemble works with an integer i that is the number of items needed for a recipe (correct?). so if i want to change the disassemble to work even when the unit has not enough slots, do i have to replace

    Code (vJASS):
    if i <= 6-UnitInventoryCount(u)+1 and i > 0 then

    with
    Code (vJASS):
    if i > 0 then

    ?

    greetings
     
  18. Killjaes

    Killjaes

    Joined:
    May 9, 2009
    Messages:
    12
    Resources:
    0
    Resources:
    0
    what is a rawcode?
    this thing works?
    WHATIS JASS!
     
  19. dragor-X

    dragor-X

    Joined:
    Feb 26, 2008
    Messages:
    172
    Resources:
    0
    Resources:
    0
    Doh! Doesn't work for me... Do I have to set RT to the recipe trigger, ic[0] to the number of items and RN to the number of recipes??

    Here's what I've did: I've cop/pasted the Recipe Script in the Custom Script Code section, then I've copy/pasted the trigger with all variables (the variables where all created), then I've set the variable RC to true (in variable window) and then I've copy/pasted the ReadMe (just in case) and after the Demo trigger (which I've modified to put my recipes)...

    Anything wrong in my list of things that I did?
    +HELP ME PLSSS!

    EDIT: It was my fault... The raw code was starting by I but in warcraft, the I ressemble like the l (minus-L). Sorry for this :D
     
    Last edited: May 14, 2009
  20. pIjIN

    pIjIN

    Joined:
    Apr 4, 2008
    Messages:
    3
    Resources:
    0
    Resources:
    0
    wd diablo. This will definently come in handy some time...