• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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)
 
Level 11
Joined
Aug 6, 2009
Messages
697
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
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
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.
Top