On Change Item Position event?

Executor

I see you
Reaction score
57
I think this works. Check it out.

JASS:
library TestArea initializer TestInit

    private function onTest takes nothing returns boolean
        local unit      carrier         = null
        local item      orderedItem     = null
        local integer   destSlot        = GetIssuedOrderId()-852002
        local integer   currSlot        = 0
        local item      destItem        = null
        if destSlot > 5 or destSlot < 0 then  // no item is moved
            return false
        endif
        set orderedItem = GetOrderTargetItem()
        set carrier     = GetTriggerUnit()
        loop // find out in which slot the item is
            exitwhen currSlot > 5 or UnitItemInSlot(carrier,currSlot) == orderedItem        
            set currSlot = currSlot + 1
        endloop
        if currSlot > 5 then // item is not in inventory (shouldn't be possible)
            set carrier     = null
            set orderedItem = null
            return false
        else
            set destItem = UnitItemInSlot(carrier,destSlot)
        endif
        
        call BJDebugMsg("New ItemMove Order:")
        if destItem == null then
            call BJDebugMsg(GetUnitName(carrier) + " moves " + GetItemName(orderedItem) + " from slot " + I2S(currSlot+1) + " to slot " + I2S(destSlot+1) + "!")
        else
            call BJDebugMsg(GetUnitName(carrier) + " swaps " + GetItemName(orderedItem) + " from slot " + I2S(currSlot+1) + " with " + GetItemName(destItem) + " in slot " + I2S(destSlot+1) + "!")
        endif
        
        set carrier     = null
        set orderedItem = null
        set destItem    = null
        return false
    endfunction

    private function TestInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
        call TriggerAddCondition(t,Condition(function onTest))
    endfunction
endlibrary


Btw. is this worth a snippet?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top