• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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
 
Level 3
Joined
Dec 21, 2008
Messages
26
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.
Top