Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Problem!! Need Some Help

Discussion in 'World Editor Help Zone' started by Dual-Cross, Oct 20, 2009.

  1. Dual-Cross

    Dual-Cross

    Joined:
    Apr 10, 2009
    Messages:
    38
    Resources:
    0
    Resources:
    0
    Hello! Is there an event that gets triggered when you swap items in a heroes inventory. Similar to EVENT_PLAYER_UNIT_DROP_ITEM and EVENT_PLAYER_UNIT_PICKUP_ITEM, looking for something like EVENT_PLAYER_UNIT_SWAP_ITEM which doesn't exist ( in that form at any rate).

    Any Ideas?
     
  2. Dark_Axl

    Dark_Axl

    Joined:
    Dec 12, 2007
    Messages:
    472
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    I think there are no event to detect item swap
    but, you could detect the orderId
    if i'm not wrong.... hehe:grin:
     
  3. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    Yes, use order ids. The ids are 852002 to 852007, or 852002 + i, where i is the slot index. Note that because these are orders, at the time the trigger actions are run the item has not been moved yet.
     
  4. Dual-Cross

    Dual-Cross

    Joined:
    Apr 10, 2009
    Messages:
    38
    Resources:
    0
    Resources:
    0
    cool thanks =D

    i really needed it because im storing the item type id's in an array for each players heroes. ItemID[12][6]. I noticed it wasnt updating when i swapped the items !! Which would break things.
     
  5. Dual-Cross

    Dual-Cross

    Joined:
    Apr 10, 2009
    Messages:
    38
    Resources:
    0
    Resources:
    0
    So after you telling me about orderID's i came up with this function to swap the item types in the cache. Is there a more efficient way to do this , or am i using orderID's correctly?

    Code (vJASS):
    private function UpdateCacheO_Condition takes nothing returns boolean
    if GetIssuedOrderId() >= 852002 and GetIssuedOrderId() <= 852007 then
    return true
    endif
    return false
    endfunction

    private function WhichSlot takes unit wu, item wi returns integer
    local integer i=0
    local item it
    loop
        exitwhen i==6
        if wi == UnitItemInSlot(wu,i) then
            return i
        set i=5
        endif
        set i=i+1
        endloop
    return 7
    endfunction

    private function UpdateCacheO takes nothing returns nothing
    local integer Slot1 //Destination
    local integer Slot2 //Source
    local integer Medium //Medium
    local unit OrderedUnit = GetOrderedUnit()
    local item OrderedItem = GetOrderTargetItem()
    local integer OwningPlayer = GetPlayerId(GetOwningPlayer(OrderedUnit))
    set Slot1 = GetIssuedOrderId() - 852002
    set Slot2 = WhichSlot(OrderedUnit,OrderedItem)
    set Medium = SlotCache[OwningPlayer][Slot1]
    set SlotCache[OwningPlayer][Slot1] = SlotCache[OwningPlayer][Slot2]
    set SlotCache[OwningPlayer][Slot2] = Medium
    set OrderedUnit = null
    set OrderedItem = null
    endfunction
     
  6. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,220
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    You are doing it right.