- Joined
- Apr 21, 2014
- Messages
- 21
Before anything else, I'd like to apologize for posting this knowing that this has been asked many times before. I've read the same topics in the past myself, but I have forgotten their titles. Now, I have the same problem:
Suppose I have a usable item that replaces it with another item. Item A is in slot no. 4, for example, and when clicked, Item B would replace it in the exact same inventory slot. However, for some reason the new item is always placed at the topmost left corner of the inventory. It works on an empty map, but not on mine.
This is the code on my empty test map, and it's the exact same (yes, even the item IDs just for the sake of testing it). However, it works exactly as intended on the empty map but not on my main map.
Please help. I've even tried calling out UnitAddItemToSlotById with a specific inventory number (calll UnitAddItemToSlotById(u, 'id', 4))but the new item would still pop out at the topmost left corner of the inventory. I've been trying to get around this for the past few days and nothing I've tried worked.
Suppose I have a usable item that replaces it with another item. Item A is in slot no. 4, for example, and when clicked, Item B would replace it in the exact same inventory slot. However, for some reason the new item is always placed at the topmost left corner of the inventory. It works on an empty map, but not on mine.
JASS:
function ItemReplace_C takes nothing returns boolean
return (GetItemTypeId(GetManipulatedItem()) == 'ratf') or (GetItemTypeId(GetManipulatedItem()) == 'ckng')
endfunction
function ItemReplace_A takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer index = 0
local integer max = 0
local integer id
local item i
local boolean off = false
loop
set i = UnitItemInSlot(u, index)
if (i == GetManipulatedItem()) then
if (GetItemTypeId(i) == 'ratf') then
set id = 'ckng'
elseif (GetItemTypeId(i) == 'ckng') then
set id = 'ratf'
endif
call RemoveItem(i)
call UnitAddItemToSlotById(u, id, index)
set off = true
endif
exitwhen index > 5 or off == true
set index = index + 1
endloop
set u = null
set i = null
endfunction
function InitTrig_item takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_USE_ITEM)
call TriggerAddCondition(trg, Condition(function ItemReplace_C))
call TriggerAddAction(trg, function ItemReplace_A)
set trg = null
endfunction
This is the code on my empty test map, and it's the exact same (yes, even the item IDs just for the sake of testing it). However, it works exactly as intended on the empty map but not on my main map.
Please help. I've even tried calling out UnitAddItemToSlotById with a specific inventory number (calll UnitAddItemToSlotById(u, 'id', 4))but the new item would still pop out at the topmost left corner of the inventory. I've been trying to get around this for the past few days and nothing I've tried worked.