Trigger Optimization with lots of loops

2evil

New Member
Reaction score
16
Hi, I need some major help optimizing this trigger somehow. Right now, it can has about 70,000 different combinations of how it can run, and although I have made it so it will exit as early as it can, is still lags a wee bit :)

As for background, heres the essential facts about the trigger:
*It is an item-combining trigger
*the combining is based off of materials in items
*The materials for the items are stored in two integer arrays (7 digits in each)
*possible items are ranked and the 10 best (determined by leftover mats) are able to be chosen by the player​
*at this point in the trigger, the combined materials have already been found (Temp_Materials_A)
*Temp_Materials_B is what the new item's materials are

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        [i]-------- Sword Verification --------[/i]
        Temp_Materials_A[1] Equal to 1
    Then - Actions
        [i]-------- Looping through all swords --------[/i]
        For each (Integer B) from 15 to 71, do (Actions)
            Loop - Actions
                [i]-------- Looping through materials --------[/i]
                For each (Integer Temp_value_2) from 2 to 14, do (Actions)
                    Loop - Actions
                        [i]-------- Since the materials are stored in 2 different variables, it changes which variable it calls upon depending on the loop number (1-7 in variable [b]Item_Codes[/b], 8-14 in [b]Item_Codes_Elements[/b]) --------[/i]
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                Temp_value_2 Less than or equal to 7
                            Then - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        Temp_value_2 Less than or equal to 6
                                    Then - Actions
                                        Set Temp_Materials_B[Temp_value_2] = (0 + (((Item_Codes[(Integer B)] mod (Integer((Power(10.00, (8.00 - (Real(Temp_value_2)))))))) - (Item_Codes[(Integer B)] mod (Integer((Power(10.00, (7.00 - (Real(Temp_value_2))))))))) / (Integer((Power(10.00, (7.00 - (Real(Temp_value_2)))))))))
                                    Else - Actions
                                        Set Temp_Materials_B[Temp_value_2] = (0 + (Item_Codes[(Integer B)] mod (Integer((Power(10.00, (8.00 - (Real(Temp_value_2)))))))))
                            Else - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        Temp_value_2 Less than or equal to 13
                                    Then - Actions
                                        Set Temp_Materials_B[Temp_value_2] = (0 + (((Item_Codes_Elements[(Integer B)] mod (Integer((Power(10.00, (15.00 - (Real(Temp_value_2)))))))) - (Item_Codes_Elements[(Integer B)] mod (Integer((Power(10.00, (14.00 - (Real(Temp_value_2))))))))) / (Integer((Power(10.00, (14.00 - (Real(Temp_value_2)))
                                    Else - Actions
                                        Set Temp_Materials_B[Temp_value_2] = (0 + (Item_Codes_Elements[(Integer B)] mod (Integer((Power(10.00, (15.00 - (Real(Temp_value_2)))))))))
                        [i]-------- Starting the similarity process, initiates once [b]Temp_Value_2[/b]=14 --------[/i]
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                Temp_Materials_A[Temp_value_2] Greater than or equal to Temp_Materials_B[Temp_value_2]
                            Then - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        Temp_value_2 Equal to 14
                                    Then - Actions 
                                        [i]-------- Creating an index for the item, based upon the amount of materials left over --------[/i]
                                        For each (Integer A) from 2 to 14, do (Actions)
                                            Loop - Actions
                                                Set Temp_value = (Temp_value + (Temp_Materials_A[(Integer A)] - Temp_Materials_B[(Integer A)]))
                                        [i]-------- Looping through other intexes, determining if the item is one of the 10 best that the player is able to create, based upon leftover materials --------[/i]
                                        For each (Integer A) from 1 to 10, do (Actions)
                                            Loop - Actions
                                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                    If - Conditions
                                                        Combiner_Items_Remainder[(Integer A)] Greater than or equal to Temp_value
                                                    Then - Actions
                                                        For each (Integer Temp_value_3) from 1 to 9, do (Actions)
                                                            Loop - Actions
                                                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                                    If - Conditions
                                                                        (10 - Temp_value_3) Greater than or equal to (Integer A)
                                                                        (10 - Temp_value_3) Less than or equal to 9
                                                                    Then - Actions
                                                                        Set Combiner_Items[(11 - Temp_value_3)] = Combiner_Items[(10 - Temp_value_3)]
                                                                        Set Combiner_Items_Remainder[(11 - Temp_value_3)] = Combiner_Items_Remainder[(10 - Temp_value_3)]
                                                                    Else - Actions
                                                        Set Combiner_Items[(Integer A)] = Item_Type[(Integer B)]
                                                        Set Combiner_Items_Remainder[(Integer A)] = Temp_value
                                                        Game - Display to (All players) the text: (Organizing! Temp_value (New item index):  + (String(Temp_value)))
                                                        Custom script:   exitwhen true
                                                    Else - Actions
                                    Else - Actions
                            Else - Actions
                                Set Temp_value_2 = 30
    Else - Actions

thank you, and if you have any questions, please ask away, ill try to clarify the best i can :D
2evil
 

Steel

Software Engineer
Reaction score
109
I normally would recommend converting it to JASS, but I'm assuming you aren't very comfortable with JASS...The thing is JASS is just more versatile, you can change the variable names to suit your own needs better. If you convert that to custom text for me, I can change things around for you and help you learn it very quickly. It might be intimidating but it is very simple.

The reason why it lags is because you are referencing a huge amount of global variable data... Again I would recommend doing something in JASS but it wouldn't make sense. Cutting down on the loops, you could try and create a better process for accomplishing the same goal.
 

2evil

New Member
Reaction score
16
ok so ive looked over it some in JASS, and i get some jass concepts, but this trigger is definitely over my head :)

PS - the first part o the trigger (i removed it in the earlier posting) is still there, i didnt want to touch anything :)

Code:
function Trig_Combiner_JASS_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A01T' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func004Func001Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_Temp_value == ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 ) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func004Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == udg_Item_Type[GetForLoopIndexB()] ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func004Func001Func001Func002Func001C takes nothing returns boolean
    if ( not ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == udg_Item_Type[GetForLoopIndexB()] ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func004Func001Func001C takes nothing returns boolean
    if ( not ( udg_Temp_value == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func004Func001C takes nothing returns boolean
    if ( not ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_PERMANENT ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_Temp_Materials_A[1] == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001Func002Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 6 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001Func002Func001Func001Func002C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 13 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001Func002Func001Func001C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 7 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001Func002Func002Func001Func001C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 6 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001Func002Func002Func001Func002C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 13 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001Func002Func002Func001C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 7 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001Func002C takes nothing returns boolean
    if ( not ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_CHARGED ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func007Func001Func001C takes nothing returns boolean
    if ( not ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == udg_Item_Type[GetForLoopIndexB()] ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func010Func001C takes nothing returns boolean
    if ( not ( udg_Temp_Materials_A[GetForLoopIndexA()] >= 10 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012Func003Func002Func002Func001C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 6 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012Func003Func002Func002Func002C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 13 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012Func003Func002Func002C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 <= 7 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012Func003Func002Func004Func002Func006Func001Func001Func001C takes nothing returns boolean
    if ( not ( ( 10 - udg_Temp_value_3 ) >= GetForLoopIndexA() ) ) then
        return false
    endif
    if ( not ( ( 10 - udg_Temp_value_3 ) <= 9 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012Func003Func002Func004Func002Func006Func001C takes nothing returns boolean
    if ( not ( udg_Combiner_Items_Remainder[GetForLoopIndexA()] >= udg_Temp_value ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012Func003Func002Func004Func002C takes nothing returns boolean
    if ( not ( udg_Temp_value_2 == 14 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012Func003Func002Func004C takes nothing returns boolean
    if ( not ( udg_Temp_Materials_A[udg_Temp_value_2] >= udg_Temp_Materials_B[udg_Temp_value_2] ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012C takes nothing returns boolean
    if ( not ( udg_Temp_Materials_A[1] == 1 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Actions takes nothing returns nothing
    set udg_Temp_value = 0
    set udg_Temp_value_2 = 0
    // Weapon-Type Detection
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 6
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Combiner_JASS_Func004Func001C() ) then
            if ( Trig_Combiner_JASS_Func004Func001Func001C() ) then
                set bj_forLoopBIndex = 14
                set bj_forLoopBIndexEnd = 71
                loop
                    exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                    if ( Trig_Combiner_JASS_Func004Func001Func001Func002Func001C() ) then
                        set udg_Temp_value = ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 )
                        exitwhen true
                    else
                    endif
                    set bj_forLoopBIndex = bj_forLoopBIndex + 1
                endloop
            else
                set bj_forLoopBIndex = 14
                set bj_forLoopBIndexEnd = 71
                loop
                    exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                    if ( Trig_Combiner_JASS_Func004Func001Func001Func001Func001C() ) then
                        if ( Trig_Combiner_JASS_Func004Func001Func001Func001Func001Func001C() ) then
                        else
                            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), "TRIGSTR_1906" )
                            set udg_Temp_value = 0
                            return
                        endif
                        exitwhen true
                    else
                    endif
                    set bj_forLoopBIndex = bj_forLoopBIndex + 1
                endloop
            endif
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set udg_Temp_value = 0
    // Code Addition, 14 size array A
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 6
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set bj_forLoopBIndex = 2
        set bj_forLoopBIndexEnd = 71
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            if ( Trig_Combiner_JASS_Func007Func001Func001C() ) then
                if ( Trig_Combiner_JASS_Func007Func001Func001Func001C() ) then
                    set udg_Temp_Materials_A[1] = ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 )
                else
                endif
                if ( Trig_Combiner_JASS_Func007Func001Func001Func002C() ) then
                    set udg_Temp_value_2 = 2
                    loop
                        exitwhen udg_Temp_value_2 > 14
                        if ( Trig_Combiner_JASS_Func007Func001Func001Func002Func001Func001C() ) then
                            if ( Trig_Combiner_JASS_Func007Func001Func001Func002Func001Func001Func001C() ) then
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ( ( ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) ))) ) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) ) )
                            else
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) ) )
                            endif
                        else
                            if ( Trig_Combiner_JASS_Func007Func001Func001Func002Func001Func001Func002C() ) then
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ( ( ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) ))) ) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) ) )
                            else
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) ) )
                            endif
                        endif
                        set udg_Temp_value_2 = udg_Temp_value_2 + 1
                    endloop
                else
                    set udg_Temp_value_2 = 2
                    loop
                        exitwhen udg_Temp_value_2 > 14
                        if ( Trig_Combiner_JASS_Func007Func001Func001Func002Func002Func001C() ) then
                            if ( Trig_Combiner_JASS_Func007Func001Func001Func002Func002Func001Func001C() ) then
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ( ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) ))) ) )
                            else
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) )
                            endif
                        else
                            if ( Trig_Combiner_JASS_Func007Func001Func001Func002Func002Func001Func002C() ) then
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ( ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) ))) ) )
                            else
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) )
                            endif
                        endif
                        set udg_Temp_value_2 = udg_Temp_value_2 + 1
                    endloop
                endif
                exitwhen true
            else
            endif
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set udg_Temp_value_2 = 0
    // +9 item detection
    set bj_forLoopAIndex = 2
    set bj_forLoopAIndexEnd = 14
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Combiner_JASS_Func010Func001C() ) then
            set udg_Temp_String = GetObjectName( udg_Item_Codes[ bj_forLoopAIndex ] )
            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), ( "You may only use a maximum of 9 of each type of material. You have " + ( I2S(udg_Temp_Materials_A[GetForLoopIndexA()]) + ( " of the material " + udg_Temp_String ) ) ) )
            set udg_Temp_value = 0
            set bj_forLoopBIndex = 1
            set bj_forLoopBIndexEnd = 14
            loop
                exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                set udg_Temp_Materials_A[GetForLoopIndexB()] = 0
                set bj_forLoopBIndex = bj_forLoopBIndex + 1
            endloop
            return
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    // Item Familiarity
    if ( Trig_Combiner_JASS_Func012C() ) then
        // Sword Verification
        // Looping through all swords
        set bj_forLoopBIndex = 15
        set bj_forLoopBIndexEnd = 71
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            // Looping through materials
            set udg_Temp_value_2 = 2
            loop
                exitwhen udg_Temp_value_2 > 14
                // Since the materials are stored in 2 different variables, it changes which variable it calls upon depending on the loop number (1-7 in variable [b]Item_Codes[/b], 8-14 in [b]Item_Codes_Elements[/b])
                if ( Trig_Combiner_JASS_Func012Func003Func002Func002C() ) then
                    if ( Trig_Combiner_JASS_Func012Func003Func002Func002Func001C() ) then
                        set udg_Temp_Materials_B[udg_Temp_value_2] = ( 0 + ( ( ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) ))) ) )
                    else
                        set udg_Temp_Materials_B[udg_Temp_value_2] = ( 0 + ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) )
                    endif
                else
                    if ( Trig_Combiner_JASS_Func012Func003Func002Func002Func002C() ) then
                        set udg_Temp_Materials_B[udg_Temp_value_2] = ( 0 + ( ( ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) ))) ) )
                    else
                        set udg_Temp_Materials_B[udg_Temp_value_2] = ( 0 + ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) )
                    endif
                endif
                // Starting the similarity process, initiates once [b]Temp_Value_2[/b]=14
                if ( Trig_Combiner_JASS_Func012Func003Func002Func004C() ) then
                    if ( Trig_Combiner_JASS_Func012Func003Func002Func004Func002C() ) then
                        // Creating an idex for the item, based upon the amount of materials left over
                        set bj_forLoopAIndex = 2
                        set bj_forLoopAIndexEnd = 14
                        loop
                            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
                            set udg_Temp_value = ( udg_Temp_value + ( udg_Temp_Materials_A[GetForLoopIndexA()] - udg_Temp_Materials_B[GetForLoopIndexA()] ) )
                            set bj_forLoopAIndex = bj_forLoopAIndex + 1
                        endloop
                        // Looping through other intexes, determining if the item is one of the 10 best that the player is able to create, based upon leftover materials
                        set bj_forLoopAIndex = 1
                        set bj_forLoopAIndexEnd = 10
                        loop
                            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
                            if ( Trig_Combiner_JASS_Func012Func003Func002Func004Func002Func006Func001C() ) then
                                set udg_Temp_value_3 = 1
                                loop
                                    exitwhen udg_Temp_value_3 > 9
                                    if ( Trig_Combiner_JASS_Func012Func003Func002Func004Func002Func006Func001Func001Func001C() ) then
                                        set udg_Combiner_Items[( 11 - udg_Temp_value_3 )] = udg_Combiner_Items[( 10 - udg_Temp_value_3 )]
                                        set udg_Combiner_Items_Remainder[( 11 - udg_Temp_value_3 )] = udg_Combiner_Items_Remainder[( 10 - udg_Temp_value_3 )]
                                    else
                                    endif
                                    set udg_Temp_value_3 = udg_Temp_value_3 + 1
                                endloop
                                set udg_Combiner_Items[GetForLoopIndexA()] = udg_Item_Type[GetForLoopIndexB()]
                                set udg_Combiner_Items_Remainder[GetForLoopIndexA()] = udg_Temp_value
                                call DisplayTextToForce( GetPlayersAll(), ( "Organizing! Temp_value (New item index): " + I2S(udg_Temp_value) ) )
                                exitwhen true
                            else
                            endif
                            set bj_forLoopAIndex = bj_forLoopAIndex + 1
                        endloop
                    else
                    endif
                else
                    set udg_Temp_value_2 = 30
                endif
                set udg_Temp_value_2 = udg_Temp_value_2 + 1
            endloop
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
    else
    endif
    set udg_Temp_value = 0
    set udg_Temp_value_2 = 0
    set udg_Temp_value_3 = 0
    set bj_forLoopBIndex = 1
    set bj_forLoopBIndexEnd = 14
    loop
        exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
        set udg_Temp_Materials_A[GetForLoopIndexB()] = 0
        set bj_forLoopBIndex = bj_forLoopBIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Combiner_JASS takes nothing returns nothing
    set gg_trg_Combiner_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Combiner_JASS, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Combiner_JASS, Condition( function Trig_Combiner_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Combiner_JASS, function Trig_Combiner_JASS_Actions )
endfunction
 

Steel

Software Engineer
Reaction score
109
Alrighty well as you can see its almost 400 lines of code. DONT get overwhelmed, GUI to JASS conversions always look very messy especially with if statements. So just stay with this and you will understand it in no time. You can notice there are a lot of 1 lined functions, these aren't necessary, its just how GUI works...So to start cleaning this up before we understand it, lets first do this.

Go down and find the bulk of your code in "function Trig_Combiner_JASS_Actions takes nothing returns nothing"

When you scroll down you will see your first If statement:
Code:
        if ( Trig_Combiner_JASS_Func004Func001C() ) then

The Trig_Combiner_JASS_Func004Func001C()) references one of the 1 liners above. Find that bit of code above that matches this function. You will find this:
Code:
function Trig_Combiner_JASS_Func004Func001C takes nothing returns boolean
    if ( not ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_PERMANENT ) ) then
        return false
    endif
    return true
endfunction

Lets look at this bit of code really quick. Lets ignore whats going on in it and look at just the boolean algebra (The True and False stuff). You have IF ( NOT ( Something ) THEN RETURN FALSE, you basically have a double negative here, so you can change it to: IF ( SOMETHING) THEN RETURN TRUE, but you can simplify this even further. You do not need the IF THEN statement, you can just simply RETURN ( Something ), if the something is true it will return true, false otherwise. So it would become:
return (GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_PERMANENT )

Now, this simplifies the functions, this is just a general understand of what each function does. Since these are just single line if statements you do not need a function. So just take the entire line, without the return, EX:GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_PERMANENT ), and copy it. Then paste is right where the function call was.

So...
Code:
        if ( Trig_Combiner_JASS_Func004Func001C() ) then
would turn into
Code:
        if ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_PERMANENT ) then


Since you have a million of these, I'll do just the next few so you can get the hang of it.

Original Code:
Code:
        if ( Trig_Combiner_JASS_Func004Func001C() ) then
            if ( Trig_Combiner_JASS_Func004Func001Func001C() ) then
                set bj_forLoopBIndex = 14
                set bj_forLoopBIndexEnd = 71
                loop
                    exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                    if ( Trig_Combiner_JASS_Func004Func001Func001Func002Func001C() ) then
                        set udg_Temp_value = ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 )
                        exitwhen true
                    else
                    endif
                    set bj_forLoopBIndex = bj_forLoopBIndex + 1
                endloop
            else
                set bj_forLoopBIndex = 14
                set bj_forLoopBIndexEnd = 71
                loop
                    exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                    if ( Trig_Combiner_JASS_Func004Func001Func001Func001Func001C() ) then
                        if ( Trig_Combiner_JASS_Func004Func001Func001Func001Func001Func001C() ) then
                        else
                            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), "TRIGSTR_1906" )
                            set udg_Temp_value = 0
                            return
                        endif
                        exitwhen true
                    else
                    endif
                    set bj_forLoopBIndex = bj_forLoopBIndex + 1
                endloop
            endif
        else
        endif

Cleaned Code
Code:
        if ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_PERMANENT ) then
            if ( udg_Temp_value == 0 ) then
                set bj_forLoopBIndex = 14
                set bj_forLoopBIndexEnd = 71
                loop
                    exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd

                    if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == udg_Item_Type[GetForLoopIndexB()] ) then
                        set udg_Temp_value = ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 )
                        exitwhen true
                    else
                    endif
                    set bj_forLoopBIndex = bj_forLoopBIndex + 1
                endloop
            else
                set bj_forLoopBIndex = 14
                set bj_forLoopBIndexEnd = 71
                loop
                    exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                    if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == udg_Item_Type[GetForLoopIndexB()] ) then
                        if ( udg_Temp_value == ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 ) ) then
                        else
                            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), "TRIGSTR_1906" )
                            set udg_Temp_value = 0
                            return
                        endif
                        exitwhen true
                    else
                    endif
                    set bj_forLoopBIndex = bj_forLoopBIndex + 1
                endloop
            endif
        else
        endif
Each time you swapped the code out you can delete the single line function calls above since they are no longer referenced.

To optimize you will need to tell me more about the global variables you use, Temp_value, Item_Type and Item_Codes. But for right now...you will notice the "else" statements, they are almost all blank, so just delete them. For right now go ahead and do the rest of your loop and tell me about those global variables.
 

2evil

New Member
Reaction score
16
The global Variables:

Temp_value: I use it for various (temp) values, could easily be changed into a local variable, as it does not effect any other triggers
Temp_value_2: Used as a loop integer, also does not effect other triggers
Temp_value_3: Used as a loop integer, also does not effect other triggers
Temp_Materials_A: integer array (size 14) that stores the combined values of the items held by the unit that are used for combining
Temp_Materials_B: integer array (size 14) that stores the value of item[temp_value_2] for comparing against temp_materials_A
Item_Codes: size 71 integer array that holds the first half of the item codes
Item_Codes_Elements: size 71 integer array that holds the second half of the item codes (one item code is 14 digits)
Combiner_Items: size 10 item array that holds the 10 best items as a result of the combination, allowing the player to choose one of them
Combiner_Items_Remainder: size 10 integer array that holds the 'index' of the top 10 items, or the remainder of items that combo would have.

EDIT: I finished optimizing how you told me to, except how do you do multiple conditions for one 'if'? do you just put a comma in between?
 

Steel

Software Engineer
Reaction score
109
EDIT: I finished optimizing how you told me to, except how do you do multiple conditions for one 'if'? do you just put a comma in between?

if (something) then
//Code
elseif (something) then
//code
elseif (something) then
//code
else
//code
endif

Note: Else not required.
 

2evil

New Member
Reaction score
16
ok so heres the reworked trigger so far. I still havent been able to figure out what you do if you have multiple conditions for if/then/else loops :(

also, I have another question. Now that you are at least partially familiar with this trigger, I'll introduce it. For some reason, when you put in more than 2 different types of ingredients, the trigger does not set temp_value in this trigger:
Code:
                                        For each (Integer A) from 2 to 14, do (Actions)
                                            Loop - Actions
                                                Set Temp_value = (Temp_value + (Temp_Materials_A[(Integer A)] - Temp_Materials_B[(Integer A)]))

Also, it passes the check earlier in the trigger that temp_value_2=14 rather oddly. It goes like this:
precheck: x=14
at check: x=14
postcheck: x=11
No trigger alters temp_value_2 after the check. This may be on the account of so much happening at once.

But heres my cleaned stuff.
Code:
function Trig_Combiner_JASS_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A01T' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Func012Func003Func002Func004Func002Func006Func001Func001Func001C takes nothing returns boolean
    if ( not ( ( 10 - udg_Temp_value_3 ) >= GetForLoopIndexA() ) ) then
        return false
    endif
    if ( not ( ( 10 - udg_Temp_value_3 ) <= 9 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Combiner_JASS_Actions takes nothing returns nothing
    set udg_Temp_value = 0
    set udg_Temp_value_2 = 0
    // Weapon-Type Detection
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 6
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_PERMANENT ) then
            if ( udg_Temp_value == 0 ) then
                set bj_forLoopBIndex = 14
                set bj_forLoopBIndexEnd = 71
                loop
                    exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                    if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == udg_Item_Type[GetForLoopIndexB()] ) then
                        set udg_Temp_value = ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 )
                        exitwhen true
                    endif
                    set bj_forLoopBIndex = bj_forLoopBIndex + 1
                endloop
            else
                set bj_forLoopBIndex = 14
                set bj_forLoopBIndexEnd = 71
                loop
                    exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                    if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == udg_Item_Type[GetForLoopIndexB()] ) then
                        if ( udg_Temp_value == ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 ) ) then
                        else
                            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), "TRIGSTR_1906" )
                            set udg_Temp_value = 0
                            return
                        endif
                        exitwhen true
                    endif
                    set bj_forLoopBIndex = bj_forLoopBIndex + 1
                endloop
            endif
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set udg_Temp_value = 0
    // Code Addition, 14 size array A
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 6
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set bj_forLoopBIndex = 2
        set bj_forLoopBIndexEnd = 71
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == udg_Item_Type[GetForLoopIndexB()] ) then
                if ( udg_Temp_Materials_A[1] == 0 ) then
                    set udg_Temp_Materials_A[1] = ( ( udg_Item_Codes[GetForLoopIndexB()] - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], 1000000) ) / 1000000 )
                endif
                if ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) == ITEM_TYPE_CHARGED ) then
                    set udg_Temp_value_2 = 2
                    loop
                        exitwhen udg_Temp_value_2 > 14
                        if ( udg_Temp_value_2 <= 7 ) then
                            if ( udg_Temp_value_2 <= 6 ) then
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ( ( ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) ))) ) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) ) )
                            else
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) ) )
                            endif
                        else
                            if ( udg_Temp_value_2 <= 13 ) then
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ( ( ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) ))) ) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) ) )
                            else
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), GetForLoopIndexA())) ) )
                            endif
                        endif
                        set udg_Temp_value_2 = udg_Temp_value_2 + 1
                    endloop
                else
                    set udg_Temp_value_2 = 2
                    loop
                        exitwhen udg_Temp_value_2 > 14
                        if ( udg_Temp_value_2 <= 7 ) then
                            if ( udg_Temp_value_2 <= 6 ) then
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ( ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) ))) ) )
                            else
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) )
                            endif
                        else
                            if ( udg_Temp_value_2 <= 13 ) then
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ( ( ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) ))) ) )
                            else
                                set udg_Temp_Materials_A[udg_Temp_value_2] = ( udg_Temp_Materials_A[udg_Temp_value_2] + ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) )
                            endif
                        endif
                        set udg_Temp_value_2 = udg_Temp_value_2 + 1
                    endloop
                endif
                exitwhen true
            endif
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set udg_Temp_value_2 = 0
    // +9 item detection
    set bj_forLoopAIndex = 2
    set bj_forLoopAIndexEnd = 14
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( ( udg_Temp_Materials_A[GetForLoopIndexA()] >= 10 ) ) then
            set udg_Temp_String = GetObjectName( udg_Item_Codes[ bj_forLoopAIndex ] )
            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), ( "You may only use a maximum of 9 of each type of material. You have " + ( I2S(udg_Temp_Materials_A[GetForLoopIndexA()]) + ( " of the material " + udg_Temp_String ) ) ) )
            set udg_Temp_value = 0
            set bj_forLoopBIndex = 1
            set bj_forLoopBIndexEnd = 14
            loop
                exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
                set udg_Temp_Materials_A[GetForLoopIndexB()] = 0
                set bj_forLoopBIndex = bj_forLoopBIndex + 1
            endloop
            return
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    // Item Familiarity
    if ( udg_Temp_Materials_A[1] == 1 ) then
        // Sword Verification
        // Looping through all swords
        set bj_forLoopBIndex = 15
        set bj_forLoopBIndexEnd = 71
        loop
            exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
            // Looping through materials
            set udg_Temp_value_2 = 2
            loop
                exitwhen udg_Temp_value_2 > 14
                // Since the materials are stored in 2 different variables, it changes which variable it calls upon depending on the loop number (1-7 in variable [b]Item_Codes[/b], 8-14 in [b]Item_Codes_Elements[/b])
                if ( ( udg_Temp_value_2 <= 7 ) ) then
                    if ( ( udg_Temp_value_2 <= 6 ) ) then
                        set udg_Temp_Materials_B[udg_Temp_value_2] = ( 0 + ( ( ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(udg_Temp_value_2) ))) ) )
                    else
                        set udg_Temp_Materials_B[udg_Temp_value_2] = ( 0 + ModuloInteger(udg_Item_Codes[GetForLoopIndexB()], R2I(Pow(10.00, ( 8.00 - I2R(udg_Temp_value_2) )))) )
                    endif
                else
                    if ( ( udg_Temp_value_2 <= 13 ) ) then
                        set udg_Temp_Materials_B[udg_Temp_value_2] = ( 0 + ( ( ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) - ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(udg_Temp_value_2) ))) ) )
                    else
                        set udg_Temp_Materials_B[udg_Temp_value_2] = ( 0 + ModuloInteger(udg_Item_Codes_Elements[GetForLoopIndexB()], R2I(Pow(10.00, ( 15.00 - I2R(udg_Temp_value_2) )))) )
                    endif
                endif
                // Starting the similarity process, initiates once [b]Temp_Value_2[/b]=14
                if ( udg_Temp_Materials_A[udg_Temp_value_2] >= udg_Temp_Materials_B[udg_Temp_value_2] ) then
                    if ( udg_Temp_value_2 == 14 ) then
                        call DisplayTextToForce( GetPlayersAll(), ( ( "Loop A (2-14 mat add)=" + I2S(GetForLoopIndexA()) ) + ( "; " + ( "Loop B (15-71 item finder)=" + I2S(GetForLoopIndexB()) ) ) ) )
                        set bj_forLoopAIndex = 1
                        set bj_forLoopAIndexEnd = 14
                        loop
                            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
                            call DisplayTextToForce( GetPlayersAll(), ( ( "index " + I2S(GetForLoopIndexA()) ) + ( ": A=" + ( ( I2S(udg_Temp_Materials_A[GetForLoopIndexA()]) + ", B=" ) + I2S(udg_Temp_Materials_B[GetForLoopIndexA()]) ) ) ) )
                            set bj_forLoopAIndex = bj_forLoopAIndex + 1
                        endloop
                        // Creating an idex for the item, based upon the amount of materials left over
                        set bj_forLoopAIndex = 2
                        set bj_forLoopAIndexEnd = 14
                        loop
                            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
                            set udg_Temp_value = ( udg_Temp_value + ( udg_Temp_Materials_A[GetForLoopIndexA()] - udg_Temp_Materials_B[GetForLoopIndexA()] ) )
                            set bj_forLoopAIndex = bj_forLoopAIndex + 1
                        endloop
                        // Looping through other intexes, determining if the item is one of the 10 best that the player is able to create, based upon leftover materials
                        set bj_forLoopAIndex = 1
                        set bj_forLoopAIndexEnd = 10
                        loop
                            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
                            if ( ( udg_Combiner_Items_Remainder[GetForLoopIndexA()] >= udg_Temp_value ) ) then
                                set udg_Temp_value_3 = 1
                                loop
                                    exitwhen udg_Temp_value_3 > 9
                                    if ( Trig_Combiner_JASS_Func012Func003Func002Func004Func002Func006Func001Func001Func001C() ) then
                                        set udg_Combiner_Items[( 11 - udg_Temp_value_3 )] = udg_Combiner_Items[( 10 - udg_Temp_value_3 )]
                                        set udg_Combiner_Items_Remainder[( 11 - udg_Temp_value_3 )] = udg_Combiner_Items_Remainder[( 10 - udg_Temp_value_3 )]
                                    else
                                    endif
                                    set udg_Temp_value_3 = udg_Temp_value_3 + 1
                                endloop
                                set udg_Combiner_Items[GetForLoopIndexA()] = udg_Item_Type[GetForLoopIndexB()]
                                set udg_Combiner_Items_Remainder[GetForLoopIndexA()] = udg_Temp_value
                                call DisplayTextToForce( GetPlayersAll(), ( "Organizing! Temp_value (New item index): " + I2S(udg_Temp_value) ) )
                                exitwhen true
                            endif
                            set bj_forLoopAIndex = bj_forLoopAIndex + 1
                        endloop
                    endif
                else
                    set udg_Temp_value_2 = 30
                endif
                set udg_Temp_value_2 = udg_Temp_value_2 + 1
            endloop
            set bj_forLoopBIndex = bj_forLoopBIndex + 1
        endloop
    endif
    set udg_Temp_value = 0
    set udg_Temp_value_2 = 0
    set udg_Temp_value_3 = 0
    set bj_forLoopBIndex = 1
    set bj_forLoopBIndexEnd = 14
    loop
        exitwhen bj_forLoopBIndex > bj_forLoopBIndexEnd
        set udg_Temp_Materials_A[GetForLoopIndexB()] = 0
        set bj_forLoopBIndex = bj_forLoopBIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Combiner_JASS takes nothing returns nothing
    set gg_trg_Combiner_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Combiner_JASS, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Combiner_JASS, Condition( function Trig_Combiner_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Combiner_JASS, function Trig_Combiner_JASS_Actions )
endfunction
 

Steel

Software Engineer
Reaction score
109
Code:
globals
integer udg_Temp_value
integer udg_Temp_value_2
integer udg_Temp_value_3
integer array udg_Item_Codes
integer array udg_Item_Type
integer array udg_Temp_Materials
integer array udg_Temp_Materials_A
integer array udg_Temp_Materials_B
integer array udg_Item_Codes_Elements
string udg_Temp_String
integer array udg_Combiner_Items
integer array udg_Combiner_Items_Remainder
endglobals

Those are all of your globals. Now, if you don't use those globals in any other triggers then we can start to clean things up since thats a LOT of globals. We have that function you left and we need to fix that, its a biconditional statement. So you would have something like if ( (something) and (something) ) then

So that statement is replaced by using: (((10-udg_Temp_value_3)>=GetForLoopIndexA()) and ((10-udg_Temp_value_3) <=9))

Here is your trigger now....but its localized:
Code:
globals
trigger gg_trg_Combiner_JASS
endglobals

function Trig_Combiner_JASS_Conditions takes nothing returns boolean
return ( GetSpellAbilityId() == 'A01T' ) 
endfunction

function Trig_Combiner_JASS_Actions takes nothing returns nothing
local integer array tempvalues
local integer array itemcodes
local integer array itemtypevar
local integer array tempmaterials
local integer array tempmaterialsA
local integer array tempmaterialsB
local integer array itemcodeelements
local integer array combineritems
local integer array combineritemsremainder
local integer loopvara
local integer loopvarb
local string tempstr

    set tempvalues[0] = 0
    set tempvalues[1] = 0
    // Weapon-Type Detection
    set loopvara = 1
    loop
        exitwhen loopvara > 6
        if ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == ITEM_TYPE_PERMANENT ) then
            if ( tempvalues[0] == 0 ) then
                set loopvarb = 14
                loop
                    exitwhen loopvarb > 71
                    if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == itemtypevar[loopvarb] ) then
                        set tempvalues[0] = ( ( itemcodes[loopvarb] - ModuloInteger(itemcodes[loopvarb], 1000000) ) / 1000000 )
                        exitwhen true
                    endif
                    set loopvarb = loopvarb + 1
                endloop
            else
                set loopvarb = 14
                loop
                    exitwhen loopvarb > 71
                    if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == itemtypevar[loopvarb] ) then
                        if ( tempvalues[0] == ( ( itemcodes[loopvarb] - ModuloInteger(itemcodes[loopvarb], 1000000) ) / 1000000 ) ) then
                        else
                            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), "TRIGSTR_1906" )
                            set tempvalues[0] = 0
                            return
                        endif
                        exitwhen true
                    endif
                    set loopvarb = loopvarb + 1
                endloop
            endif
        endif
        set loopvara = loopvara + 1
    endloop



    set tempvalues[0] = 0
    // Code Addition, 14 size array A
    set loopvara = 1
    loop
        exitwhen loopvara > 6
        set loopvarb = 2
        loop
            exitwhen loopvarb > 71
            if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == itemtypevar[loopvarb] ) then
                if ( tempmaterialsA[1] == 0 ) then
                    set tempmaterialsA[1] = ( ( itemcodes[loopvarb] - ModuloInteger(itemcodes[loopvarb], 1000000) ) / 1000000 )
                endif
                if ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == ITEM_TYPE_CHARGED ) then
                    set tempvalues[1] = 2
                    loop
                        exitwhen tempvalues[1] > 14
                        if ( tempvalues[1] <= 7 ) then
                            if ( tempvalues[1] <= 6 ) then
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ( ( ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) - ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) ))) ) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) ) )
                            else
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) ) )
                            endif
                        else
                            if ( tempvalues[1] <= 13 ) then
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ( ( ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) - ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) ))) ) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) ) )
                            else
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) ) )
                            endif
                        endif
                        set tempvalues[1] = tempvalues[1] + 1
                    endloop
                else
                    set tempvalues[1] = 2
                    loop
                        exitwhen tempvalues[1] > 14
                        if ( tempvalues[1] <= 7 ) then
                            if ( tempvalues[1] <= 6 ) then
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ( ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) - ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) ))) ) )
                            else
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) )
                            endif
                        else
                            if ( tempvalues[1] <= 13 ) then
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ( ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) - ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) ))) ) )
                            else
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) )
                            endif
                        endif
                        set tempvalues[1] = tempvalues[1] + 1
                    endloop
                endif
                exitwhen true
            endif
            set loopvarb = loopvarb + 1
        endloop
        set loopvara = loopvara + 1
    endloop
    set tempvalues[1] = 0
    // +9 item detection
    set loopvara = 2
    loop
        exitwhen loopvara > 14
        if ( ( tempmaterialsA[loopvara] >= 10 ) ) then
            set tempstr = GetObjectName( itemcodes[ loopvara ] )
            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), ( "You may only use a maximum of 9 of each type of material. You have " + ( I2S(tempmaterialsA[loopvara]) + ( " of the material " + tempstr ) ) ) )
            set tempvalues[0] = 0
            set loopvarb = 1
            loop
                exitwhen loopvarb > 14
                set tempmaterialsA[loopvarb] = 0
                set loopvarb = loopvarb + 1
            endloop
            return
        endif
        set loopvara = loopvara + 1
    endloop
    // Item Familiarity
    if ( tempmaterialsA[1] == 1 ) then
        // Sword Verification
        // Looping through all swords
        set loopvarb = 15
        loop
            exitwhen loopvarb > 71
            // Looping through materials
            set tempvalues[1] = 2
            loop
                exitwhen tempvalues[1] > 14
                // Since the materials are stored in 2 different variables, it changes which variable it calls upon depending on the loop number (1-7 in variable Item_Codes, 8-14 in Item_Codes_Elements)
                if ( ( tempvalues[1] <= 7 ) ) then
                    if ( ( tempvalues[1] <= 6 ) ) then
                        set tempmaterialsB[tempvalues[1]] = ( 0 + ( ( ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) - ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) ))) ) )
                    else
                        set tempmaterialsB[tempvalues[1]] = ( 0 + ModuloInteger(itemcodes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) )
                    endif
                else
                    if ( ( tempvalues[1] <= 13 ) ) then
                        set tempmaterialsB[tempvalues[1]] = ( 0 + ( ( ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) - ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) ))) ) )
                    else
                        set tempmaterialsB[tempvalues[1]] = ( 0 + ModuloInteger(itemcodeelements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) )
                    endif
                endif
                // Starting the similarity process, initiates once Temp_Value_2=14
                if ( tempmaterialsA[tempvalues[1]] >= tempmaterialsB[tempvalues[1]] ) then
                    if ( tempvalues[1] == 14 ) then
                        call DisplayTextToForce( GetPlayersAll(), ( ( "Loop A (2-14 mat add)=" + I2S(loopvara) ) + ( "; " + ( "Loop B (15-71 item finder)=" + I2S(loopvarb) ) ) ) )
                        set loopvara = 1
                        loop
                            exitwhen loopvara > 14
                            call DisplayTextToForce( GetPlayersAll(), ( ( "index " + I2S(loopvara) ) + ( ": A=" + ( ( I2S(tempmaterialsA[loopvara]) + ", B=" ) + I2S(tempmaterialsB[loopvara]) ) ) ) )
                            set loopvara = loopvara + 1
                        endloop
                        // Creating an idex for the item, based upon the amount of materials left over
                        set loopvara = 2
                        loop
                            exitwhen loopvara > 14
                            set tempvalues[0] = ( tempvalues[0] + ( tempmaterialsA[loopvara] - tempmaterialsB[loopvara] ) )
                            set loopvara = loopvara + 1
                        endloop
                        // Looping through other intexes, determining if the item is one of the 10 best that the player is able to create, based upon leftover materials
                        set loopvara = 1
                        loop
                            exitwhen loopvara > 10
                            if ( ( combineritemsremainder[loopvara] >= tempvalues[0] ) ) then
                                set tempvalues[2] = 1
                                loop
                                    exitwhen tempvalues[2] > 9
                                    if ( (((10-tempvalues[2])>=loopvara) and ((10-tempvalues[2]) <=9)) ) then
                                        set combineritems[( 11 - tempvalues[2] )] = combineritems[( 10 - tempvalues[2] )]
                                        set combineritemsremainder[( 11 - tempvalues[2] )] = combineritemsremainder[( 10 - tempvalues[2] )]
                                    else
                                    endif
                                    set tempvalues[2] = tempvalues[2] + 1
                                endloop
                                set combineritems[loopvara] = itemtypevar[loopvarb]
                                set combineritemsremainder[loopvara] = tempvalues[0]
                                call DisplayTextToForce( GetPlayersAll(), ( "Organizing! Temp_value (New item index): " + I2S(tempvalues[0]) ) )
                                exitwhen true
                            endif
                            set loopvara = loopvara + 1
                        endloop
                    endif
                else
                    set tempvalues[1] = 30
                endif
                set tempvalues[1] = tempvalues[1] + 1
            endloop
            set loopvarb = loopvarb + 1
        endloop
    endif
    set tempvalues[0] = 0
    set tempvalues[1] = 0
    set tempvalues[2] = 0
    set loopvarb = 1
    loop
        exitwhen loopvarb > 14
        set tempmaterialsA[loopvarb] = 0
        set loopvarb = loopvarb + 1
    endloop
    
    set tempstr = null
endfunction

//===========================================================================
function InitTrig_Combiner_JASS takes nothing returns nothing
    set gg_trg_Combiner_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Combiner_JASS, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Combiner_JASS, Condition( function Trig_Combiner_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Combiner_JASS, function Trig_Combiner_JASS_Actions )
endfunction

I'll take a look at how the trigger works now to see if I can't fix it up.
 

2evil

New Member
Reaction score
16
I revised it a little to include 3 of the globals that were edited out (they are needed in other triggers) I am about to test it, but here it is:

Code:
globals
trigger gg_trg_Combiner_JASS
integer array udg_Item_Codes
integer array udg_Item_Codes_Elements
item-type array udg_Item_Type
endglobals

function Trig_Combiner_JASS_Conditions takes nothing returns boolean
return ( GetSpellAbilityId() == 'A01T' ) 
endfunction

function Trig_Combiner_JASS_Actions takes nothing returns nothing
local integer array tempvalues
local integer array tempmaterialsA
local integer array tempmaterialsB
local item-type array combineritems
local integer array combineritemsremainder
local integer loopvara
local integer loopvarb
local string tempstr

    set tempvalues[0] = 0
    set tempvalues[1] = 0
    // Weapon-Type Detection
    set loopvara = 1
    loop
        exitwhen loopvara > 6
        if ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == ITEM_TYPE_PERMANENT ) then
            if ( tempvalues[0] == 0 ) then
                set loopvarb = 14
                loop
                    exitwhen loopvarb > 71
                    if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == udg_Item_Type[loopvarb] ) then
                        set tempvalues[0] = ( ( udg_Item_Codes[loopvarb] - ModuloInteger(udg_Item_Codes[loopvarb], 1000000) ) / 1000000 )
                        exitwhen true
                    endif
                    set loopvarb = loopvarb + 1
                endloop
            else
                set loopvarb = 14
                loop
                    exitwhen loopvarb > 71
                    if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == udg_Item_Type[loopvarb] ) then
                        if ( tempvalues[0] == ( ( udg_Item_Codes[loopvarb] - ModuloInteger(udg_Item_Codes[loopvarb], 1000000) ) / 1000000 ) ) then
                        else
                            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), "TRIGSTR_1906" )
                            set tempvalues[0] = 0
                            return
                        endif
                        exitwhen true
                    endif
                    set loopvarb = loopvarb + 1
                endloop
            endif
        endif
        set loopvara = loopvara + 1
    endloop



    set tempvalues[0] = 0
    // Code Addition, 14 size array A
    set loopvara = 1
    loop
        exitwhen loopvara > 6
        set loopvarb = 2
        loop
            exitwhen loopvarb > 71
            if ( GetItemTypeId(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == udg_Item_Type[loopvarb] ) then
                if ( tempmaterialsA[1] == 0 ) then
                    set tempmaterialsA[1] = ( ( udg_Item_Codes[loopvarb] - ModuloInteger(udg_Item_Codes[loopvarb], 1000000) ) / 1000000 )
                endif
                if ( GetItemType(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) == ITEM_TYPE_CHARGED ) then
                    set tempvalues[1] = 2
                    loop
                        exitwhen tempvalues[1] > 14
                        if ( tempvalues[1] <= 7 ) then
                            if ( tempvalues[1] <= 6 ) then
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ( ( ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) - ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) ))) ) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) ) )
                            else
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) ) )
                            endif
                        else
                            if ( tempvalues[1] <= 13 ) then
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ( ( ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) - ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) ))) ) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) ) )
                            else
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) * GetItemCharges(UnitItemInSlotBJ(GetSpellAbilityUnit(), loopvara)) ) )
                            endif
                        endif
                        set tempvalues[1] = tempvalues[1] + 1
                    endloop
                else
                    set tempvalues[1] = 2
                    loop
                        exitwhen tempvalues[1] > 14
                        if ( tempvalues[1] <= 7 ) then
                            if ( tempvalues[1] <= 6 ) then
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ( ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) - ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) ))) ) )
                            else
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) )
                            endif
                        else
                            if ( tempvalues[1] <= 13 ) then
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ( ( ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) - ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) ))) ) )
                            else
                                set tempmaterialsA[tempvalues[1]] = ( tempmaterialsA[tempvalues[1]] + ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) )
                            endif
                        endif
                        set tempvalues[1] = tempvalues[1] + 1
                    endloop
                endif
                exitwhen true
            endif
            set loopvarb = loopvarb + 1
        endloop
        set loopvara = loopvara + 1
    endloop
    set tempvalues[1] = 0
    // +9 item detection
    set loopvara = 2
    loop
        exitwhen loopvara > 14
        if ( ( tempmaterialsA[loopvara] >= 10 ) ) then
            set tempstr = GetObjectName( udg_Item_Codes[ loopvara ] )
            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellAbilityUnit())), ( "You may only use a maximum of 9 of each type of material. You have " + ( I2S(tempmaterialsA[loopvara]) + ( " of the material " + tempstr ) ) ) )
            set tempvalues[0] = 0
            set loopvarb = 1
            loop
                exitwhen loopvarb > 14
                set tempmaterialsA[loopvarb] = 0
                set loopvarb = loopvarb + 1
            endloop
            return
        endif
        set loopvara = loopvara + 1
    endloop
    // Item Familiarity
    if ( tempmaterialsA[1] == 1 ) then
        // Sword Verification
        // Looping through all swords
        set loopvarb = 15
        loop
            exitwhen loopvarb > 71
            // Looping through materials
            set tempvalues[1] = 2
            loop
                exitwhen tempvalues[1] > 14
                // Since the materials are stored in 2 different variables, it changes which variable it calls upon depending on the loop number (1-7 in variable Item_Codes, 8-14 in Item_Codes_Elements)
                if ( ( tempvalues[1] <= 7 ) ) then
                    if ( ( tempvalues[1] <= 6 ) ) then
                        set tempmaterialsB[tempvalues[1]] = ( 0 + ( ( ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) - ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 7.00 - I2R(tempvalues[1]) ))) ) )
                    else
                        set tempmaterialsB[tempvalues[1]] = ( 0 + ModuloInteger(udg_Item_Codes[loopvarb], R2I(Pow(10.00, ( 8.00 - I2R(tempvalues[1]) )))) )
                    endif
                else
                    if ( ( tempvalues[1] <= 13 ) ) then
                        set tempmaterialsB[tempvalues[1]] = ( 0 + ( ( ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) - ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) )))) ) / R2I(Pow(10.00, ( 14.00 - I2R(tempvalues[1]) ))) ) )
                    else
                        set tempmaterialsB[tempvalues[1]] = ( 0 + ModuloInteger(udg_Item_Codes_Elements[loopvarb], R2I(Pow(10.00, ( 15.00 - I2R(tempvalues[1]) )))) )
                    endif
                endif
                // Starting the similarity process, initiates once Temp_Value_2=14
                if ( tempmaterialsA[tempvalues[1]] >= tempmaterialsB[tempvalues[1]] ) then
                    if ( tempvalues[1] == 14 ) then
                        call DisplayTextToForce( GetPlayersAll(), ( ( "Loop A (2-14 mat add)=" + I2S(loopvara) ) + ( "; " + ( "Loop B (15-71 item finder)=" + I2S(loopvarb) ) ) ) )
                        set loopvara = 1
                        loop
                            exitwhen loopvara > 14
                            call DisplayTextToForce( GetPlayersAll(), ( ( "index " + I2S(loopvara) ) + ( ": A=" + ( ( I2S(tempmaterialsA[loopvara]) + ", B=" ) + I2S(tempmaterialsB[loopvara]) ) ) ) )
                            set loopvara = loopvara + 1
                        endloop
                        // Creating an idex for the item, based upon the amount of materials left over
                        set loopvara = 2
                        loop
                            exitwhen loopvara > 14
                            set tempvalues[0] = ( tempvalues[0] + ( tempmaterialsA[loopvara] - tempmaterialsB[loopvara] ) )
                            set loopvara = loopvara + 1
                        endloop
                        // Looping through other intexes, determining if the item is one of the 10 best that the player is able to create, based upon leftover materials
                        set loopvara = 1
                        loop
                            exitwhen loopvara > 10
                            if ( ( combineritemsremainder[loopvara] >= tempvalues[0] ) ) then
                                set tempvalues[2] = 1
                                loop
                                    exitwhen tempvalues[2] > 9
                                    if ( (((10-tempvalues[2])>=loopvara) and ((10-tempvalues[2]) <=9)) ) then
                                        set combineritems[( 11 - tempvalues[2] )] = combineritems[( 10 - tempvalues[2] )]
                                        set combineritemsremainder[( 11 - tempvalues[2] )] = combineritemsremainder[( 10 - tempvalues[2] )]
                                    else
                                    endif
                                    set tempvalues[2] = tempvalues[2] + 1
                                endloop
                                set combineritems[loopvara] = udg_Item_Type[loopvarb]
                                set combineritemsremainder[loopvara] = tempvalues[0]
                                call DisplayTextToForce( GetPlayersAll(), ( "Organizing! Temp_value (New item index): " + I2S(tempvalues[0]) ) )
                                exitwhen true
                            endif
                            set loopvara = loopvara + 1
                        endloop
                    endif
                else
                    set tempvalues[1] = 30
                endif
                set tempvalues[1] = tempvalues[1] + 1
            endloop
            set loopvarb = loopvarb + 1
        endloop
    endif
    set tempvalues[0] = 0
    set tempvalues[1] = 0
    set tempvalues[2] = 0
    set loopvarb = 1
    loop
        exitwhen loopvarb > 14
        set tempmaterialsA[loopvarb] = 0
        set loopvarb = loopvarb + 1
    endloop
    
    set tempstr = null
endfunction

//===========================================================================
function InitTrig_Combiner_JASS takes nothing returns nothing
    set gg_trg_Combiner_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Combiner_JASS, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Combiner_JASS, Condition( function Trig_Combiner_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Combiner_JASS, function Trig_Combiner_JASS_Actions )
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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