• 🏆 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!

Item Recipe System [GUI Friendly]

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
This is a recipe engine that takes multiple item types, charges, or no charges to make an item. It has a GUI setup but a vJass core.

System:
JASS:
//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

Comments
Recipe_ItemType is the item requirement to make the Recipe_ItemMade
For every new recipe you must increase the number in the brackets [ ] by 1
So if you were to add a new recipe to this right now you would do

Set RecipeItemType_1 [2] = YourItem

As you add more needed item requirements you must use the next variable
From RecipeItemType_1 to RecipeItemType_2 to RecipeItemType_3 ...

Hope you understand, have fun making recipes :p
~maddeem
  • Initialize Recipes
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Game - Display to (All players) for 999.00 seconds the text: Combine: --------...
      • -------- ------------------------ --------
      • -------- Recipe Setup --------
      • -------- ------------------------ --------
      • Set Recipe_Effect = Abilities\Spells\Human\HolyBolt\HolyBoltSpecialArt.mdl
      • -------- ------------------------ --------
      • -------- Kelen's Dagger of Escape RECIPE --------
      • -------- ------------------------ --------
      • Set Recipe_ItemType_1[1] = Claws of Attack +15
      • Set Recipe_ItemAmount_1[1] = 3
      • Set Recipe_ItemType_2[1] = Crown of Kings +5
      • Set Recipe_ItemAmount_2[1] = 1
      • Set Recipe_ItemMade[1] = Kelen's Dagger of Escape
      • -------- ------------------------ --------
      • -------- Potion of Divinity RECIPE --------
      • -------- ------------------------ --------
      • Set Recipe_ItemType_1[2] = Potion of Greater Healing
      • Set Recipe_ItemAmount_1[2] = 2
      • Set Recipe_ItemType_2[2] = Potion of Greater Mana
      • Set Recipe_ItemAmount_2[2] = 1
      • Set Recipe_ItemType_3[2] = Potion of Invulnerability
      • Set Recipe_ItemAmount_3[2] = 1
      • Set Recipe_ItemMade[2] = Potion of Divinity
      • -------- ------------------------ --------
      • -------- For the variable copy ONLY! Delete below once you have copied this folder into your map! --------
      • -------- ------------------------ --------
      • Set Recipe_ItemAmount_1[0] = 0
      • Set Recipe_ItemAmount_2[0] = 0
      • Set Recipe_ItemAmount_3[0] = 0
      • Set Recipe_ItemAmount_4[0] = 0
      • Set Recipe_ItemAmount_5[0] = 0
      • Set Recipe_ItemAmount_6[0] = 0
      • Set Recipe_ItemType_1[0] = (Item-type of No item)
      • Set Recipe_ItemType_2[0] = (Item-type of No item)
      • Set Recipe_ItemType_3[0] = (Item-type of No item)
      • Set Recipe_ItemType_4[0] = (Item-type of No item)
      • Set Recipe_ItemType_5[0] = (Item-type of No item)
      • Set Recipe_ItemType_6[0] = (Item-type of No item)


Keywords:
Recipe, Item Combination, System
Contents

Recipe Engine (Map)

Reviews
12th Dec 2015 IcemanBo: Too long as NeedsFix. Rejected. 00:16, 20th Jul 2012 Magtheridon96: I would totally recommend restructuring the system because currently, the algorithms are not very clear. :/ It's totally fine though. You told me...

Moderator

M

Moderator

12th Dec 2015
IcemanBo: Too long as NeedsFix. Rejected.

00:16, 20th Jul 2012
Magtheridon96:

I would totally recommend restructuring the system because currently, the algorithms are not very clear. :/
It's totally fine though.

You told me this thing only loops over recipes associated with the item you picked up. I don't really see how though =o

I would also recommend making it so that we can define the number of
charges required inside the configuration.

Charges shouldn't be treated as amounts bro.
Charges are charges. Simply that.

Let's say I have a scepter with 5 charges and each charge would allow me to cast a spell. I want to combine 2 of these scepters to make a stronger one. It would compile the first and make a better one because of the charges :/

As soon as this is fixed, I can approve this.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Thats from a coding perspective, but from ingame it makes actual sense. A charge really is just a multiple of an item, nothing else. Thats the way this system treats it. If people have a problem with that (you appear to be the only one) they can use another system. It's not that difficult to grasp

That would slow down the code, make it more bulky, and harder to configure. Who would actually want to set Item Amount and Item Charges. That would be freakin confusing.
Also if they wanted it to remove whole charge items they could set it to the default number of charges.
For every item type you would have to set THREE things. Nobody wants to do that.

It appears your trying to shape it into YOUR ideal recipe system. Rejecting something for this, is ridiculous.

Completely untrue. If you have 3 charges of invisibility on a belt, does that mean you have three belts? No.

You should only be able to set item charges, I agree, but item charges represent either the amount of item or the charge of an item =)
 
Level 23
Joined
Jan 1, 2011
Messages
1,504
I would totally recommend restructuring the system because currently, the algorithms are not very clear. :/
It's totally fine though.

You told me this thing only loops over recipes associated with the item you picked up. I don't really see how though =o

I would also recommend making it so that we can define the number of
charges required inside the configuration.

Charges shouldn't be treated as amounts bro.
Charges are charges. Simply that.

Let's say I have a scepter with 5 charges and each charge would allow me to cast a spell. I want to combine 2 of these scepters to make a stronger one. It would compile the first and make a better one because of the charges :/

As soon as this is fixed, I can approve this.
K will create a version which differentiates charges and actual item amount.
 
Top