////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Item functions:
//
library ItemFunctions
//Checks if the given unit has items of the given types.
//Fill the parameters with 0 to have fewer required item types.
//Works with multiple items of the same type.
function UnitCheckItems takes unit whichUnit, integer i1, integer i2, integer i3, integer i4, integer i5, integer i6 returns boolean
local integer array heldItems
local integer array requestedItems
local integer index1
local integer index2
local integer requestedItemsLength = 6
set requestedItems[0] = i1
set requestedItems[1] = i2
set requestedItems[2] = i3
set requestedItems[3] = i4
set requestedItems[4] = i5
set requestedItems[5] = i6
set heldItems[0] = GetItemTypeId(UnitItemInSlot(whichUnit, 0))
set heldItems[1] = GetItemTypeId(UnitItemInSlot(whichUnit, 1))
set heldItems[2] = GetItemTypeId(UnitItemInSlot(whichUnit, 2))
set heldItems[3] = GetItemTypeId(UnitItemInSlot(whichUnit, 3))
set heldItems[4] = GetItemTypeId(UnitItemInSlot(whichUnit, 4))
set heldItems[5] = GetItemTypeId(UnitItemInSlot(whichUnit, 5))
set index1 = 0
loop
if requestedItems[index1] == 0 then
set requestedItemsLength = requestedItemsLength-1
set requestedItems[index1] = requestedItems[requestedItemsLength]
if requestedItemsLength == 0 then
return true
endif
endif
exitwhen index1 == 5
set index1 = index1 +1
endloop
set index1 = 0
loop
set index2 = 0
loop
exitwhen index2 >= requestedItemsLength
if heldItems[index1] == requestedItems[index2] then
set requestedItemsLength = requestedItemsLength-1
set requestedItems[index2] = requestedItems[requestedItemsLength]
if requestedItemsLength == 0 then
return true
endif
exitwhen true
endif
set index2 = index2 +1
endloop
exitwhen index1 == 5
set index1 = index1 +1
endloop
return false
endfunction
function UnitCountItemsOfType takes unit whichUnit, integer itemType returns integer
local integer result = 0
local integer i = 0
loop
exitwhen i >= 6
if GetItemTypeId(UnitItemInSlot(whichUnit, i)) == itemType then
set result = result +1
endif
set i = i +1
endloop
return result
endfunction
endlibrary
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Item functions:
//
library ItemFunctions initializer init
//Checks if the given unit has items of the given types.
//Fill the parameters with 0 to have fewer required item types.
//Works with multiple items of the same type.
function UnitCheckItems takes unit whichUnit, integer i1, integer i2, integer i3, integer i4, integer i5, integer i6 returns boolean
local integer array heldItems
local integer array requestedItems
local integer index1
local integer index2
local integer requestedItemsLength = 6
set requestedItems[0] = i1
set requestedItems[1] = i2
set requestedItems[2] = i3
set requestedItems[3] = i4
set requestedItems[4] = i5
set requestedItems[5] = i6
set heldItems[0] = GetItemTypeId(UnitItemInSlot(whichUnit, 0))
set heldItems[1] = GetItemTypeId(UnitItemInSlot(whichUnit, 1))
set heldItems[2] = GetItemTypeId(UnitItemInSlot(whichUnit, 2))
set heldItems[3] = GetItemTypeId(UnitItemInSlot(whichUnit, 3))
set heldItems[4] = GetItemTypeId(UnitItemInSlot(whichUnit, 4))
set heldItems[5] = GetItemTypeId(UnitItemInSlot(whichUnit, 5))
set index1 = 0
loop
if requestedItems[index1] == 0 then
set requestedItemsLength = requestedItemsLength-1
set requestedItems[index1] = requestedItems[requestedItemsLength]
if requestedItemsLength == 0 then
return true
endif
endif
exitwhen index1 == 5
set index1 = index1 +1
endloop
set index1 = 0
loop
set index2 = 0
loop
exitwhen index2 >= requestedItemsLength
if heldItems[index1] == requestedItems[index2] then
set requestedItemsLength = requestedItemsLength-1
set requestedItems[index2] = requestedItems[requestedItemsLength]
if requestedItemsLength == 0 then
return true
endif
exitwhen true
endif
set index2 = index2 +1
endloop
exitwhen index1 == 5
set index1 = index1 +1
endloop
return false
endfunction
function UnitCountItemsOfType takes unit whichUnit, integer itemType returns integer
local integer result = 0
local integer i = 0
loop
exitwhen i >= 6
if GetItemTypeId(UnitItemInSlot(whichUnit, i)) == itemType then
set result = result +1
endif
set i = i +1
endloop
return result
endfunction
/*globals
trigger udg_TriggerUnitCheckItems
unit udg_UnitCheckItems_Unit
itemtype array udg_UnitCheckItems_Items
endglobals*/
private function UnitCheckItemsHandler takes nothing returns boolean
local boolean b = UnitCheckItems(udg_UnitCheckItems_Unit, udg_UnitCheckItems_Items[0], udg_UnitCheckItems_Items[1], udg_UnitCheckItems_Items[2], udg_UnitCheckItems_Items[3], udg_UnitCheckItems_Items[4], udg_UnitCheckItems_Items[5])
set udg_UnitCheckItems_Items[0] = 0
set udg_UnitCheckItems_Items[1] = 0
set udg_UnitCheckItems_Items[2] = 0
set udg_UnitCheckItems_Items[3] = 0
set udg_UnitCheckItems_Items[4] = 0
set udg_UnitCheckItems_Items[5] = 0
return b
endfunction
private function init takes nothing returns nothing
set udg_TriggerUnitCheckItems = CreateTrigger()
call TriggerAddCondition(udg_TriggerUnitCheckItems, Filter(function UnitCheckItemsHandler))
endfunction
endlibrary
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
local integer a = 0
local integer b = 0
local integer c = 0
local integer d = 5
loop
exitwhen b == 6
if ( *Hero has an item of (What Item) on slot #(b) ) then
if ( a < (How many number of that item does it requires) ) then
a = a + 1
c = a
endif
endif
b = b + 1
endloop
//Item checking
**A unit acquired an item**
if (*Hero has an item of (The item from the recipe, not the item that requires 2 or more) then
if ( *Hero has an item of (The item that requires 2 or more.) ) ) then
if (a == (Number of that item that requires)) then
loop
if ( *Hero has an item of (Same Item) on slot #(d) ) then
**Remove the item from that slot**
c = c - 1
endif
d = d - 1
exitwhen c == 0
if ( c == 0 ) then
**Actions here**
endif
endloop
endif
endif
endif
Well remove the ; they are not needed unless you code in Zinc.
Otherwise it seems correct.
doesn't work.
if TriggerEvaluate(trig) then
Can you quote that solution please?Ah, I see.
Well that certainly seems like a lot of code compared to the other pure GUI solutions presented.
Seems != is.Your way may provide a better API but it seems like you use more function calls, maybe that's just an illusion the 'huge' code makes when compared to the GUI presented in this thread.
yes.
you can do it even in GUI.
i am new at triggers so i don't understand variable
plus you use jass for that and jass is uncopyable
So what the hex is this??
so jass is like in minecraft command block