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

Move item to specific inventory slot

Status
Not open for further replies.
Level 12
Joined
May 22, 2015
Messages
1,051
I have this item that you throw and then can pick up off the ground. It's all working well, but one thing bothers me. When you throw it and pick it up again, it goes to the first available slot. Is there some way I can tell it which slot to go to when the hero picks it up? This would allow me to keep the slot the same so that the hotkey is consistent.

I already found a way to detect which slot was last used for the item. I don't need help for that part. I just need to know how to take an item and move it to a specific slot in a hero's inventory.

I use JASS, so JASS or GUI solution is good. Thanks in advance!
 
Level 14
Joined
Nov 30, 2013
Messages
926
I have this item that you throw and then can pick up off the ground. It's all working well, but one thing bothers me. When you throw it and pick it up again, it goes to the first available slot. Is there some way I can tell it which slot to go to when the hero picks it up? This would allow me to keep the slot the same so that the hotkey is consistent.

I already found a way to detect which slot was last used for the item. I don't need help for that part. I just need to know how to take an item and move it to a specific slot in a hero's inventory.

I use JASS, so JASS or GUI solution is good. Thanks in advance!

You could remove the item then readded it by using this.
JASS:
native UnitAddItemToSlotById takes unit whichUnit, integer itemId, integer itemSlot returns boolean
However, I'm unsure how that works.
 
Level 12
Joined
May 22, 2015
Messages
1,051
You could remove the item then readded it by using this.
JASS:
native UnitAddItemToSlotById takes unit whichUnit, integer itemId, integer itemSlot returns boolean
However, I'm unsure how that works.

Ya this is what I used in my hacky version. It didn't end up working, but maybe my code is bad. I didn't have time to thoroughly test it yet.

The part that sucks is that it doesn't even return the item handle like other Create... functions. I had to search the inventory to get the item again rofl.

I should add that the item can have variable charges and the hero could have an item in that slot already. I don't know if those will cause problems. I already accounted for the charges by storing it before I remove the item.

Maybe I can just check if there is an item in that slot first. If there is, then do nothing. Otherwise, I can add the item like this and assume the item in that slot is the correct one. I still didn't manage to get the item in that slot, though (potentially due to faulty code).

I'll definitely take another crack at it tonight.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
native UnitDropItemSlot takes unit whichUnit, item whichItem, integer slot returns boolean
This function probably doesn't work for paused units, as it orders the unit to move the item into the desired slot.
In case the desired slot is full, the item in that slot changes places with item "whichItem".
 
Level 12
Joined
May 22, 2015
Messages
1,051
lmao so that's the native to do this? DropItemSlot makes it sound like they drop the item in the slot on the ground, though the parameters wouldn't need an item then. I'll test it out later tonight :D
 

Ardenian

A

Ardenian

Do you start with 0 as slot number ?
Appearently item slots are 0-5, not 1-6

i want it too but can you covert it into trigger.

thanks! in advance
Use custom script for it.
A GUI trigger is nothing else than Jass in an alternative form.
 
Status
Not open for further replies.
Top