Warcraft III resources & community, 2003–2006 · archived

MakeItemUndroppable

not rated
Submitted by shadow1500Functions0 downloads
will prevent the unit from dropping the item while still allowing drag and dropping.
useful for a UI buttons on the hero inventory.
requires
-Handle Variables
-GetItemSlot function (below this JASS Script)
-GetHandleTriggerAction (Included)

usage:
MakeItemUndroppable2 takes unit whichUnit, item whichItem, boolean sameslot
whichUnit is the unit that will not be able to drop the item
whichItem is the item that cannot be dropped
sameslot true to prevent the item from switching slots when dropped, shud be true in most cases.
MakeItemDroppable2 takes unit whichUnit, item whichItem
this function will allow the unit to drop the item again

Source

function GetHandleTriggerAction takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function MakeItemUndroppable2_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t,"u")
    local item i = GetHandleItem(t,"i")
    local integer s = GetHandleInt(t,"s")
    call UnitAddItem(u,i)
    if s != 0 then
        call SetHandleInt(i,"g",1)
        call UnitDropItemSlotBJ(u,i,s)
        call SetHandleInt(i,"g",0)
    endif
    set u = null
    set i = null
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set t = null
endfunction


function MakeItemUndroppable2_Actions takes nothing returns nothing
    local trigger x = GetTriggeringTrigger()
    local timer t = CreateTimer()
    if GetManipulatedItem() == GetHandleItem(x,"i") then
        call SetHandleHandle( t, "u", GetTriggerUnit())
        if GetHandleInt(x,"s") == 1 then
            call SetHandleInt(t, "s", GetItemSlot( GetTriggerUnit(),GetManipulatedItem() ) )
        endif
        call SetHandleHandle(t, "i", GetManipulatedItem())
        call TimerStart(t,0,false,function MakeItemUndroppable2_Timer)
    else
        call DestroyTimer(t)
    endif
    set t = null
endfunction
function MakeItemUndroppable2 takes unit whichUnit, item whichItem, boolean sameslot returns nothing
    local trigger x = CreateTrigger()
    call SetHandleHandle(x,"i",whichItem)
    if sameslot then
        call SetHandleInt(x,"s",1)
    endif
    call TriggerRegisterUnitEvent( x, whichUnit,EVENT_UNIT_DROP_ITEM)
    call SetHandleHandle(x,"a", TriggerAddAction( x, function MakeItemUndroppable2_Actions ))
    call SetHandleHandle(whichItem,"droptrg",x)
    set x = null
endfunction
function MakeItemDroppable2 takes unit whichUnit, item whichItem returns nothing
    local trigger x = GetHandleTrigger(whichItem,"droptrg")
    call SetHandleHandle(whichItem,"droptrg",null)
    call TriggerRemoveAction(x,GetHandleTriggerAction(x,"a"))
    call FlushHandleLocals(x)
    call DestroyTrigger(x)
    set x = null
endfunction

Comments

1
dont ask me to add any comments to this since its almost the same thing as the script above.