• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] A basic recipe item system

Status
Not open for further replies.
Level 9
Joined
Oct 11, 2009
Messages
477
Could someone tell me on how to create a multi-item recipe system? For example: Monkey King Bar(Requires: 2 Javelin, Demon Edge). I want to know on how to detect 2 Javelins because I only know how to detect one item. Thanks in advance!:grin::grin::grin:
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Set ItemCounter = 0
      • For each (Integer A) from 1 to (Size of inventory for YourUnit), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by YourUnit in slot (Integer A))) Equal to Claws of Attack +15
            • Then - Actions
              • Set ItemCounter = (ItemCounter + 1)
            • Else - Actions
      • -------- Now the variable ItemCounter will refer to the amount of items of type "Blades of Attack +15" in YourUnit's inventory. --------
 
Level 9
Joined
Oct 11, 2009
Messages
477
  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Set ItemCounter = 0
      • For each (Integer A) from 1 to (Size of inventory for YourUnit), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by YourUnit in slot (Integer A))) Equal to Claws of Attack +15
            • Then - Actions
              • Set ItemCounter = (ItemCounter + 1)
            • Else - Actions
      • -------- Now the variable ItemCounter will refer to the amount of items of type "Blades of Attack +15" in YourUnit's inventory. --------

Yes, I tried that but it leaks. Could you provide an another one? Because last month I saw a tutorial about that at http://thehelper.net/ but a while, its gone, maybe it was deleted or whatsoever. Anyway a bit thanks for the effort...:thumbs_up:
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
What are you talking about, the trigger I posted does not leak. If you convert it to custom script, it looks like:

JASS:
function Trig_Untitled_Trigger_001_Func002Func001C takes nothing returns boolean
    if ( not ( GetItemTypeId(UnitItemInSlotBJ(udg_YourUnit, GetForLoopIndexA())) == 'ratf' ) ) then
    // ---
    // The above statement is simplified (strictly native functions) to:
  //if ( not ( GetItemTypeId(UnitItemInSlot(udg_YourUnit, bj_forLoopAIndex-1))   == 'ratf' ) ) then
  
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    set udg_ItemCounter = 0
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = UnitInventorySizeBJ(udg_YourUnit)
    // ---
    // The above statement simplifies (strictly native functions) to:
  //set bj_forLoopAIndexEnd = UnitInventorySize(udg_YourUnit)
    
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Untitled_Trigger_001_Func002Func001C() ) then
            set udg_ItemCounter = ( udg_ItemCounter + 1 )
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction

I've shown you the break-down of the BJ functions, there is nothing in here that causes memory leaks.
 
Level 9
Joined
Oct 11, 2009
Messages
477
What are you talking about, the trigger I posted does not leak. If you convert it to custom script, it looks like:

JASS:
function Trig_Untitled_Trigger_001_Func002Func001C takes nothing returns boolean
    if ( not ( GetItemTypeId(UnitItemInSlotBJ(udg_YourUnit, GetForLoopIndexA())) == 'ratf' ) ) then
    // ---
    // The above statement is simplified (strictly native functions) to:
  //if ( not ( GetItemTypeId(UnitItemInSlot(udg_YourUnit, bj_forLoopAIndex-1))   == 'ratf' ) ) then
  
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    set udg_ItemCounter = 0
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = UnitInventorySizeBJ(udg_YourUnit)
    // ---
    // The above statement simplifies (strictly native functions) to:
  //set bj_forLoopAIndexEnd = UnitInventorySize(udg_YourUnit)
    
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Untitled_Trigger_001_Func002Func001C() ) then
            set udg_ItemCounter = ( udg_ItemCounter + 1 )
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction

I've shown you the break-down of the BJ functions, there is nothing in here that causes memory leaks.

But why did I experience like disability of triggers or somewhat?, for example: I bought 2 Javelins and a Demon Edge for the first try and the item-type Monkey King Bar is formed, but when I tried it on the second time, even if I completed the item requirements, the trigger doesn't create any Monkey King Bar and the required items are not removed.
 
Status
Not open for further replies.
Top