Exide
I am amazingly focused right now!
- Reaction score
- 448
Hi.
I'm too tired right now to make this work.
I got six different items that can be merged into one.
Item A, B and C. -If the hero acquires item A and B, the hero recieves item AB. If the hero acquires item A and C, he gets item AC, and so on..
-I worked this part out, but the code isn't pretty.
I also don't want the hero to be able to pick up any two similar items. (If the hero has item A and acquires item A, the manipulated item should be dropped.)
-I worked this out as well, but a problem occurs: If the hero has item ABC he can pick up any item (as long as it isn't ABC, or turns into ABC - then it will be dropped.)
Here's my trigger:
Yes, it's a mess.
-Please help me optimize it.
I'm too tired right now to make this work.
I got six different items that can be merged into one.
Item A, B and C. -If the hero acquires item A and B, the hero recieves item AB. If the hero acquires item A and C, he gets item AC, and so on..
-I worked this part out, but the code isn't pretty.
I also don't want the hero to be able to pick up any two similar items. (If the hero has item A and acquires item A, the manipulated item should be dropped.)
-I worked this out as well, but a problem occurs: If the hero has item ABC he can pick up any item (as long as it isn't ABC, or turns into ABC - then it will be dropped.)
Code:
The item ids are the following:
Item A (Ice): 'I000'
Item B (Fire): 'I001'
Item C (Poison): 'I002'
----
Item AC (Ice + Poison): 'I003'
Item BC (Poison + Fire): 'I004'
Item AB (Ice + Fire): 'I005'
----
Item ABC (Ice + Fire + Poison): 'I006'
Here's my trigger:
JASS:
function sfx_func takes nothing returns nothing
local real x = GetUnitX(GetTriggerUnit())
local real y = GetUnitY(GetTriggerUnit())
call DestroyEffect(AddSpecialEffect( "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl", x, y ))
endfunction
function Trig_Merging_Items_Actions takes nothing returns nothing
local integer newitemid = GetItemTypeId(GetManipulatedItem())
local item newitem = GetManipulatedItem()
local unit u = GetTriggerUnit()
local item array itemindex
local integer loopnr = 0
local player p = GetOwningPlayer(u)
loop
exitwhen loopnr > 6
set itemindex[loopnr] = UnitItemInSlot( u, loopnr )
if ( (GetItemTypeId(itemindex[loopnr]) == newitemid) and (newitem != itemindex[loopnr]) ) then
call UnitRemoveItem( u, newitem )
call DisplayTextToPlayer( p, 0, 0, "You can only carry one of those items!" )
endif
set loopnr = loopnr + 1
endloop
if (newitemid == 039;I000039;) then
if (UnitHasItemOfTypeBJ(u, 039;I001039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I001039;) )
call UnitAddItemById( u, 039;I005039; )
call sfx_func()
endif
if (UnitHasItemOfTypeBJ(u, 039;I002039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I002039;) )
call UnitAddItemById( u, 039;I003039; )
call sfx_func()
endif
if (UnitHasItemOfTypeBJ(u, 039;I004039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I004039;) )
call UnitAddItemById( u, 039;I006039; )
call sfx_func()
endif
endif
if (newitemid == 039;I001039;) then
if (UnitHasItemOfTypeBJ(u, 039;I000039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I000039;) )
call UnitAddItemById( u, 039;I005039; )
call sfx_func()
endif
if (UnitHasItemOfTypeBJ(u, 039;I002039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I002039;) )
call UnitAddItemById( u, 039;I004039; )
call sfx_func()
endif
if (UnitHasItemOfTypeBJ(u, 039;I003039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I003039;) )
call UnitAddItemById( u, 039;I006039; )
call sfx_func()
endif
endif
if (newitemid == 039;I002039;) then
if (UnitHasItemOfTypeBJ(u, 039;I001039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I001039;) )
call UnitAddItemById( u, 039;I004039; )
call sfx_func()
endif
if (UnitHasItemOfTypeBJ(u, 039;I000039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I000039;) )
call UnitAddItemById( u, 039;I003039; )
call sfx_func()
endif
if (UnitHasItemOfTypeBJ(u, 039;I005039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I005039;) )
call UnitAddItemById( u, 039;I006039; )
call sfx_func()
endif
endif
if (newitemid == 039;I003039;) then
if (UnitHasItemOfTypeBJ(u, 039;I001039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I001039;) )
call UnitAddItemById( u, 039;I006039; )
call sfx_func()
endif
endif
if (newitemid == 039;I004039;) then
if (UnitHasItemOfTypeBJ(u, 039;I000039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I000039;) )
call UnitAddItemById( u, 039;I006039; )
call sfx_func()
endif
endif
if (newitemid == 039;I005039;) then
if (UnitHasItemOfTypeBJ(u, 039;I002039;)) then
call RemoveItem( newitem )
call RemoveItem( GetItemOfTypeFromUnitBJ(u, 039;I002039;) )
call UnitAddItemById( u, 039;I006039; )
call sfx_func()
endif
endif
endfunction
//===========================================================================
function InitTrig_Merging_Items takes nothing returns nothing
local trigger Merging_Items = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( Merging_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( Merging_Items, function Trig_Merging_Items_Actions )
endfunction
Yes, it's a mess.
-Please help me optimize it.