function Trig_Setting_Owner_Actions takes nothing returns nothing
local integer i=0
loop
exitwhen GetBooleanOr(udg_Item[i]==null,i>udg_Item_Max)
set i=i+1
endloop
if i>udg_Item_Max then
call BJDebugMsg("|cffff0000Error:|rItem limit reached. Item-Owner-Detection failed.")
call BJDebugMsg("|cffff0000Error:|rThe author of the map should increase this value.")
return
endif
set udg_Item[i]=GetSoldItem()
set udg_Item_Owner[i]=GetOwningPlayer(GetBuyingUnit())
endfunction
//===========================================================================
function InitTrig_Setting_Owner takes nothing returns nothing
set gg_trg_Setting_Owner = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Setting_Owner, EVENT_PLAYER_UNIT_SELL_ITEM )
call TriggerAddAction( gg_trg_Setting_Owner, function Trig_Setting_Owner_Actions )
endfunction
function Trig_Removing_Owner_Actions takes nothing returns nothing
local integer i=0
loop
exitwhen GetBooleanOr(udg_Item[i]==GetSoldItem(),i>udg_Item_Max)
set i=i+1
endloop
if i>udg_Item_Max then
return
endif
set udg_Item[i]=null
set udg_Item_Owner[i]=null
endfunction
//===========================================================================
function InitTrig_Removing_Owner takes nothing returns nothing
set gg_trg_Removing_Owner = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Removing_Owner, EVENT_PLAYER_UNIT_PAWN_ITEM )
call TriggerAddAction( gg_trg_Removing_Owner, function Trig_Removing_Owner_Actions )
endfunction
function GetFakeItem takes item i returns integer
if GetBooleanOr(GetItemTypeId(i) == 'I000',GetItemTypeId(i) == 'I001') then
return 'I000'
endif
call BJDebugMsg("|cffff0000Error:|r Item Database doesn't fit with target item.")
return 'texp'
endfunction
function GetRealItem takes item i returns integer
if GetBooleanOr(GetItemTypeId(i) == 'I000',GetItemTypeId(i) == 'I001') then
return 'I001'
endif
call BJDebugMsg("|cffff0000Error:|r Item Database doesn't fit with target item.")
return 'texp'
endfunction
//===========================================================================
function Trig_Getting_Owner_Actions takes nothing returns nothing
local integer i
local unit u=GetTriggerUnit()
local integer itemid
loop
exitwhen GetBooleanOr(udg_Item[i]==GetManipulatedItem(),i>udg_Item_Max)
set i=i+1
endloop
if i>udg_Item_Max then
return
endif
if udg_Item_Owner[i]!=GetOwningPlayer(u) then
set itemid=GetFakeItem(GetManipulatedItem())
else
set itemid=GetRealItem(GetManipulatedItem())
endif
call RemoveItem(GetManipulatedItem())
call UnitAddItemById(u,itemid)
set udg_Item[i]=GetLastCreatedItem()
set u=null
endfunction
//===========================================================================
function InitTrig_Getting_Owner takes nothing returns nothing
set gg_trg_Getting_Owner = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Getting_Owner, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_Getting_Owner, function Trig_Getting_Owner_Actions )
endfunction
Event - A Unit Acquires an Item
Actions:
if custom value of (item) == 0 then
set custom value of (item) to player number of (owner of hero manipulating item)
if custom value of (item) != player number of (owner of hero manipulating item) then
drop (item being manipulated) from (hero manipulating item)
exitwhen udg_Item[i] == null or i > udg_Item_Max