Hello, Bond009, here is how to do what you're after.
In the Map Initialization, save "true" to the items' raw ids, that you do not wish to be dropped after the effect, e.g.
Custom script: call SaveBoolean (udg_M_Hash, 'I000', StringHash("cannotbedropped"), true)
When the ownership should be switched back, there's a block already in the script (function EndDuration):
loop
exitwhen i > i1
call SetItemDroppable (UnitItemInSlot (u, i), true)
set i = i + 1
endloop
change it to:
local item it
loop
exitwhen i > i1
set it = UnitItemInSlot (u,i)
if not LoadBoolean (udg_M_Hash, GetItemTypeId (it), StringHash("cannotbedropped")) then
call SetItemDroppable (UnitItemInSlot (u, i), true)
endif
set i = i + 1
set it = null
endloop
Don't touch anything else from the function, only apply the mentioned changes.