1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. The mythological era has spawned some interesting characters around. Check them out and be sure to vote for them in the 30th Poll of the Texturing Contest.
    Dismiss Notice
  3. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  4. Hivers united and created a bunch of 2v2 melee maps. Vote for the best in our Melee Mapping Contest #4 - Poll!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

Trigger Viewer

Item fusion Shop 2.0.2.w3x
Variables
Item Fusion Shop
Item Fusion shop
How To copy
GUI Wrapper
IFS Add Item
IFS Add Fusion
Confige below
IFS Init Fusion GUI
INit Fusions Jass
IFS Init Item
IFS Init General
Demo Map only
Use Upgrades Spell
Hero Gains Item
ShowAll
Map Only
Kartenspezifischen eigenen Skript-Code unten eingeben. Dieser Text wird in das Karten-Skript nach der Deklaration der Variablen und vor jeglichem Auslöser-Code eingefügt.
function EnableScriptUsage takes nothing returns nothing
endfunction
Name Type Is Array Initial Value
IFShop_Bagpack_Enabled boolean Yes
IFShop_Bagpack_Hero_Max_Distan real No
IFShop_Bagpack_Pick_SlotBased boolean No
IFShop_Bagpack_Shopper_First boolean No
IFShop_Bagpack_Timer timer No
IFShop_Buy_Zones rect Yes
IFShop_Buy_Zones_Excluded force Yes
IFShop_Buy_Zones_Last integer No
IFShop_Continue_After_Fusion boolean Yes
IFShop_Fusion_SFX_Path modelfile No
IFShop_Gold integer No
IFShop_Is_Shopping boolean Yes
IFShop_Item_List_Fusions_Last integer No
IFShop_Item_Stack item Yes
IFShop_Item_Stack_Last integer No
IFShop_Item_Type itemcode No
IFShop_Mats itemcode Yes
IFShop_Page_Current integer Yes
IFShop_Page_Max integer Yes
IFShop_Page_Skill_Button abilcode Yes
IFShop_Page_Skill_Next abilcode No
IFShop_Page_Skill_Previous abilcode No
IFShop_Page_Skill_Select abilcode No
IFShop_Shop unit Yes
IFShop_Shop_Avaible_Fuse_Costs integer Yes
IFShop_Shop_Avaible_Fuse_First integer Yes
IFShop_Shop_Avaible_Fuse_Last integer Yes
IFShop_Shop_Avaible_Fuse_plans itemcode Yes
IFShop_Shop_Avaible_Fusions integer Yes
IFShop_Shop_Bagpack_Accessable boolean Yes
IFShop_Shop_LastTry itemcode Yes
IFShop_Shop_Shopper unit Yes
IFShop_Shop_Shopper_Bagpack unit Yes
IFShop_Shop_UnitType unitcode No
IFShop_Shopper_Count integer No
IFShop_ShowMaxUpgrades boolean Yes
IFShop_Skill_Show_Upgrades abilcode No
IFShop_Sound_No_Gold sound No
IFShop_Strings string Yes
IFShop_Table hashtable No
//Item Fusion Shop 2.0.2
//By Tasyen
//============

//Item fusion shop is a Recipe System showing possible upgrades of an item inside the Warcraft basic user interface.
//The system calculates the needed gold cost and regards items already obtained by the hero and its bagpack, if wanted.
//This way the player gets control over the fusions he want to do and it feels like visiting a shop in basic Warcraft 3.

//============
//  API Fusion Creation
//============
//  function IFShopAddFusion takes integer fusion, integer mat0, integer mat1, integer mat2, integer mat3, integer mat4, integer mat5, integer mat6 returns boolean
//      Creates a Fusion with Mat 0 to 6 returns.
//      builtInfo is the stuff the item grants, keep compact probably a list is enough.
//      You need to set all mats, with a ItemTypeId or 0 for not needed.
//      Auto generates a Requier String List

//  function IFShopAddMat takes integer mat, integer plan returns nothing
//      Adds a Material component to the plan
//      expects ItemTypeId
//      after beeing done with AddMats one can "call IFShopUpdateReqStrings(plan)" to generate a requier list.

//  function IFShopAddMatEx takes integer mat returns nothing
//      Wraper function for IFShopAddMat for the Last register Plan

//  function IFShopCreate takes integer fusion returns boolean
//      Creates a Fusion without material

//  function IFShopSetItemStringList takes integer itemType, string text returns nothing
//      Write only the content
//      On default one does not need to call that one.
//      Requier Lists are autogenerated and Gives List are using the Object Field Description of the fusion result.

//============
//  API Show Shop
//============
//  function IFShopIsInShopZone takes unit u returns boolean
//      Checks if the unit is inside an BuyZone which his owner can use.
//      This should be used before calling IFShopShow, but is not requiered.

//  function IFShopShow takes integer playerIndex, unit shopper, unit bagpack, integer itemType returns nothing
//      this will show the shop the owner of shopper
//      itemType = 0, will add all Ugrades of all items in the inventories of shopper and bagpack
//      itemType = -1 all Plans are added to the shop.
//============
// API  for getting fusions (not needed on default usage)
//============
//  function IFShopCalcCost takes integer playerIndex, unit shopper, unit bagpack returns nothing
//      calcs the goldcosts regarding owned items from the two units.
//      into udg_IFShop_Shop_Avaible_Fuse_Costs
//      you should fill the list with IFShopGetPossibleFusions before using this.

//  function IFShopResetPossibleFusion takes integer playerIndex returns nothing
//      Resets the listvariables at playerIndex.

//  function IFShopGetPossibleFusions takes integer itemType, integer playerIndex returns nothing
//      Loads all upgrades of the itemType into udg_IFShop_Shop_Avaible_Fuse_plans, udg_IFShop_Shop_Avaible_Fusions
//      MPI based access udg_IFShop_Shop_Avaible_Fuse_First,udg_IFShop_Shop_Avaible_Fuse_Last
//      udg_IFShop_ShowMaxUpgrades enables to show itemtypes upgrade's upgrade...,

//  function IFShopGetAllFusions takes integer playerIndex, integer start returns nothing
//      Loads all Plans registered for that player, starting from Plan start.
//============

// The intervale in which the System rechecks Bagpack useability
// Every x seconds useability of Bagpack is rechecked.
// Lower numbers are more accurate but more costly.
constant function IFShopTimerIntervale takes nothing returns real
    return 0.4
endfunction

//how many items can a shop contain?
//keep max player amount * this smaller than 32k (JASS_MAX_ARRAY_SIZE)
//this system uses GUI PlayerIds therefore the 0 IFShopPlayerShopSize block is not used.
constant function IFShopPlayerShopSize takes nothing returns integer
    return 500
endfunction

//this are the number of Items each page contains
//setting this to something higher than 9 is not working (2 pagecontrol +1 target control) (Wc3 V1.28.5)
//Each PageEntry needs 1 Ability beeing its button.
constant function IFShopPageSize takes nothing returns integer
    return 9
endfunction

//Strings used by this system, one could change them to change results a bit.
function IFShopInitStrings takes nothing returns nothing
    set udg_IFShop_Strings[0] = "\n\n|cffffA000Requiers|r:" //Requiers Word
    set udg_IFShop_Strings[1] = "\n  "      //Prefix for each Mat in the Requiers List beeing autogenerated
    set udg_IFShop_Strings[2] = "|cffffA000Gives|r:\n"  //Start of the builtInfo part, builtInfo uses item description of the fusion result.
    set udg_IFShop_Strings[3] = "\n\n|cffffA000Replaces|r:" //If a fusion needs only one Mat, this is used instead of Requiers.
    set udg_IFShop_Strings[4] = " - " //Prefix GoldCost Number
    set udg_IFShop_Strings[5] = " "+GetLocalizedString("GOLD") //Sufix GoldCost Number
    set udg_IFShop_Strings[6] = "x " //2x Axe, written after the number
   
    set udg_IFShop_Strings[7] = "|cffffff00Singpleplayer Info|r: " //Duplicat - Warning Prefix
    set udg_IFShop_Strings[8] = " amount of builtways: " //Duplicat - Warning Sufix
    set udg_IFShop_Strings[9] = "|cffff0000Error|r:|nIFShopPlayerShopSize limit was exceeded." //Warning IFShopPlayerShopSize exceeded
   
endfunction

//============
//System constants
//============
//hashtable saved:
//============
//  Normal items (itemCode 'I000'):
//============
//  +side   = beeing material in plan
//  0       = Goldvalue
//  -side   = built ways
//  0 = Granted Powers List as Text
//============
//  Item Handle
//============
//  0 = true -> Is already used in current calculation

//============
//  plans
//============
//  0   = -1 easy identyfier
//  0   = Requiered Item List as Text
//  1   = result
//  2   = Mat amount
//  3+  = Mats
//============

//The OrderId of select ShopTarget.
constant function IFShopSelectShopTarget takes nothing returns integer
    return 852566
endfunction

constant function IFShopAbiltiyIdSellItems takes nothing returns integer
    return 'Asid'
endfunction

constant function IFShopTableResult takes nothing returns integer
    return 1
endfunction

constant function IFShopTablePlan takes nothing returns integer
    return 0
endfunction

constant function IFShopTableMatAmount takes nothing returns integer
    return 2
endfunction

constant function IFShopTableMatStart takes nothing returns integer
    return 3
endfunction

//Is this buildway already registered?
function IFShopIsBuiltWay takes integer itemType, integer plan returns boolean
    local integer index = 0
    local integer ancestor
    //find next free ancestor spot
    loop
        set index = index -1
        set ancestor = LoadInteger(udg_IFShop_Table,itemType,index)
        exitwhen ancestor == 0
        if ancestor == plan then
            return true
        endif  
    endloop
    return false
endfunction

//Returns the already existing amount of builtways for an item
function IFShopGetBuiltWayCount takes integer itemType returns integer
    local integer index = 0
    //find next free ancestor spot
    loop
        set index = index -1
        exitwhen not HaveSavedInteger(udg_IFShop_Table,itemType,index)
    endloop
    return - (index + 1)
endfunction

//Remember that this item can be built by this plan.
//Builtways are saved at the -Side.
function IFShopAddBuiltWay takes integer itemType, integer plan returns nothing
    local integer index = 0
    if plan == 0 then
        return
    endif
    //find next free ancestor spot
    loop
        set index = index -1
        exitwhen not HaveSavedInteger(udg_IFShop_Table,itemType,index)
    endloop
    call SaveInteger(udg_IFShop_Table, itemType, index, plan)
endfunction

//Remebers that this item is used in plan as material
//Beeing Material is at the +Side.
function IFShopMatIsUsedInPlan takes integer itemType, integer plan returns nothing
    local integer index = 0
    if plan == 0 then
        return
    endif
    //find next free ancestor spot
    loop
        set index = index +1
        //Already know this mat can be used in this plan?
        if LoadInteger(udg_IFShop_Table,itemType,index) == plan then
            return
        endif
        exitwhen not HaveSavedInteger(udg_IFShop_Table,itemType,index)
    endloop
    call SaveInteger(udg_IFShop_Table, itemType, index, plan)
endfunction

//Updates the Requier string List also merges same mats as one strong with 2x Blade
//On Default everytime you use IFShopAddFusion
function IFShopUpdateReqStrings takes integer plan returns nothing
    local integer Loop_A = 0
    local integer matCount = LoadInteger(udg_IFShop_Table, plan, IFShopTableMatAmount())
    local integer array matTypes        //the types found
    local integer array matTypesAmount //Amount of items of type[index] found
    local integer matTypesCount = 0     //size of matTypes & matTypesAmount
    local string text = ""
    local integer itemType
    local boolean isNew
    loop
        exitwhen matCount == -1
        set itemType = LoadInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+matCount)
        set Loop_A = matTypesCount
        set isNew = true
        loop
            exitwhen Loop_A == 0
            if matTypes[Loop_A] == itemType then
                set isNew = false
                set matTypesAmount[Loop_A] = matTypesAmount[Loop_A] + 1
                exitwhen true
            endif

            set Loop_A = Loop_A -1
        endloop
        if isNew then
            set matTypesCount = matTypesCount + 1
            set matTypesAmount[matTypesCount] = 1
            set matTypes[matTypesCount] = itemType
        endif
        set matCount = matCount - 1
    endloop
   
    loop
        exitwhen matTypesCount == 0
        if matTypesAmount[matTypesCount] > 1 then
            set text = text + udg_IFShop_Strings[1]+ I2S(matTypesAmount[matTypesCount]) + udg_IFShop_Strings[6] +GetObjectName(matTypes[matTypesCount])
        else
            set text = text + udg_IFShop_Strings[1]+GetObjectName(matTypes[matTypesCount])
        endif
        set matTypesCount = matTypesCount - 1
    endloop
    call SaveStr(udg_IFShop_Table, plan, 0, text)
endfunction

function IFShopSetItemStringList takes integer itemType, string text returns nothing
    call SaveStr(udg_IFShop_Table, itemType, 0, text)
endfunction


//The most important API action
//It creates an new way to built an Fusion.
//taking up to 7 mats as argument ( this is not the max limit)
//function IFShopAddFusion takes integer fusion, integer plan, integer mat0, integer mat1, integer mat2, integer mat3, integer mat4, integer mat5, integer mat6 returns boolean
function IFShopAddFusion takes integer fusion, integer mat0, integer mat1, integer mat2, integer mat3, integer mat4, integer mat5, integer mat6 returns boolean
    local integer amount = -1
    local integer plan
    local item i
    set udg_IFShop_Item_List_Fusions_Last = udg_IFShop_Item_List_Fusions_Last + 1
    set plan = udg_IFShop_Item_List_Fusions_Last

    if not HaveSavedString (udg_IFShop_Table, fusion, 0) then
        set i = CreateItem(fusion,0,0)
        call SaveStr(udg_IFShop_Table, fusion, 0, BlzGetItemDescription(i))
        call RemoveItem(i)
        set i = null
    endif

    //PrintOut multiple Builtways in Single player, might be an possible error.
    if bj_isSinglePlayer then
        if IFShopGetBuiltWayCount(fusion) != 0 then
            call DisplayTimedTextToPlayer( GetLocalPlayer(),0,0, 30, udg_IFShop_Strings[7]+GetObjectName(fusion) + udg_IFShop_Strings[8] +I2S(IFShopGetBuiltWayCount(fusion)+1) )
        endif
    endif
    call IFShopAddBuiltWay(fusion, plan)

    //Save Fusion and plan
    call SaveInteger( udg_IFShop_Table, plan, IFShopTableResult(), fusion)
    call SaveInteger( udg_IFShop_Table, plan, IFShopTablePlan(), -1 )

   
    //Check for Mats and save them at nearest slot
    if( mat0 != 0) then
        set amount = amount + 1
        call SaveInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+amount,  mat0)
        call IFShopMatIsUsedInPlan(mat0, plan)
    endif
    if( mat1 != 0) then
        set amount = amount + 1
        call SaveInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+amount,  mat1)
        call IFShopMatIsUsedInPlan(mat1, plan)
    endif
    if( mat2 != 0) then
        set amount = amount + 1
        call SaveInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+amount,  mat2)
        call IFShopMatIsUsedInPlan(mat2, plan)
    endif
    if( mat3 != 0) then
        set amount = amount + 1
        call SaveInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+amount,  mat3)
        call IFShopMatIsUsedInPlan(mat3, plan)
    endif
    if( mat4 != 0) then
        set amount = amount + 1
        call SaveInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+amount,  mat4)
        call IFShopMatIsUsedInPlan(mat4, plan)
    endif
    if( mat5 != 0) then
        set amount = amount + 1
        call SaveInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+amount,  mat5)
        call IFShopMatIsUsedInPlan(mat5, plan)
    endif
    if( mat6 != 0) then
        set amount = amount + 1
        call SaveInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+amount,  mat6)
        call IFShopMatIsUsedInPlan(mat6, plan)
    endif

    call SaveInteger( udg_IFShop_Table, plan, IFShopTableMatAmount(), amount)
   
    call IFShopUpdateReqStrings(plan)
    return true
endfunction

//Adds material to plan.
function IFShopAddMat takes integer mat, integer plan returns nothing
    local integer amount
    //Ignore calls with no ItemType
    if( mat != 0 and plan != 0) then
        set amount = LoadInteger(udg_IFShop_Table, plan, IFShopTableMatAmount())+1
        call SaveInteger( udg_IFShop_Table, plan, IFShopTableMatAmount(), amount)
        call SaveInteger(udg_IFShop_Table, plan, IFShopTableMatStart()+amount,  mat)
        call IFShopMatIsUsedInPlan(mat, plan)
    endif
endfunction

//Add an material to the last created plan
function IFShopAddMatEx takes integer mat returns nothing
    call IFShopAddMat(mat, udg_IFShop_Item_List_Fusions_Last)
endfunction

//Creates an fusion without mats.
function IFShopCreate takes integer fusion returns boolean
   
    //PrintOut multiple Builtways in Single player, might be an possible error.
    if bj_isSinglePlayer then
        if IFShopGetBuiltWayCount(fusion) != 0 then
            call DisplayTimedTextToPlayer( GetLocalPlayer(),0,0, 30, udg_IFShop_Strings[7]+GetObjectName(fusion) + udg_IFShop_Strings[8] +I2S(IFShopGetBuiltWayCount(fusion)+1) )
        endif
    endif
    //Inc Pool Size
    set udg_IFShop_Item_List_Fusions_Last = udg_IFShop_Item_List_Fusions_Last + 1
    call IFShopAddBuiltWay(fusion, udg_IFShop_Item_List_Fusions_Last)
    //Save ItemTypes and mat amount
    call SaveInteger( udg_IFShop_Table, udg_IFShop_Item_List_Fusions_Last, IFShopTableResult(), fusion)
    call SaveInteger( udg_IFShop_Table, udg_IFShop_Item_List_Fusions_Last, IFShopTableMatAmount(), -1)
    call SaveStr( udg_IFShop_Table, udg_IFShop_Item_List_Fusions_Last, 0, "")
    return true
endfunction

//Updates the shop for this Player.
//Uses GUI Indexing Red = 1 blue = 2
function IFShopUpdate takes integer playerIndex returns nothing
    local integer Loop_A
    local integer Loop_A_End
    local integer itemType
    local integer counter = 0
    local player p = Player(playerIndex - 1)
    local string text
    //Clear Shop
    set Loop_A = IFShopPageSize()
    loop
        exitwhen Loop_A <= 0
        //call SetPlayerAbilityAvailable(p, udg_IFShop_Page_Skill_Button[Loop_A], false)
        call UnitRemoveAbility(udg_IFShop_Shop[playerIndex],udg_IFShop_Page_Skill_Button[Loop_A])
        set Loop_A = Loop_A - 1
    endloop


    call UnitRemoveAbility( udg_IFShop_Shop[playerIndex] , IFShopAbiltiyIdSellItems()  )
    call UnitAddAbility(  udg_IFShop_Shop[playerIndex] , IFShopAbiltiyIdSellItems() )

    //Is Multipaging needed?
    if( udg_IFShop_Page_Max[playerIndex] > 0) then
        //Get Current-Page ItemTypes
        set Loop_A = ( udg_IFShop_Shop_Avaible_Fuse_First[playerIndex] + ( IFShopPageSize() * udg_IFShop_Page_Current[playerIndex] ) )
        set Loop_A_End = Loop_A + (IFShopPageSize()-1)
        if  Loop_A_End > udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] then
            set Loop_A_End = udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex]
        endif  
        //Add Page Controll
        call UnitAddAbility(  udg_IFShop_Shop[playerIndex] ,udg_IFShop_Page_Skill_Next )
        call UnitAddAbility(  udg_IFShop_Shop[playerIndex] ,udg_IFShop_Page_Skill_Previous )   
    else
        //Remove Page Controll
        call UnitRemoveAbility( udg_IFShop_Shop[playerIndex], udg_IFShop_Page_Skill_Next )
        call UnitRemoveAbility( udg_IFShop_Shop[playerIndex], udg_IFShop_Page_Skill_Previous )
        //Get ItemTypes
        set Loop_A = udg_IFShop_Shop_Avaible_Fuse_First[playerIndex]
        set Loop_A_End = udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex]
    endif
    set counter = 1
    loop
        exitwhen Loop_A > Loop_A_End
        set itemType = udg_IFShop_Shop_Avaible_Fusions[Loop_A]

        if GetLocalPlayer() == p then
            if LoadInteger(udg_IFShop_Table, udg_IFShop_Shop_Avaible_Fuse_plans[Loop_A], IFShopTableMatAmount()) == 0 then
                if HaveSavedString(udg_IFShop_Table, itemType, 0) then //Has Gained Effect String List?
                    set text = udg_IFShop_Strings[2]+ LoadStr(udg_IFShop_Table, itemType, 0) + udg_IFShop_Strings[3] + LoadStr(udg_IFShop_Table, udg_IFShop_Shop_Avaible_Fuse_plans[Loop_A], 0)
                else
                    set text = BlzGetAbilityExtendedTooltip(itemType,1) + udg_IFShop_Strings[3] + LoadStr(udg_IFShop_Table, udg_IFShop_Shop_Avaible_Fuse_plans[Loop_A], 0)
                endif
            else
                if HaveSavedString(udg_IFShop_Table, itemType, 0) then
                    set text = udg_IFShop_Strings[2]+ LoadStr(udg_IFShop_Table, itemType, 0) + udg_IFShop_Strings[0] + LoadStr(udg_IFShop_Table, udg_IFShop_Shop_Avaible_Fuse_plans[Loop_A], 0)
                else
                    set text = BlzGetAbilityExtendedTooltip(itemType,1) + udg_IFShop_Strings[0] + LoadStr(udg_IFShop_Table, udg_IFShop_Shop_Avaible_Fuse_plans[Loop_A], 0)
                endif
            endif
           
            call BlzSetAbilityExtendedTooltip(udg_IFShop_Page_Skill_Button[counter], text,1)
            if udg_IFShop_Shop_Avaible_Fuse_Costs[Loop_A] > 0 then
                call BlzSetAbilityTooltip(udg_IFShop_Page_Skill_Button[counter],    BlzGetAbilityTooltip(itemType,1) + udg_IFShop_Strings[4]+I2S(udg_IFShop_Shop_Avaible_Fuse_Costs[Loop_A]) + udg_IFShop_Strings[5],1)
            else
                call BlzSetAbilityTooltip(udg_IFShop_Page_Skill_Button[counter],    BlzGetAbilityTooltip(itemType,1) ,1)
            endif
            call BlzSetAbilityIcon(udg_IFShop_Page_Skill_Button[counter], BlzGetAbilityIcon(itemType))

        endif
        //call SetPlayerAbilityAvailable(p, udg_IFShop_Page_Skill_Button[counter], true)
        call UnitAddAbility(udg_IFShop_Shop[playerIndex],udg_IFShop_Page_Skill_Button[counter])
        set counter = counter + 1
        set Loop_A = Loop_A + 1
    endloop
   
    set p = null
endfunction

//When one deselects the shop hide it.
function IFShopHide takes nothing returns nothing
    local integer playerIndex = GetPlayerId( GetOwningPlayer(GetTriggerUnit()) ) + 1
    //Clear and Hide Shop
    call UnitRemoveAbility( udg_IFShop_Shop[playerIndex] , IFShopAbiltiyIdSellItems()  )
    call ShowUnit(GetTriggerUnit(),false)
    set udg_IFShop_Is_Shopping[playerIndex] = false
    set udg_IFShop_Shopper_Count = udg_IFShop_Shopper_Count - 1
    //If none is shopping disable Backpack loop checking.
    if(udg_IFShop_Shopper_Count == 0) then
        call PauseTimer( udg_IFShop_Bagpack_Timer )
    endif
endfunction

function IFShopPageControl takes integer spell, integer playerIndex returns nothing
    if( spell == udg_IFShop_Page_Skill_Next ) then
        set udg_IFShop_Page_Current[playerIndex] = ( udg_IFShop_Page_Current[playerIndex] + 1 )
        //Return to Page 0?
        if ( udg_IFShop_Page_Current[playerIndex] > udg_IFShop_Page_Max[playerIndex]) then
            set udg_IFShop_Page_Current[playerIndex] = 0
        endif
    else
        //Previous Page.
        set udg_IFShop_Page_Current[playerIndex] = ( udg_IFShop_Page_Current[playerIndex] - 1 )
        //Return to max Max?
        if ( udg_IFShop_Page_Current[playerIndex] < 0) then
            set udg_IFShop_Page_Current[playerIndex] = udg_IFShop_Page_Max[playerIndex]
        endif
    endif
    call IFShopUpdate(playerIndex)
endfunction

//Checks if the unit is inside an BuyZone whiche his owner can use.
// This should be used before calling IFShopShow
function IFShopIsInShopZone takes unit u returns boolean
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local integer Loop_A=0
    //loop All Registere Buyzones.
    loop
        exitwhen Loop_A > udg_IFShop_Buy_Zones_Last
        //Is Shopper inside BuyZone and is his owner allowed to use it? yes = true
        if ( RectContainsCoords(udg_IFShop_Buy_Zones[Loop_A], x,y) and not (IsPlayerInForce ( GetOwningPlayer (u), udg_IFShop_Buy_Zones_Excluded[Loop_A] )) ) then
            return true
        endif
        set Loop_A = Loop_A + 1
    endloop
    return false
endfunction

function IFShopIsBagpackUseable takes unit shopper, unit bagpack returns boolean
    //Developer don't want Bagpack?
    if not(udg_IFShop_Bagpack_Enabled[GetPlayerId(GetOwningPlayer(shopper))+1])then
        return false
    endif
    //null Pointer?
    if GetUnitTypeId (bagpack) == 0 then
        return false
    endif
    //Bagpack is dead?
    if IsUnitType(bagpack, UNIT_TYPE_DEAD) then
        return false
    endif
    //In Range Check?
    if not IsUnitInRange(shopper, bagpack, udg_IFShop_Bagpack_Hero_Max_Distan) then
        return false
    endif
    return true
endfunction

//Helper Function
//Saves old Custom Value and loads into the stack
function IFShopCheckAndMarkItem takes item mat, integer itemType returns boolean
    //Filters other Item Types, Marked Items and Not existing items
    if(itemType != GetItemTypeId(mat) or HaveSavedBoolean(udg_IFShop_Table, GetHandleId(mat),0) or mat == null ) then
        return false
    endif
   
    //Inser into Item stack and  Mark it.
    set udg_IFShop_Item_Stack_Last = ( udg_IFShop_Item_Stack_Last + 1 )
    set udg_IFShop_Item_Stack[udg_IFShop_Item_Stack_Last] = mat
    call SaveBoolean(udg_IFShop_Table, GetHandleId(mat),0, true)
    return true
endfunction

//Resets the found itemTypes stack for this player.
//Playerindexes are in this system overall GUI-Like
//But if you do not use the shops you don't have care about that.
function IFShopResetPossibleFusion takes integer playerIndex returns nothing
    set udg_IFShop_Shop_Avaible_Fuse_First[playerIndex] = ( IFShopPlayerShopSize() * playerIndex )
    set udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] = ( udg_IFShop_Shop_Avaible_Fuse_First[playerIndex] - 1 )
    set udg_IFShop_Page_Max[playerIndex] = 0
    set udg_IFShop_Page_Current[playerIndex] = 0
endfunction

function IFShopGetPossibleFusions takes integer itemType, integer playerIndex returns nothing
    local integer Loop_B = 1
    local integer Loop_A = 0
    local integer plan
    local integer pageMembersReamining = IFShopPageSize()
    local integer counter = ( udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] - udg_IFShop_Shop_Avaible_Fuse_First[playerIndex]) +1
    local boolean skip
   
    //Loop the Material of current Fusion
    loop
        //Exceeds Players Array Size? yes -> stop. Should normally not happen.
        if ( counter >= IFShopPlayerShopSize() ) then
            //show Stacksize to small only in singleplayer.
            if bj_isSinglePlayer then
                call DisplayTimedTextToPlayer( GetLocalPlayer(),0,0, 30, udg_IFShop_Strings[9] )
            endif  
            return
        endif
        set plan = LoadInteger(udg_IFShop_Table, itemType, Loop_B)
        set skip = false
        exitwhen plan == 0
        //filter out duplicates.
        set Loop_A = udg_IFShop_Shop_Avaible_Fuse_First[playerIndex]
        loop
            exitwhen Loop_A > udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] or skip
            if plan == udg_IFShop_Shop_Avaible_Fuse_plans[Loop_A] then
                set skip = true
            endif  
            set Loop_A = Loop_A +1
        endloop
        // if no duplicate load it in.
        if not skip then
            set udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] = ( udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] + 1 )
            set udg_IFShop_Shop_Avaible_Fusions[udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex]] = LoadInteger(udg_IFShop_Table, plan, IFShopTableResult())
           
            set udg_IFShop_Shop_Avaible_Fuse_plans[udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex]] = plan
            set counter = counter + 1
            set pageMembersReamining = pageMembersReamining - 1
            //Is a new Page needed?
            if pageMembersReamining == -1 then
                set udg_IFShop_Page_Max[playerIndex] = udg_IFShop_Page_Max[playerIndex] + 1
                set pageMembersReamining = IFShopPageSize() - 1
            endif
            //Find Upgrade's Upgrades?
            if udg_IFShop_ShowMaxUpgrades[playerIndex] then
                call IFShopGetPossibleFusions(udg_IFShop_Shop_Avaible_Fusions[udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex]],playerIndex)
            endif
        endif
        set Loop_B = Loop_B + 1
    endloop
endfunction

function IFShopGetAllFusions takes integer playerIndex, integer start returns nothing
    local integer plan = start
    local integer result
    local integer counter = ( udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] - udg_IFShop_Shop_Avaible_Fuse_First[playerIndex]) +1
    local integer pageMembersReamining = IFShopPageSize()
    //Loop the Material of current Fusion
    loop
        //Exceeds Players Array Size? yes -> stop. Should normally not happen.
        if ( counter >= IFShopPlayerShopSize() ) then
            //show Stacksize to small only in singleplayer.
            if bj_isSinglePlayer then
                call DisplayTimedTextToPlayer( GetLocalPlayer(),0,0, 30, udg_IFShop_Strings[9] )
            endif  
            return
        endif
        set result = LoadInteger(udg_IFShop_Table, plan, IFShopTableResult())
        exitwhen result == 0
        set udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] = ( udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] + 1 )
        set udg_IFShop_Shop_Avaible_Fusions[udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex]] = result
       
        set udg_IFShop_Shop_Avaible_Fuse_plans[udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex]] = plan
        set counter = counter + 1
        set pageMembersReamining = pageMembersReamining - 1
        //Is a new Page needed?
        if pageMembersReamining == -1 then
            set udg_IFShop_Page_Max[playerIndex] = udg_IFShop_Page_Max[playerIndex] + 1
            set pageMembersReamining = IFShopPageSize() - 1
        endif
        set plan = plan + 1
    endloop

endfunction

function IFShopCheckInventory takes unit u, integer itemType returns boolean
    local integer Loop_B = 0
    //Checks Full Inventory
    loop
        exitwhen Loop_B == bj_MAX_INVENTORY
        if IFShopCheckAndMarkItem(UnitItemInSlot(u, Loop_B), itemType) then
            return true
        else
            set Loop_B = Loop_B + 1
        endif
    endloop
    return false
endfunction

function IFShopInventorySlotBased takes unit first, unit second, integer itemType returns boolean
    local integer Loop_B = 0
    //Checks Shopper Bagpacks Items in turns.
    loop
        exitwhen Loop_B == bj_MAX_INVENTORY
        if IFShopCheckAndMarkItem(UnitItemInSlot(first, Loop_B), itemType) then
            return true
        endif
        if IFShopCheckAndMarkItem(UnitItemInSlot(second, Loop_B), itemType) then
            return true
        endif  
        set Loop_B = Loop_B + 1
    endloop
    return false
endfunction

//Unmarks Items starting from start and setting size to the approached amount
function IFShopUnmarkMats takes integer start returns nothing
    local integer Loop_A = start
    loop
        exitwhen Loop_A > udg_IFShop_Item_Stack_Last
        call RemoveSavedBoolean(udg_IFShop_Table, GetHandleId(udg_IFShop_Item_Stack[Loop_A]),0)
        set Loop_A = Loop_A +1
    endloop
    set udg_IFShop_Item_Stack_Last = start - 1
endfunction

function IFShopGetSubFusions takes integer playerIndex, unit shopper, unit bagpack, integer plan returns integer
    local integer Loop_A = IFShopTableMatStart()
    local integer Loop_B = -1
    local integer subChoosen = Loop_B
    local integer subCurrent
    local integer subChoosenGold
    local integer subCurrentGold
    local integer costs = 0
    local integer unmarkStart
    local integer itemType
    local boolean matAvailable
    local integer subChoosenTry
    loop
        set itemType = LoadInteger(udg_IFShop_Table, plan, Loop_A )
        exitwhen itemType == null
        set matAvailable = false
        //Followng Defines the Order of accessing the inventories.
        //Is No Bagpack used or not allowed? yes -> simply check the Shopper.
        if not( udg_IFShop_Shop_Bagpack_Accessable[playerIndex] ) then
            set matAvailable = IFShopCheckInventory(shopper,itemType)
        else
            //Check Inventories in Turns?
            if udg_IFShop_Bagpack_Pick_SlotBased then
                //In Turns; Start with who?
                if udg_IFShop_Bagpack_Shopper_First then
                    set matAvailable = IFShopInventorySlotBased(shopper,bagpack,itemType)
                else   
                    set matAvailable = IFShopInventorySlotBased(bagpack,shopper,itemType)
                endif  
            else
                //Slotbased
                //Start with Shopper?
                if udg_IFShop_Bagpack_Shopper_First then
                    set matAvailable = IFShopCheckInventory(shopper,itemType)
                    //Still missing?
                    if not (matAvailable) then
                        set matAvailable = IFShopCheckInventory(bagpack,itemType)
                    endif  
                else
                    set matAvailable = IFShopCheckInventory(bagpack,itemType)
                    if not (matAvailable) then
                        set matAvailable = IFShopCheckInventory(shopper,itemType)
                    endif
                endif  
            endif
        endif
       
        //Mat unavaible?
        if not (matAvailable) then
            //Is Mat a Fusion? yes -> search for sub Material; Recursiv
            //Fusionitems have numbers saved in the -side aka built ways
            if(LoadInteger( udg_IFShop_Table, itemType, -1) != 0) then
                //Remember Index from where to unmark.
                //Without this sets the loop below won't work in recursion, why ever i had them before at the local init but it didn't work.
                set unmarkStart = udg_IFShop_Item_Stack_Last+1
                set subChoosenGold = 99999
                set Loop_B = -1
                //Loop all Builtways of this item and choose the cheapest.
                loop
                    set subCurrent = LoadInteger(udg_IFShop_Table,itemType,Loop_B)
                    exitwhen  subCurrent == 0
                    call IFShopUnmarkMats(unmarkStart)
                    set subCurrentGold = IFShopGetSubFusions(playerIndex, shopper, bagpack, subCurrent )
                    //Calced one Cheaper then cheapest?
                    if subCurrentGold < subChoosenGold then
                        set subChoosenTry = Loop_B
                        set subChoosen = subCurrent
                        set subChoosenGold = subCurrentGold
                    endif
                   
                    set Loop_B = Loop_B - 1
                endloop
                //mark + Load choosen items again
                //if was not found on last try
                if subChoosenTry != Loop_B + 1 then
                    call IFShopUnmarkMats(unmarkStart)
                    call IFShopGetSubFusions(playerIndex, shopper, bagpack, subChoosen )
                endif
                set costs = costs + subChoosenGold
            else
                //No Fusion; Increment Gold if wanted.
                set costs = costs + LoadInteger(udg_IFShop_Table, itemType, 0)
            endif
        endif
        set Loop_A = Loop_A + 1
    endloop
   
    return costs
endfunction

//This is called to calculate Gold Costs of all avaibleFusions for this player.
function IFShopCalcCost takes integer playerIndex, unit shopper, unit bagpack returns nothing
    local integer Loop_A = udg_IFShop_Shop_Avaible_Fuse_First[playerIndex]
    call IFShopUnmarkMats(0)
    //loop all Upgrade Options
    loop
        exitwhen Loop_A > udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex]
        set udg_IFShop_Shop_Avaible_Fuse_Costs[Loop_A] = IFShopGetSubFusions(playerIndex,shopper,bagpack,udg_IFShop_Shop_Avaible_Fuse_plans[Loop_A])
        call IFShopUnmarkMats(0)
        set Loop_A = Loop_A + 1
    endloop
endfunction

function IFShopTimerAction  takes nothing returns nothing
    local integer playerIndex = 1
    local boolean isAvaible=false
    //loop all Players
    loop
        exitwhen playerIndex >  bj_MAX_PLAYERS
        if udg_IFShop_Is_Shopping[playerIndex] and udg_IFShop_Bagpack_Enabled[playerIndex] then
            set isAvaible = IFShopIsBagpackUseable (udg_IFShop_Shop_Shopper[playerIndex],udg_IFShop_Shop_Shopper_Bagpack[playerIndex])
            //Bagpack accessability Changed?
            if udg_IFShop_Shop_Bagpack_Accessable[playerIndex] != isAvaible then
                //Access Changed Recalc Gold Costs.
                set udg_IFShop_Shop_Bagpack_Accessable[playerIndex] = isAvaible
                call IFShopCalcCost(playerIndex,udg_IFShop_Shop_Shopper[playerIndex],udg_IFShop_Shop_Shopper_Bagpack[playerIndex])
                call IFShopUpdate(playerIndex)
            endif
        endif
    set playerIndex = playerIndex + 1
    endloop    
endfunction

function IFShopShow takes integer playerIndex, unit shopper, unit bagpack, integer itemType returns nothing
    local integer Loop_A = 0
    set udg_IFShop_Shop_Bagpack_Accessable[playerIndex] = IFShopIsBagpackUseable(shopper,bagpack)
    //IFShopGetPossibleFusions only if not the same as last try or it is 0 aka whole inventory?
    if udg_IFShop_Shop_LastTry[playerIndex] != itemType or itemType == 0 or itemType == -1 then
        set udg_IFShop_Shop_LastTry[playerIndex] = itemType
        call IFShopResetPossibleFusion(playerIndex)
        //specific item
        if itemType > 0 then
            call IFShopGetPossibleFusions(itemType,playerIndex)
        elseif itemType == 0 then //all upgrades of carried Items
            //Non specific item show all avaible Upgrades of all items in shopper's and bagpack's inventory
            //Load Inventory
            set Loop_A = 0
            //Hero
            loop
                exitwhen Loop_A == bj_MAX_INVENTORY
                set itemType =  GetItemTypeId(UnitItemInSlot(shopper, Loop_A))
                if itemType != 0 then
                    call IFShopGetPossibleFusions(itemType,playerIndex)
                endif
                set Loop_A = Loop_A + 1
            endloop
            //bagpack exists?
            if  GetUnitTypeId(bagpack) != 0 and udg_IFShop_Bagpack_Enabled[playerIndex] then
                //Bagpack
                set Loop_A = 0
                loop
                    exitwhen Loop_A == bj_MAX_INVENTORY
                    set itemType = GetItemTypeId( UnitItemInSlot(bagpack, Loop_A))
                    if itemType != 0 then
                        call IFShopGetPossibleFusions(itemType,playerIndex)
                    endif
                    set Loop_A = Loop_A + 1
                endloop
            endif
        elseif itemType == -1 then //all plans registered
            call IFShopGetAllFusions(playerIndex, 1)
        endif
    endif
   
    //Does an Upgrade Exist?
    if( udg_IFShop_Shop_Avaible_Fuse_Last[playerIndex] >= udg_IFShop_Shop_Avaible_Fuse_First[playerIndex] ) then
        set udg_IFShop_Shopper_Count = udg_IFShop_Shopper_Count + 1
        //First Player Shopping? start Periodic check.
        if( udg_IFShop_Shopper_Count ==1 and udg_IFShop_Bagpack_Enabled[playerIndex]) then
            call TimerStart ( udg_IFShop_Bagpack_Timer, IFShopTimerIntervale(), true, function IFShopTimerAction)
        endif
        //Save Current Shopping Situation
        set udg_IFShop_Is_Shopping[playerIndex] = true
        set udg_IFShop_Shop_Shopper[playerIndex] = shopper
        set udg_IFShop_Shop_Shopper_Bagpack[playerIndex] = bagpack 
        call IFShopCalcCost(playerIndex,shopper,bagpack)
        //Inser upgrade Options and Open Shop
        call ShowUnit( udg_IFShop_Shop[playerIndex],true )
        call SetUnitX(udg_IFShop_Shop[playerIndex], GetUnitX(shopper))
        call SetUnitY(udg_IFShop_Shop[playerIndex], GetUnitY(shopper))
        call IFShopUpdate(playerIndex)
        call SelectUnitForPlayerSingle( udg_IFShop_Shop[playerIndex], Player(playerIndex - 1) )
        //Make Shop target Shopper.
        call IssueNeutralTargetOrderById( Player(playerIndex - 1), udg_IFShop_Shop[playerIndex], IFShopSelectShopTarget() , shopper)
    else
        //No Upgrades avaible Reselect Shopper.
        call SelectUnitForPlayerSingle( shopper, GetOwningPlayer(shopper) )
    endif
endfunction

function IFShopShowGUI takes nothing returns nothing
    local integer itemType
    local integer eid = GetHandleId(GetTriggerEventId())
    local unit shopper

    if eid == GetHandleId(EVENT_PLAYER_UNIT_SPELL_EFFECT) or eid == GetHandleId(EVENT_UNIT_SPELL_EFFECT) then
        set itemType = GetItemTypeId(GetSpellTargetItem())
        set shopper = GetTriggerUnit()
    elseif eid == GetHandleId(EVENT_PLAYER_UNIT_PICKUP_ITEM) or eid == GetHandleId(EVENT_UNIT_PICKUP_ITEM) then
        set itemType = GetItemTypeId(GetManipulatedItem())
        set shopper = GetTriggerUnit()
    elseif eid == GetHandleId(EVENT_GAME_ENTER_REGION)  then
        set itemType = -1
        set shopper = GetTriggerUnit() 
    else
        set itemType = 0
        set shopper = udg_IFShop_Shop_Shopper[0]
    endif
    if IFShopIsInShopZone(GetTriggerUnit()) then
        call IFShopShow(GetConvertedPlayerId(GetOwningPlayer(shopper)), shopper, udg_IFShop_Shop_Shopper_Bagpack[0], itemType)
    endif
    set udg_IFShop_Shop_Shopper_Bagpack[0] = null
    set shopper = null
endfunction

function IFShopDoFusion takes integer spell, integer playerIndex returns nothing
    local integer Loop_A = IFShopPageSize()
    local integer Loop_A_End
    local integer Loop_B = 0
    local integer itemType
    local integer indexInShop = 0
   
    local unit bagpack = udg_IFShop_Shop_Shopper_Bagpack[playerIndex]  
    local unit shopper = udg_IFShop_Shop_Shopper[playerIndex]
    call IFShopUnmarkMats(0)
    loop
        exitwhen Loop_A <= 0
        //Was this one bought?
        if ( udg_IFShop_Page_Skill_Button[Loop_A] == spell) then
            set indexInShop = udg_IFShop_Shop_Avaible_Fuse_First[playerIndex] + ( IFShopPageSize() * udg_IFShop_Page_Current[playerIndex] ) + Loop_A -1
            set itemType = udg_IFShop_Shop_Avaible_Fuse_plans[indexInShop]
            exitwhen true
        endif
        set Loop_A = Loop_A - 1
    endloop
    //Enough Gold?
    if( GetPlayerState( Player(playerIndex - 1), PLAYER_STATE_RESOURCE_GOLD) >= udg_IFShop_Shop_Avaible_Fuse_Costs[indexInShop] )then
        call AdjustPlayerStateBJ( ( -1 * udg_IFShop_Shop_Avaible_Fuse_Costs[indexInShop] ), Player(playerIndex - 1), PLAYER_STATE_RESOURCE_GOLD )
        // Collect avaible Fusion-Material
        call IFShopGetSubFusions(playerIndex, shopper, bagpack, itemType)
        //Destory Found material
        loop
            exitwhen Loop_B > udg_IFShop_Item_Stack_Last
            call RemoveSavedBoolean(udg_IFShop_Table, GetHandleId(udg_IFShop_Item_Stack[Loop_B]),0)
            call RemoveItem( udg_IFShop_Item_Stack[Loop_B] )
            set Loop_B = Loop_B + 1
        endloop
        //Create Fusion
        set itemType = udg_IFShop_Shop_Avaible_Fusions[indexInShop]
        call UnitAddItemByIdSwapped( itemType, shopper )
        call DestroyEffect( AddSpecialEffectTarget(udg_IFShop_Fusion_SFX_Path, shopper, "origin") )
       
        call IFShopHide()
        //continue Shopping, with gained Fusion?
        if udg_IFShop_Continue_After_Fusion[playerIndex] then
            call IFShopShow (playerIndex, shopper, bagpack, itemType)
        else
            call SelectUnitForPlayerSingle( shopper, GetTriggerPlayer() )
        endif
    else
        call StartSoundForPlayerBJ(GetTriggerPlayer() ,udg_IFShop_Sound_No_Gold)
    endif
   
    set shopper = null 
    set bagpack = null 
endfunction

//When an shop casts a spell
function IFShopCast takes nothing returns nothing
    local integer playerIndex = GetPlayerId(GetTriggerPlayer()) + 1
    local integer spell = GetSpellAbilityId()
    //Next Page used?
    if (spell == udg_IFShop_Page_Skill_Next or spell == udg_IFShop_Page_Skill_Previous) then
        call IFShopPageControl(spell, playerIndex)
    else
        call IFShopDoFusion(spell, playerIndex)
    endif
endfunction

//Creates all needed stuff.
function IFShopInit takes nothing returns nothing
    local trigger switchPage =CreateTrigger()
    local trigger hideShops =CreateTrigger()
    local integer playerIndex = 0
    local integer skillLoop
    local unit shop
    // Basic Setup
   
    set udg_IFShop_Shopper_Count = 0   
    set udg_IFShop_Table = InitHashtable()
    call TriggerAddAction( switchPage, function IFShopCast )
    call TriggerAddAction(hideShops, function IFShopHide)

    //Loop all Players;
    loop
        exitwhen playerIndex == bj_MAX_PLAYERS
        //Is Playing? Is User?
        if ( GetPlayerSlotState(Player(playerIndex)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(playerIndex)) == MAP_CONTROL_USER  ) then
            //Create Shops, Register: Page Controll, Shop Closing
            set shop = CreateUnit( Player(playerIndex), udg_IFShop_Shop_UnitType, GetStartLocationX(playerIndex), GetStartLocationY(playerIndex), 270.0)
            call UnitAddAbility(shop, udg_IFShop_Page_Skill_Next)
            call UnitAddAbility(shop, udg_IFShop_Page_Skill_Previous)
            call UnitAddAbility(shop, udg_IFShop_Page_Skill_Select)
            set skillLoop = IFShopPageSize()
            loop
                exitwhen skillLoop <= 0
                call UnitAddAbility(shop, udg_IFShop_Page_Skill_Button[skillLoop])
                set skillLoop = skillLoop - 1
            endloop
            call SetUnitPathing( shop, false )
           
            call TriggerRegisterUnitEvent( switchPage, shop, EVENT_UNIT_SPELL_CAST )
            call TriggerRegisterUnitEvent( hideShops, shop, EVENT_UNIT_DESELECTED )
            set udg_IFShop_Shop[playerIndex+1] = shop
        endif
        set playerIndex = playerIndex + 1
    endloop
    set shop = null
    call TriggerClearActions(gg_trg_Item_Fusion_shop)
    call IFShopInitStrings()
    call TriggerAddAction(gg_trg_Item_Fusion_shop, function IFShopShowGUI)
endfunction

//===========================================================================
function InitTrig_Item_Fusion_shop takes nothing returns nothing
    set gg_trg_Item_Fusion_shop = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Item_Fusion_shop, function IFShopInit )
endfunction
Make sure you set the Option "File - preferences - Create Unknown Variables".
Copy The Ability "IFS - Select Hero".
> "ItemFusionShop - Show Upgrades"
> "ItemFusionShop - Page Next"
> "ItemFusionShop - Page Previous"
> All of the "ItemFusionShop - Button" 1 to 9
Copy The "ItemFusionShop" Unit.
Copy the Folder "Item Fusion Shop"
Check out the Configer below Triggers, to complet missing links and fill the database.
To let units open the Item fusion shop checkout the Demo Map only folder.

If you get an error you might need to make sure that the mapheader contains an valid function.
Or check point 1.
IFS Add Item
  Events
  Conditions
  Actions
    Custom script: call SaveInteger(udg_IFShop_Table , udg_IFShop_Item_Type, 0, udg_IFShop_Gold )
IFS Add Fusion
  Events
  Conditions
  Actions
    Custom script: call IFShopAddFusion ( udg_IFShop_Item_Type, udg_IFShop_Mats[0], udg_IFShop_Mats[1], udg_IFShop_Mats[2], udg_IFShop_Mats[3], udg_IFShop_Mats[4], udg_IFShop_Mats[5], udg_IFShop_Mats[6])
    For each (Integer A) from 0 to 6, do (Actions)
      Loop - Actions
        Custom script: set udg_IFShop_Mats[bj_forLoopAIndex] = 0
    Custom script: set udg_IFShop_Item_Type = 0
IFS Init Fusion GUI
  Events
    Time - Elapsed game time is 0.00 seconds
  Conditions
  Actions
    -------- - --------
    -------- Inser the Fusions. --------
    -------- Item_Type = Result of the Fusion --------
    -------- Item_Type_Fake = Shown in the UI; Should have No Gold Cost, No Skills, No Modell, be Powerup --------
    -------- Mats[0 to 6], are Supported --------
    -------- You can split this trigger into multiple ones if it becomes to long. --------
    Set IFShop_Item_Type = Axt +12
    Set IFShop_Mats[0] = Claws of Attack +6
    Set IFShop_Mats[1] = Claws of Attack +6
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Blade +30
    Set IFShop_Mats[0] = Hammer +9
    Set IFShop_Mats[1] = Hammer +9
    Set IFShop_Mats[2] = Axt +12
    Set IFShop_Mats[3] = Rezept 200 Gold
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Blade +30
    Set IFShop_Mats[0] = Claws of Attack +6
    Set IFShop_Mats[1] = Claws of Attack +6
    Set IFShop_Mats[2] = Claws of Attack +6
    Set IFShop_Mats[3] = Claws of Attack +6
    Set IFShop_Mats[4] = Claws of Attack +6
    Set IFShop_Mats[5] = Rezept 200 Gold
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Blade +30
    Set IFShop_Mats[0] = Claws of Attack +6
    Set IFShop_Mats[1] = Axt +12
    Set IFShop_Mats[2] = Axt +12
    Set IFShop_Mats[3] = Rezept 200 Gold
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Crown of Kings +5
    Set IFShop_Mats[0] = Blade +30
    Set IFShop_Mats[1] = Blade +30
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Warsong Battle Drums
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Ancient Janggo of Endurance
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Legion Doom-Horn
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Cloak of Shadows
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Periapt of Vitality
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Boots of Speed
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Sobi Mask
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Runed Bracers
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Robe of the Magi +6
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Circlet of Nobility
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Pendant of Mana
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Ring of Regeneration
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Helm of Valor
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Scourge Bone Chimes
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = The Lion Horn of Stormwind
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Cloak of Flames
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Amulet of Spell Shield
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Ring of Protection +3
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Gloves of Haste
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Talisman of Evasion
    Set IFShop_Mats[0] = Built to many
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Belt of Giant Strength +6
    Set IFShop_Mats[0] = Gauntlets of Ogre Strength +3
    Set IFShop_Mats[1] = Gauntlets of Ogre Strength +3
    Set IFShop_Mats[2] = Rezept 200 Gold
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
    Set IFShop_Item_Type = Symbol of Strenght +12
    Set IFShop_Mats[0] = Belt of Giant Strength +6
    Set IFShop_Mats[1] = Belt of Giant Strength +6
    Trigger - Run IFS_Add_Fusion <gen> (ignoring conditions)
This is how one could do the fusion init completly in jass.
It is shorter and faster, if one likes this 4 Sign number stuff :|.
I created this cause my tests had wierd results which were fixed, but now i think it might be good to keep it.
function Trig_INit_Fusions_Actions takes nothing returns nothing
    //      result,    mats.
    call IFShopAddFusion ( 'ward', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'ajen', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'lgdh', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'clsd', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'prvt', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'bspd', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'rwiz', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'brac', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'ciri', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'cnob', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'rst1', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'rlif', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'hval', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'sbch', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'lhst', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'clfm', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'spsh', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'rde2', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'gcel', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'evtl', 'I000', 0,0,0,0,0,0)
    call IFShopAddFusion ( 'bgst', 'rst1', 'rst1','I004',0,0,0,0)
    call IFShopAddFusion ( 'I00S', 'bgst', 'bgst',0,0,0,0,0)
endfunction

//===========================================================================
function InitTrig_INit_Fusions_Jass takes nothing returns nothing
    set gg_trg_INit_Fusions_Jass = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_INit_Fusions_Jass, 0.00 )
    call TriggerAddAction( gg_trg_INit_Fusions_Jass, function Trig_INit_Fusions_Actions )
endfunction

 
IFS Init Item
  Events
  Conditions
  Actions
    -------- Inser the Items together with their Gold value --------
    Set IFShop_Item_Type = Claws of Attack +6
    Set IFShop_Gold = 200
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
    Set IFShop_Item_Type = Hammer +9
    Set IFShop_Gold = 300
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
    Set IFShop_Item_Type = Axt +12
    Set IFShop_Gold = 400
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
    Set IFShop_Item_Type = Blade +30
    Set IFShop_Gold = 1200
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
    Set IFShop_Item_Type = Rezept 200 Gold
    Set IFShop_Gold = 200
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
    Set IFShop_Item_Type = Gauntlets of Ogre Strength +3
    Set IFShop_Gold = 150
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
    Set IFShop_Item_Type = Belt of Giant Strength +6
    Set IFShop_Gold = 500
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
    Set IFShop_Item_Type = Symbol of Strenght +12
    Set IFShop_Gold = 1000
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
    Set IFShop_Item_Type = Built to many
    Set IFShop_Gold = 1000000
    Trigger - Run IFS_Add_Item <gen> (ignoring conditions)
Acces Order
Slotbased:
Shopper Bagpack
1 | 3 2 | 4
5 | 7 6 | 8
9 | 11 10 | 12

Inventory Acces:
1 | 2 7 | 8
3 | 4 9 | 10
5 | 6 11 | 12
IFS Init General
  Events
    Map initialization
  Conditions
  Actions
    Player Group - Pick every player in (All players) and do (Actions)
      Loop - Actions
        -------- After Fusing an Item shall the Upgrades of the fusion be shown and the shopping continue? --------
        Set IFShop_Continue_After_Fusion[(Player number of (Picked player))] = True
        -------- If enabled will show additional upgrades of upgrades. --------
        Set IFShop_ShowMaxUpgrades[(Player number of (Picked player))] = False
        -------- This player can use Bagpacks? --------
        Set IFShop_Bagpack_Enabled[(Player number of (Picked player))] = True
    -------- The Sound has to be created Inside Sound Editor --------
    -------- Default ones are placed inside: Sound/Interface/Warning/<Race> --------
    Set IFShop_Sound_No_Gold = MoreGold <gen>
    Set IFShop_Shop_UnitType = ItemFusionShop
    Set IFShop_Skill_Show_Upgrades = ItemFusionShop - Show Upgrade
    Set IFShop_Page_Skill_Next = ItemFusionShop - Page Next
    Set IFShop_Page_Skill_Previous = ItemFusionShop - Page Previous
    Set IFShop_Page_Skill_Select = ItemFusionShop - Select Hero
    Set IFShop_Page_Skill_Button[1] = ItemFusionShop - Button 1
    Set IFShop_Page_Skill_Button[2] = ItemFusionShop - Button 2
    Set IFShop_Page_Skill_Button[3] = ItemFusionShop - Button 3
    Set IFShop_Page_Skill_Button[4] = ItemFusionShop - Button 4
    Set IFShop_Page_Skill_Button[5] = ItemFusionShop - Button 5
    Set IFShop_Page_Skill_Button[6] = ItemFusionShop - Button 6
    Set IFShop_Page_Skill_Button[7] = ItemFusionShop - Button 7
    Set IFShop_Page_Skill_Button[8] = ItemFusionShop - Button 8
    Set IFShop_Page_Skill_Button[9] = ItemFusionShop - Button 9
    -------- Displayed when an Fusion is done. --------
    Set IFShop_Fusion_SFX_Path = Abilities\Spells\Items\AIem\AIemTarget.mdl
    -------- ---- --------
    -------- Bagpack settings --------
    -------- ---- --------
    -------- Search Material Slotbased? --------
    -------- True -> Access Order Shopper: 1/3/5/7/9/11; Bagpack 2/4/6/8/10/12 --------
    -------- False -> Access Order Shopper: 1/2/3/4/5/6; Bagpack 7/8/9/10/11/12 --------
    Set IFShop_Bagpack_Pick_SlotBased = False
    -------- Start Material Search with Shopper? --------
    Set IFShop_Bagpack_Shopper_First = True
    Set IFShop_Bagpack_Hero_Max_Distan = 600.00
    -------- ---- --------
    -------- Shop Zones --------
    -------- ---- --------
    -------- Setup here The Places where the System Shall work --------
    Set IFShop_Buy_Zones[0] = Gebiet_000 <gen>
    Set IFShop_Buy_Zones[1] = Gebiet_001 <gen>
    Set IFShop_Buy_Zones[2] = Gebiet_002 <gen>
    Set IFShop_Buy_Zones[3] = Gebiet_003 <gen>
    Set IFShop_Buy_Zones[4] = Gebiet_004 <gen>
    Set IFShop_Buy_Zones_Last = 4
    -------- You can Exclude Player Groups from using specific Buz_Zones --------
    Set IFShop_Buy_Zones_Excluded[1] = Player Group - Player 2 (Blue)
    Set IFShop_Buy_Zones_Excluded[3] = (All players matching (((Matching player) slot status) Equal to Is playing))
    Set IFShop_Buy_Zones_Excluded[4] = Player Group - Player 1 (Red)
    -------- - --------
    -------- This Creates the Shops and setups some basic Stuff --------
    Trigger - Run Item_Fusion_shop <gen> (ignoring conditions)
    Trigger - Run IFS_Init_Item <gen> (ignoring conditions)
    -------- After executing Trigger "Item Fusion Shop" the first time you can execute it to start shoping inside an Pickup or StartEffect event. --------
    -------- IFShop_Shop_Shopper_Bagpack[0] is treated as bagpack --------
    -------- -- --------
    -------- -- --------
    Skip remaining actions
    -------- Auto-Generate Needed Global Variables --------
    Set IFShop_Item_List_Fusions_Last = 0
    Set IFShop_Strings[0] =
    Set IFShop_Table = (Last created hashtable)
    Set IFShop_Shop[0] = IFShop_Shop_Shopper[0]
    Set IFShop_Shop_Shopper_Bagpack[0] = No unit
    Set IFShop_Page_Max[0] = IFShop_Page_Current[0]
    Set IFShop_Shop_Avaible_Fuse_Last[0] = IFShop_Shop_Avaible_Fuse_First[0]
    Set IFShop_Shop_Avaible_Fusions[0] = IFShop_Shopper_Count
    Set IFShop_Shop_Avaible_Fuse_plans[0] = IFShop_Mats[0]
    Set IFShop_Shop_Avaible_Fuse_Costs[0] = 0
    Set IFShop_Is_Shopping[0] = IFShop_Shop_Bagpack_Accessable[0]
    Set IFShop_Bagpack_Timer = IFShop_Bagpack_Timer
    Set IFShop_Item_Stack[0] = No item
    Set IFShop_Item_Stack_Last = 0
    Set IFShop_Shop_LastTry[0] = Secret Level Powerup
Use Upgrades Spell
  Events
    Unit - A unit Starts the effect of an ability
  Conditions
    (Ability being cast) Equal to IFShop_Skill_Show_Upgrades
  Actions
    -------- Used on yourself or an item owned (= in your inventory) --------
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Or - Any (Conditions) are true
          Conditions
            ((Target item of ability being cast) is owned) Equal to True
            (Triggering unit) Equal to (Target unit of ability being cast)
      Then - Actions
        -------- This Player uses Bagpacks? --------
        -------- Yes, get the one of that player --------
        -------- IFShop_Shop_Shopper_Bagpack[0] is treated as custom argument --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            (Triggering player) Equal to Player 1 (Red)
          Then - Actions
            Set IFShop_Shop_Shopper_Bagpack[0] = Bagpack 0032 <gen>
          Else - Actions
            Set IFShop_Shop_Shopper_Bagpack[0] = Bagpack 0039 <gen>
        -------- Inside Effect/PickUP Item/ Enter Region event, triggering unit is the shopper. --------
        -------- Inside an Enter Event all registered upgrades are buyable --------
        -------- Inside Effect upgrades of targeted item or upgrades of all items in the inventory --------
        -------- Inside Pickup shows upgrades of the picked up item. --------
        Trigger - Run Item_Fusion_shop <gen> (ignoring conditions)
      Else - Actions
Hero Gains Item
  Events
    Unit - A unit Acquires an item
  Conditions
    ((Item being manipulated) is A powerup) Equal to False
    ((Triggering unit) is selected by (Owner of (Triggering unit))) Equal to True
  Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Triggering player) Equal to Player 1 (Red)
      Then - Actions
        Set IFShop_Shop_Shopper_Bagpack[0] = Bagpack 0032 <gen>
      Else - Actions
        Set IFShop_Shop_Shopper_Bagpack[0] = Bagpack 0039 <gen>
    Trigger - Run Item_Fusion_shop <gen> (ignoring conditions)
ShowAll
  Events
    Player - Player 1 (Red) types a chat message containing showAll as An exact match
  Conditions
  Actions
    Game - Display to (All players) for 30 seconds the text: (Name of the current trigger)
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Triggering player) Equal to Player 1 (Red)
      Then - Actions
        Set IFShop_Shop_Shopper[0] = Mountain King 0007 <gen>
        Set IFShop_Shop_Shopper_Bagpack[0] = Bagpack 0032 <gen>
      Else - Actions
        Set IFShop_Shop_Shopper[0] = Blademaster 0000 <gen>
        Set IFShop_Shop_Shopper_Bagpack[0] = Bagpack 0039 <gen>
    Custom script: call IFShopShow(1, udg_IFShop_Shop_Shopper[0], udg_IFShop_Shop_Shopper_Bagpack[0], -1)
Map Only
  Events
    Map initialization
  Conditions
  Actions
    Game - Display to (All players) for 1000000000.00 seconds the text: This System shows upgrade Options of items inside the Unit Interface. -Works only on defined Rects (Here, Grass) -BuyZones can exclude Player Groups from using it. -Shows Upgrade Options if item gaind/ Show spell casted -Support a Bagpack (Unit) -The UI shows multiple Pages if needed.
    Floating Text - Create floating text that reads Red & Blue at (Center of Gebiet_000 <gen>) with Z offset 0, using font size 20.00, color (100%, 100%, 100%), and 0% transparency
    Floating Text - Create floating text that reads Nobody at (Center of Gebiet_003 <gen>) with Z offset 0, using font size 20.00, color (100%, 100%, 100%), and 0% transparency
    Floating Text - Create floating text that reads Red & Blue at (Center of Gebiet_002 <gen>) with Z offset 0, using font size 20.00, color (100%, 100%, 100%), and 0% transparency
    Floating Text - Create floating text that reads Red at (Center of Gebiet_001 <gen>) with Z offset 0, using font size 20.00, color (100%, 100%, 100%), and 0% transparency
    Floating Text - Create floating text that reads Blue at (Center of Gebiet_004 <gen>) with Z offset 0, using font size 20.00, color (100%, 100%, 100%), and 0% transparency