• 🏆 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!

Item slot detection

Status
Not open for further replies.
Level 4
Joined
May 14, 2018
Messages
34
Hi guys.
I'm making item bank spell which will give you item from n slot when you'll use it.
But i need to make trigger that will replace item in the same slot if inventory is full.
There is any way to detect in which slot was item-target of spell? Becouse i didn't find any solution.
Thx
 
Level 13
Joined
May 10, 2009
Messages
868
Blizzard didn't provide a direct function which returns the inventory slot of an item. Though, you can find that out by looping through a unit inventory and checking if a specific item is in slot X.
JASS:
// Returns the inventory slot for a specific item
function GetItemSlotPosition takes unit whichUnit, item whichItem returns integer
    local integer slot = -1
    local item itm = null
    local integer i = 0
    loop
        exitwhen i == bj_MAX_INVENTORY
        set itm = UnitItemInSlot(whichUnit, i)
        if itm == whichItem then
            set slot = i
            exitwhen true
        endif
        set i = i + 1
    endloop
    set itm = null
    return slot
endfunction
Now that function will do the job. However, in JASS inventory slots range from 0 to 5 whereas in GUI it's from 1 to 6. If you are using GUI only, then I suggest you add +1 to the return line.
return slot
->
return slot+1

Example:
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Whatever
  • Actions
    • Set WhichUnit = (Triggering unit)
    • Set TargetItem = (Target item of ability being cast)
    • Custom script: set udg_ItemSlot = GetItemSlotPosition(udg_WhichUnit, udg_TargetItem)
    • -------- Keep in mind the function above "GetItemSlotPos" ranges from 1 to 6 --------
    • Game - Display to (All players) the text: (Slot: + (String(ItemSlot)))
The attached map below was saved with the latest version which means older world editors won't be able to open it.
 

Attachments

  • FindSlot.w3x
    18 KB · Views: 18
Last edited:
Status
Not open for further replies.
Top