globals
timer t
rect r
unit tempUnit=null
endglobals
hook CreateItemLoc CreateItemLocEx //1
hook UnitAddItemByIdSwapped UnitAddItemByIdSwappedEx //2
hook CreateItem CreateItemEx //3
hook UnitAddItemById UnitAddItemByIdEx //4
hook UnitAddItemToSlotById UnitAddItemToSlotByIdEx //5
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//these 2 for demo only
function IsItemIndexed takes item i returns boolean
return GetItemUserData(i)>0
endfunction
function IndexItem takes item i returns nothing
call SetItemUserData(i, 1)
endfunction
//-------------------------------------------------------------------
function CreateItem1 takes nothing returns item
call BJDebugMsg(GetItemName(bj_lastCreatedItem))
return bj_lastCreatedItem
endfunction
//-------------------1-------------------------------------------------------------
function CreateItemLocEx takes integer itemId, location loc returns nothing
call TimerStart(t, 0.00, false, function CreateItem1)
endfunction
//-------------------2-------------------------------------------------------------
function UnitAddItemByIdSwappedEx takes integer itemId, unit whichHero returns nothing
call TimerStart(t, 0.00, false, function CreateItem1)
endfunction
//-------------------3-------------------------------------------------------------
function EnumItm takes nothing returns nothing
local item i = GetEnumItem()
if not IsItemIndexed(i) then
call IndexItem(i)
call BJDebugMsg("indexing item: " + GetItemName(i))
endif
set i=null
endfunction
function SearchInRect takes nothing returns nothing
call EnumItemsInRect(r, null, function EnumItm)
endfunction
function CreateItemEx takes integer itemid, real x, real y returns nothing
call MoveRectTo(r, x, y)
call TimerStart(t, 0.00, false, function SearchInRect)
endfunction
//-------------------4-------------------------------------------------------------
function SearchOnUnitThenInRect takes nothing returns nothing
local integer x=0
loop
if not IsItemIndexed(UnitItemInSlot(tempUnit, x)) then
call IndexItem(UnitItemInSlot(tempUnit, x))
call BJDebugMsg("indexing item: " + GetItemName(UnitItemInSlot(tempUnit, x)) + " in slot " + I2S(x))
return
endif
set x=x+1
exitwhen x==bj_MAX_INVENTORY
endloop
//if non-indexed item not found on "tempUnit" unit (inventory may be full) then look at the ground
call EnumItemsInRect(r, null, function EnumItm)
endfunction
function UnitAddItemByIdEx takes unit whichUnit, integer itemId returns nothing
call MoveRectTo(r, GetUnitX(whichUnit), GetUnitY(whichUnit))
set tempUnit=whichUnit
call TimerStart(t, 0.00, false, function SearchOnUnitThenInRect)
endfunction
//-------------------5-------------------------------------------------------------
function UnitAddItemToSlotByIdEx takes unit whichUnit, integer itemId, integer itemSlot returns nothing
call UnitAddItemByIdEx(whichUnit, itemId)
endfunction
//===========================================================================
function InitTrig_func takes nothing returns nothing
set t=CreateTimer()
set r=Rect(0.00, 0.00, 256.00, 256.00)
endfunction