CaptainJack
New Member
- Reaction score
- 2
JASS:
function ItemRecipe_2items_Conditions takes nothing returns boolean
local integer asdf
set asdf = udg_ItemRecipe_Counter
if ( (UnitHasItemOfTypeBJ(GetTriggerUnit(), LoadInteger(udg_ItemRecipe, udg_ItemRecipe_ParentKey[asdf], 1)) == true) and (UnitHasItemOfTypeBJ(GetTriggerUnit(), LoadInteger(udg_ItemRecipe, udg_ItemRecipe_ParentKey[asdf], 2)) == true) ) then
return true
endif
return false
endfunction
function ItemRecipe_2items_Actions takes nothing returns nothing
call RemoveItem( GetItemOfTypeFromUnitBJ(GetTriggerUnit(), LoadInteger(udg_ItemRecipe, udg_ItemRecipe_ParentKey[udg_ItemRecipe_Counter], 1)) )
call RemoveItem( GetItemOfTypeFromUnitBJ(GetTriggerUnit(), LoadInteger(udg_ItemRecipe, udg_ItemRecipe_ParentKey[udg_ItemRecipe_Counter], 2)) )
call UnitAddItemByIdSwapped(LoadInteger(udg_ItemRecipe, udg_ItemRecipe_ParentKey[udg_ItemRecipe_Counter], 0), GetTriggerUnit())
endfunction
function ItemRecipe_2items takes integer i1, integer i2, integer created returns nothing
local trigger ItemRecipe = CreateTrigger()
set udg_ItemRecipe_Counter = udg_ItemRecipe_Counter + 1
call SaveInteger(udg_ItemRecipe, udg_ItemRecipe_ParentKey[udg_ItemRecipe_Counter], 0, created)
call SaveInteger(udg_ItemRecipe, udg_ItemRecipe_ParentKey[udg_ItemRecipe_Counter], 1, i1)
call SaveInteger(udg_ItemRecipe, udg_ItemRecipe_ParentKey[udg_ItemRecipe_Counter], 2, i2)
call TriggerRegisterAnyUnitEventBJ(ItemRecipe, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition(ItemRecipe, Condition(function ItemRecipe_2items_Conditions))
call TriggerAddAction(ItemRecipe, function ItemRecipe_2items_Actions)
endfunction
//===========================================================================
function InitTrig_Item_Recipes takes nothing returns nothing
set udg_ItemRecipe = InitHashtable()
call ItemRecipe_2items(039;ratf039;, 039;ckng039;, 039;modt039;)
call ItemRecipe_2items(039;desc039;, 039;rde4039;, 039;ofro039;)
endfunction
I have tried unsuccessfully to pass a variable by value as opposed to reference. Does anyone have a nice way to do this? For those of you who don't get what I mean here. The local asdf is proof of this, as I was hoping that local value would create a "leaked variable" to hold the static value.
This is what I want to happen.
udg_ItemRecipe_ParentKey[udg_ItemRecipe_Counter]
udg_ItemRecipe_ParentKey[1]
I want a way to pass the udg_ItemRecipe_Counter as a number value as opposed to the variable itself, so that I can create triggers on the fly. I would rather have several triggers created then appending action code to a single trigger. (Though I'm not sure if this would even matter, because there is a decent chance that blizzard merges all things with similar events into a single block of code at compilation.)