Jonnycakes
New Member
- Reaction score
- 6
EDIT: Solved-the condition line was wrong and created an infinitely recurring trigger call.
I am working on an item stacking trigger, and got it to work fine...until a hero's inventory is full. Now I am trying to work around that, and have made dummy 'tome/powerup' items for every charged item in my map. I added a function that replaces the dummy item with a real item (with appropriate number of charges) when a dummy is picked up. Whenever I pick up a dummy item though, all that happens is that the dummy item is removed. In fact, I set up some BJDebug messages that seem to contradict themselves. Here is my trigger, with some comments about the debug messages. This is driving me insane...what is happening?
Ah, one last note...the IDs of the stackable dummy items range from 'I00E' to 'I00Z' and the IDs of the real items range from 'I02E' to 'I02Z'. The ID for a flare (the item I am using to test the trigger) is 'I00L' ('I02L').
I am working on an item stacking trigger, and got it to work fine...until a hero's inventory is full. Now I am trying to work around that, and have made dummy 'tome/powerup' items for every charged item in my map. I added a function that replaces the dummy item with a real item (with appropriate number of charges) when a dummy is picked up. Whenever I pick up a dummy item though, all that happens is that the dummy item is removed. In fact, I set up some BJDebug messages that seem to contradict themselves. Here is my trigger, with some comments about the debug messages. This is driving me insane...what is happening?
Ah, one last note...the IDs of the stackable dummy items range from 'I00E' to 'I00Z' and the IDs of the real items range from 'I02E' to 'I02Z'. The ID for a flare (the item I am using to test the trigger) is 'I00L' ('I02L').
JASS:
scope itemstack initializer init
private function conditions takes nothing returns boolean
return GetItemCharges(GetManipulatedItem())!=0
endfunction
private function main takes unit u, item picked, real x, real y returns nothing
local integer i=0
local integer id=GetItemTypeId(picked)
local item temp
local integer level=GetItemLevel(picked)
local integer charges=GetItemCharges(picked)
local integer chargestemp
local boolean boo=UnitAddItem(u, picked)
loop
exitwhen i>5
set temp=UnitItemInSlot(u, i)
set chargestemp=GetItemCharges(temp)
if GetItemTypeId(temp)==id and chargestemp<level and temp!=picked then
if chargestemp+charges>level then
call SetItemCharges(picked, chargestemp+charges-level)
call SetItemCharges(temp, level)
set charges=GetItemCharges(picked)
else
call SetItemCharges(temp, charges+chargestemp)
call RemoveItem(picked)
set charges=0
endif
endif
set i=i+1
endloop
if charges>0 and not boo then
call RemoveItem(picked)
call CreateItem(id-512, x, y)
endif
set u=null
set picked=null
set temp=null
endfunction
private function actions takes nothing returns nothing
local unit u=GetTriggerUnit()
local item pick=GetManipulatedItem()
local integer id=GetItemTypeId(pick)
local integer charges=GetItemCharges(pick)
local real x=GetItemX(pick)
local real y=GetItemY(pick)
if not (id>=039;I00E039; and id<=039;I00Z039;) then//this message always shows...
call BJDebugMsg("Error: Invalid item type for stacking.")
endif
if not (039;I00L039;>=039;I00E039;) then//and these ones never show...
call BJDebugMsg("less")
elseif not (039;I00L039;<=039;I00Z039;) then
call BJDebugMsg("more")
endif
if id==039;I00L039; then//even though this one also shows when you pick up a flare (item id 'I00L')...what???
call BJDebugMsg("this is a flare")
endif
call RemoveItem(pick)
set pick=CreateItem(id+512, x, y)//I set up my item ids so that the 'real' item id is 'I02<X>' when the dummy's is 'I00<X>'
call SetItemCharges(pick, charges)
call main(u, pick, x, y)
set u=null
set pick=null
endfunction
//===========================================================================
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
local integer i=0
loop
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
set i=i+1
exitwhen i==8
endloop
call TriggerAddCondition(t, Condition(function conditions))
call TriggerAddAction(t, function actions)
endfunction
endscope