• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Item BJ function kill needed

Status
Not open for further replies.
Hi all! I have a problem with the weird BJ - GetInventoryIndexOfItemTypeBJ(). It declares a local item, but don't null it. That is quite leaky. How can I kill it in that code?

JASS:
function WhiteRing_Conditions takes nothing returns boolean
    return (GetItemTypeId(GetManipulatedItem())=='I030' or GetItemTypeId(GetManipulatedItem())=='I02F') and (UnitHasItemOfTypeBJ(GetManipulatingUnit(),'I02F') and UnitHasItemOfTypeBJ(GetManipulatingUnit(),'I030'))
endfunction

function WhiteRing_Actions takes nothing returns nothing
    call RemoveItem(GetItemOfTypeFromUnitBJ(GetManipulatingUnit(),'I02F'))
    call RemoveItem(GetItemOfTypeFromUnitBJ(GetManipulatingUnit(),'I030'))
    call UnitAddItemById(GetManipulatingUnit(),'I02V')
    if IsUnitAlly(GetTriggerUnit(),Player(10)) then
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.md​l",GetManipulatingUnit(),"origin"))
    else
        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl"​;,GetManipulatingUnit(),"origin"))
    endif
endfunction

//===========================================================================
function InitTrig_WhiteRing takes nothing returns nothing
    local trigger WhiteRing = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(WhiteRing,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(WhiteRing,Condition(function WhiteRing_Conditions))
    call TriggerAddAction(WhiteRing,function WhiteRing_Actions)
    set WhiteRing = null
endfunction
 
You had unit leaks and call the same function many times.. I cleaned up most ( if not all ) of the leaky code ,
You cannot kill the local item var ... but you could just replace the BJ with your own :
JASS:
function GetInventoryIndexOfItemType takes unit whichUnit, integer itemId returns integer
    local integer index
    local item    indexItem

    set index = 0
    loop
        set indexItem = UnitItemInSlot(whichUnit, index)
        if (indexItem != null) and (GetItemTypeId(indexItem) == itemId) then
            set indexItem = null //<--- here
            return index + 1
        endif

        set index = index + 1
        exitwhen index >= bj_MAX_INVENTORY
    endloop
    set indexItem = null //<-- and here
    return 0
endfunction

JASS:
function unitHasItemType takes unit u,integer typez returns boolean
    local integer i = 0
    loop
        exitwhen i ==6
        if(GetItemTypeId(UnitItemInSlot(u,i)))        
            return true
        endif
        set i = i + 1
    endloop
    return false
endfunction

function WhiteRing_Conditions takes nothing returns boolean
    local integer itemId = GetItemTypeId(GetManipulatedItem())
    local unit u = GetManipulatingUnit()
    local boolean hasItem1 = UnitHasItemOfTypeBJ(u,'I02F')// or unitHasItemType(u,itemId)
    local boolean hasItem2 = UnitHasItemOfTypeBJ(u,'I030')// saved the BJ... your choice...
    set u = null
    return (itemId=='I030' or itemId=='I02F') and hasItem1 and hasItem2)
endfunction

function WhiteRing_Actions takes nothing returns nothing
    local unit u = GetManipulatingUnit()
    call RemoveItem(GetItemOfTypeFromUnitBJ(u,'I02F'))// and here :D
    call RemoveItem(GetItemOfTypeFromUnitBJ(u,'I030'))// Just saves the BJ calling the other BJ's lol...
    call UnitAddItemById(u,'I02V')
    if IsUnitAlly(u,Player(10)) then
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.md?l",u,"origin"))
    else
        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl"​;,u,"origin"))
    endif
    set u = null
endfunction

//===========================================================================
function InitTrig_WhiteRing takes nothing returns nothing
    local trigger WhiteRing = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(WhiteRing,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(WhiteRing,Condition(function WhiteRing_Conditions))
    call TriggerAddAction(WhiteRing,function WhiteRing_Actions)
    set WhiteRing = null
endfunction

Well I did two things for you :D
I hope your happy because I sure feel happy... :thumbs_up:
 
Status
Not open for further replies.
Back
Top