• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

How to switch position of two items in inventory?

Status
Not open for further replies.
Level 12
Joined
Mar 26, 2005
Messages
790
Y'know, I have normal inventory, but in some moment, I want change the position of two items in inventory (e.g. I have sword in slot 4 and helm in slot 6) and I want to switch them, that the sword will be in 6 and helm in 4. (but I dont know their position before, this is just an example, they can be in whatever position)


So I need first to "check" in what position is some type of item and then the second one, and then just delete them, and recreate them, but in their new places.

But I just didnt find the way to make the first step (aka to "check" their positions)
 
I just made this in 5 minutes so you could probably make this better, but here.

  • Untitled Trigger 001
    • Events
    • Conditions
      • ((Load 0 of 1 in (Last created hashtable)) has an item of type Claws of Attack +15) Equal to True
      • ((Load 0 of 1 in (Last created hashtable)) has an item of type Crown of Kings +5) Equal to True
    • Actions
      • Item - Remove (Item carried by (Load 0 of 1 in (Last created hashtable)) of type Claws of Attack +15)
      • Item - Remove (Item carried by (Load 0 of 1 in (Last created hashtable)) of type Crown of Kings +5)
      • Hero - Create Claws of Attack +15 and give it to (Load 0 of 1 in (Last created hashtable))
      • Unit - Order (Load 0 of 1 in (Last created hashtable)) to move (Last created item) to inventory slot 4
      • Hero - Create Crown of Kings +5 and give it to (Load 0 of 1 in (Last created hashtable))
      • Unit - Order (Load 0 of 1 in (Last created hashtable)) to move (Last created item) to inventory slot 6
 
There is a direct way to do this.
Let me quote this tutorial:
852002 to 852007 (moveslot): These are item targeted orders that move the target item to a certain inventory slot of the ordered hero. The id 852002 will move it to slot 1, the id 852003 will move it to slot 2 and so on.

So this would move the second item to the third slot:
JASS:
call IssueTargetOrderById(some_unit, 852004, UnitItemInSlot(some_unit, 1))

That's for swapping, ofc. It's better than to destroy and re-create the items.
e: I see, the actually is a gui-function for this. And another native to do this
JASS:
call UnitDropItemSlot(some_unit, UnitItemInSlot(some_unit, 1), 2)

Finding the items is simple: just loop throuh the inventory and check if the item in slot n is the item you look for.
 
Last edited:
Status
Not open for further replies.
Back
Top