HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Moving Items Around

07-03-2006, 06:50 AM#1
Pheonix-IV
Yes, i did run a search first.

Now, its probably been asked before and i probably missed it. But is it possible to move items around inside the heros inventory (Say i have "Boots of Speed" in slot 1, i want to use triggers to move it to slot 5.) If so, how?
07-03-2006, 07:24 AM#2
Anvilsmith
The crudest way would be to use RemoveItemFromSlot and AddItemToSlot.

function swapitems takes unit u, integer s1, integer s2 returns nothing
local item i1 = UnitRemoveItemFromSlot(u,s1 - 1)
local item i2 = UnitRemoveItemFromSlot(u,s2 - 1)

call UnitAddItemToSlot(u,GetItemTypeId(i2),s1 - 1)
call UnitAddItemToSlot(u,GetItemTypeId(i1),s2 - 1)

//Not sure if items are dropped when removed, but...
call RemoveItem(i1)
call RemoveItem(i2)
set i1 = null
set i2 = null
endfunction
07-03-2006, 07:39 AM#3
Naakaloh
Quote:
Originally Posted by PitzerMike (Warcraft III Ability Guide)
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.
07-03-2006, 08:13 AM#4
The)TideHunter(
Naakaloh is very right, the actual orders are much better than adding and removing.
If you remove then add, things change, spells could be effected etc. But moving them never effects.
I just made some lines of code which would work for this situation.
Im not sure if works yet, im going to go and try it out.

Collapse JASS:
function MoveItemSlot takes unit MovingUnit, integer CurrentItemSlot, integer NewItemSlot returns nothing
    if(NewItemSlot == 1) then
        call IssueTargetOrderById(MovingUnit, 852002, UnitItemInSlot(MovingUnit, CurrentItemSlot))
    elseif(NewItemSlot == 2) then
        call IssueTargetOrderById(MovingUnit, 852003, UnitItemInSlot(MovingUnit, CurrentItemSlot))
    elseif(NewItemSlot == 3) then
        call IssueTargetOrderById(MovingUnit, 852004, UnitItemInSlot(MovingUnit, CurrentItemSlot))
    elseif(NewItemSlot == 4) then
        call IssueTargetOrderById(MovingUnit, 852005, UnitItemInSlot(MovingUnit, CurrentItemSlot))
    elseif(NewItemSlot == 5) then
        call IssueTargetOrderById(MovingUnit, 852006, UnitItemInSlot(MovingUnit, CurrentItemSlot))
    elseif(NewItemSlot == 6) then
        call IssueTargetOrderById(MovingUnit, 852007, UnitItemInSlot(MovingUnit, CurrentItemSlot))
    endif 
endfunction
07-03-2006, 10:11 AM#5
Pheonix-IV
Double post FTW!

This thread can be closed, it turns out what i was going to try and do won't work anyway.
07-03-2006, 10:22 AM#6
Anitarf
Double post deleted. Also, The)TideHunter(, that function can be made a lot simpler.

Collapse JASS:
function MoveItemSlot takes unit movingUnit, integer currentItemSlot, integer newItemSlot returns nothing
        call IssueTargetOrderById(MovingUnit, 852001+newItemSlot, UnitItemInSlot(movingUnit, currentItemSlot))
endfunction
07-03-2006, 10:33 AM#7
PipeDream
Usually we index slots from zero, too.
07-03-2006, 11:32 AM#8
The)TideHunter(
Quote:
Originally Posted by Anitarf
Collapse JASS:
function MoveItemSlot takes unit movingUnit, integer currentItemSlot, integer newItemSlot returns nothing
        call IssueTargetOrderById(MovingUnit, 852001+newItemSlot, UnitItemInSlot(movingUnit, currentItemSlot))
endfunction

Ah yea, that would be MUCH better. Good thinking.
07-03-2006, 12:33 PM#9
shadow1500
There's a native for that -.-
Collapse JASS:
native UnitDropItemSlot takes unit whichUnit,item whichItem,integer slot returns boolean
07-03-2006, 12:44 PM#10
The)TideHunter(
That drops a item in a slow to the ground though, dosent it?
If it does, hes asking how to change a item thats in 1 slot to another.
If not, i stand corrected
07-03-2006, 01:09 PM#11
shadow1500
You stand corrected (as always), this function asks the slot AND the item, so it couldnt be what you said. There's a native that drops item from slot though, just like you said.
Collapse JASS:
native UnitRemoveItemFromSlot takes unit whichUnit,integer itemSlot returns item
07-03-2006, 01:13 PM#12
The)TideHunter(
Quote:
Originally Posted by shadow1500
You stand corrected (as always)

All lies! i swear!