• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Problem!! Need Some Help

Status
Not open for further replies.
Level 3
Joined
Apr 10, 2009
Messages
39
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?
 
Level 3
Joined
Apr 10, 2009
Messages
39
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.
 
Level 3
Joined
Apr 10, 2009
Messages
39
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?

JASS:
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
 
JASS:
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
You are doing it right.
 
Status
Not open for further replies.
Top