Warcraft III resources & community, 2003–2006 · archived

MakeItemUnmovable

not rated
Submitted by shadow1500Functions0 downloads
same as MakeItemUndroppable except that it will prevent the item from being moved throughout the inventory.
This requires the handle variables by Kattana

Source

function GetHandleTriggerAction takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function MakeItemUnmovable_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 SetHandleInt(i,"g",1) //use this handlevar to find w/e or not the item was moved by the function
    call UnitDropItemSlotBJ(u,i,s)
    call SetHandleInt(i,"g",0)
    set u = null
    set i = null
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set t = null
endfunction


function MakeItemUnmovable_Actions takes nothing returns nothing
    local trigger x = GetTriggeringTrigger()
    local timer t = CreateTimer()
    local integer g = GetHandleInt(GetOrderTargetItem(),"g")
    if not (GetIssuedOrderId() >= 852002) and (GetIssuedOrderId() <= 852007) then
       call DestroyTimer(t)
       set t = null
       return
    endif
    //above if statment finds if the order was a drag and drop order (between 852002-852007 depending on slot)
    if GetOrderTargetItem() == GetHandleItem(x,"i") and g == 0 then
        //if the drag n dropped item matches the one that the trigger should lock then
        // it will get moved back to its previous slot
        call SetHandleHandle( t, "u", GetTriggerUnit())
        call SetHandleInt(t, "s", GetItemSlot(GetTriggerUnit(),GetOrderTargetItem()) )
        call SetHandleHandle(t, "i", GetOrderTargetItem())
        call TimerStart(t,0,false,function MakeItemUnmovable_Timer)
    else
        call DestroyTimer(t)
    endif
    set t = null
endfunction
function MakeItemUnmovable takes unit whichUnit, item whichItem returns nothing
    local trigger x = CreateTrigger()
    call SetHandleHandle(x,"i",whichItem)
    call TriggerRegisterUnitEvent( x, whichUnit,EVENT_UNIT_ISSUED_TARGET_ORDER)
    call SetHandleHandle(x,"a", TriggerAddAction( x, function MakeItemUnmovable_Actions ))
    call SetHandleHandle(whichItem,"droptrg",x)
    set x = null
endfunction
function MakeItemMovable takes unit whichUnit, item whichItem returns nothing
    local trigger x = GetHandleTrigger(whichItem,"droptrg")
    //this function simply destroyes the trigger thats responisble for the locking of the item
    call SetHandleHandle(whichItem,"droptrg",null)
    call TriggerRemoveAction(x,GetHandleTriggerAction(x,"a"))
    call FlushHandleLocals(x)
    call DestroyTrigger(x)
    set x = null
endfunction

Comments

4
UPDATE: Added comments by request

Their is so many JASS on this site I could use but it neaver says what variables you need

in the documentation provided by the other function (MakeItemUndropable) u wud see that it requires the handle vars.

btw u shud use those two functions together if ur planning on making a drag n drop system.
Their is so many JASS on this site I could use but it neaver says what variables you need :(
Comments would be very good.
Comments are a sign of intelligence.
Comments help everybody understanding your code and not just using it.
Comments are worth adding them.

So I suggest you to add comments anyways.
You should consider adding comments to this code.