- Joined
- Jan 18, 2012
- Messages
- 92
I just started fiddling around with the World Editor again and after getting used to putting 'call' keyword before functions again I ran into this problem. The function UnitAddItem works normally but in the code below it crashes the game. I don't have a clue as to why it is doing that as the pickup isn't null by the time it gets to the line where I'm calling the function. It still points to the item it should, but it crashes the game for some reason.
The code:
I've also attached the map file so you can test it yourselves.
Thanks in advance.
The code:
JASS:
function manageItems takes nothing returns nothing
local integer i = 0
local integer j = 0
local boolean willTake = true
local unit triggerer = GetTriggerUnit()
local item pickup = GetManipulatedItem()
call UnitRemoveItemSwapped(pickup, triggerer)
set pickup = bj_lastRemovedItem
if GetItemType(pickup) == ITEM_TYPE_ARTIFACT then
loop
if GetItemType(UnitItemInSlot(triggerer, i)) == ITEM_TYPE_ARTIFACT then
call DisplayTextToPlayer(GetOwningPlayer(triggerer), 0.0, 0.0, GetUnitName(triggerer) + " can only carry one weapon.")
set willTake = false
endif
set i = i + 1
exitwhen i >= bj_MAX_INVENTORY
endloop
elseif GetItemType(pickup) == ITEM_TYPE_CAMPAIGN then
loop
if GetItemType(UnitItemInSlot(triggerer, i)) == ITEM_TYPE_CAMPAIGN then
call DisplayTextToPlayer(GetOwningPlayer(triggerer), 0.0, 0.0, GetUnitName(triggerer) + " can only carry one shield.")
set willTake = false
endif
set i = i + 1
exitwhen i >= bj_MAX_INVENTORY
endloop
endif
if willTake == true then
call UnitAddItem(triggerer, pickup)
endif
set pickup = null
set triggerer = null
endfunction
//===========================================================================
function InitTrig_Item_Managment takes nothing returns nothing
local trigger itemManagment = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( itemManagment, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( itemManagment, function manageItems )
endfunction
I've also attached the map file so you can test it yourselves.
Thanks in advance.