Need Help Optimizing.

Exide

I am amazingly focused right now!
Reaction score
448
Hi.
I'm too tired right now to make this work. :p

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. :p

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 == 'I000') then
        if (UnitHasItemOfTypeBJ(u, 'I001')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I001') )
            call UnitAddItemById( u, 'I005' )
            call sfx_func()
            
        endif
        
        if (UnitHasItemOfTypeBJ(u, 'I002')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I002') )
            call UnitAddItemById( u, 'I003' )
            call sfx_func()
            
        endif
        
        if (UnitHasItemOfTypeBJ(u, 'I004')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I004') )
            call UnitAddItemById( u, 'I006' )
            call sfx_func()
            
        endif
    endif
    
    if (newitemid == 'I001') then
        if (UnitHasItemOfTypeBJ(u, 'I000')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I000') )
            call UnitAddItemById( u, 'I005' )
            call sfx_func()
            
        endif
        
        if (UnitHasItemOfTypeBJ(u, 'I002')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I002') )
            call UnitAddItemById( u, 'I004' )
            call sfx_func()
            
        endif
        
        if (UnitHasItemOfTypeBJ(u, 'I003')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I003') )
            call UnitAddItemById( u, 'I006' )
            call sfx_func()
            
        endif
    endif
    
    if (newitemid == 'I002') then
        if (UnitHasItemOfTypeBJ(u, 'I001')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I001') )
            call UnitAddItemById( u, 'I004' )
            call sfx_func()
            
        endif
        
        if (UnitHasItemOfTypeBJ(u, 'I000')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I000') )
            call UnitAddItemById( u, 'I003' )
            call sfx_func()
            
        endif
        
        if (UnitHasItemOfTypeBJ(u, 'I005')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I005') )
            call UnitAddItemById( u, 'I006' )
            call sfx_func()
            
        endif
    endif
    
    if (newitemid == 'I003') then
        if (UnitHasItemOfTypeBJ(u, 'I001')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I001') )
            call UnitAddItemById( u, 'I006' )
            call sfx_func()
            
        endif
    endif
    
    if (newitemid == 'I004') then
        if (UnitHasItemOfTypeBJ(u, 'I000')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I000') )
            call UnitAddItemById( u, 'I006' )
            call sfx_func()
            
        endif
    endif
    
    if (newitemid == 'I005') then
        if (UnitHasItemOfTypeBJ(u, 'I002')) then
            
            call RemoveItem( newitem )
            call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I002') )
            call UnitAddItemById( u, 'I006' )
            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. :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top