HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help Optim this

12-24-2006, 01:48 AM#1
Joker
Collapse JASS:
function Trig_Recipe_Items_Actions takes nothing returns nothing
    local unit a = GetManipulatingUnit()
    if UnitHasItemOfTypeBJ(a, 'belv') == true and UnitHasItemOfTypeBJ(a, 'ciri') == true and UnitHasItemOfTypeBJ(a, 'bgst') == true then
        call RemoveItem( GetItemOfTypeFromUnitBJ(a, 'bgst') )
        call RemoveItem( GetItemOfTypeFromUnitBJ(a, 'ciri') )
        call RemoveItem( GetItemOfTypeFromUnitBJ(a, 'belv') )
        call UnitAddItemById( a,'I00E' )
        call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", a, "origin" ) )
    endif
    set a = null
endfunction

//===========================================================================
function InitTrig_Recipe_Items takes nothing returns nothing
    set gg_trg_Recipe_Items = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Recipe_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Recipe_Items, function Trig_Recipe_Items_Actions )
endfunction
I dont want to use the BJ's besides the one for the event, but the Bj's origins are too complicated, is that the only way to do recipes?
12-24-2006, 01:56 AM#2
wyrmlord
Suggestion: Remove the '==true' parts from the code. Also, this is too complicated to replace?! (Even though it's just another BJ function)
Collapse JASS:
function UnitHasItemOfTypeBJ takes unit whichUnit, integer itemId returns boolean
    return GetInventoryIndexOfItemTypeBJ(whichUnit, itemId) > 0
endfunction
As for the GetItemOfTypeFromUnitBJ, instead you could probably do a loop that loops through each inventory slot of a unit and it it finds the certain item it removes it.
12-24-2006, 02:01 AM#3
Vexorian
There are a lot of ways to make recipes.

For this case since you don't want it dynamic I recomment a loop through the slots of the inventory and asking if UnitItemInSlot is one of those items then checking. would reduce T from 18 to 6,
12-24-2006, 02:07 AM#4
darkwulfv
Replace
Collapse JASS:
function InitTrig_Recipe_Items takes nothing returns nothing
    set gg_trg_Recipe_Items = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Recipe_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Recipe_Items, function Trig_Recipe_Items_Actions )
endfunction

with

Collapse JASS:
function InitTrig_Recipe_Items takes nothing returns nothing
  local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( t, function Trig_Recipe_Items_Actions )
set t = null
endfunction

Put that in. Just a bit of optimization, saves a few kb of memory, plus its cleaner. I suggest doing this for all your JASS triggers. It's become habit for me.

He asked for optimization, thats what he gets XD