| 08-07-2005, 01:03 PM | #1 |
Is there an easier way to replace an item in a unit's inventory other than emptying all the slots up to the desired item's slot and then placing the new item there and moving all the old items back in reverse order? This way requires a lot of item manipulation that I would rather not have to mess with. |
| 08-07-2005, 04:56 PM | #2 |
um, yeah? add this function to the top of your map Code:
function GetItemSlot takes unit u, item it returns integer
local integer i=0
loop
exitwhen i==6
if(UnitItemInSlot(u,i)==it)then
return i
endif
set i=i+1
endloop
return -1
endfunctionThen call this sequence, local integer slot=GetItemSlot(hero,ItemIwantToRePlace) call RemoveItem(slot) call UnitAddItemToSlotById(hero,itemtypetoadd,slot) |
