Combine same items and continue to next level

Status
Not open for further replies.

wwwwvw

W

wwwwvw

Hi,

I'm making a map, but have a problem with combined same items.

I made items name "Ring+1" , "Ring+2",..."Ring+10" and set array on every item like:

Citem[1]=Ring+1

Citem[2]=Ring+2

....

Citem[10]=Ring+10

And an ability name "Combine Item"

What I need is when I press "Combine Item" while having 3 same Rings, It will fuse into a new item with higher level ( 3 items Ring+1 --> Ring+2... ), and continue until get to level 10.



Can someone help me how to do this, sorry for my bad English.

Thanks
 
There is a simple way to do this. This option isn't the most optimized, but it is pretty simple and will get the job done.

In this example, I want to be able to merge Rings of Protection. Every 3 same rings can be merged into their more powerful version.

  • Map Ini
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet RingsArray[1] = Ring of Protection +1
      • Set VariableSet RingsArray[2] = Ring of Protection +2
      • Set VariableSet RingsArray[3] = Ring of Protection +3
      • Set VariableSet RingsArray[4] = Ring of Protection +4
      • Set VariableSet RingsArray[5] = Ring of Protection +5
      • Set VariableSet NumberOfRingVariants = 5
      • Set VariableSet MergeEveryNItems = 3
In the map initialization, I just set various ring types into an item-type array. Of note is that more powerful rings have higher array index - so Ring Of Protection +4 is more powerful than Ring Of Protection +3, hence the +4 variant has higher index (4) than the weaker variant (index 3).


  • Merge Rings
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Animate Dead
    • Actions
      • Set VariableSet ItemsMergingUnit = (Triggering unit)
      • For each (Integer RingIndex) from 1 to (NumberOfRingVariants - 1), do (Actions)
        • Loop - Actions
          • Set VariableSet RingsOwned = 0
          • For each (Integer InventorySlot) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Item carried by ItemsMergingUnit in slot InventorySlot)) Equal to RingsArray[RingIndex]
                • Then - Actions
                  • Set VariableSet RingsOwned = (RingsOwned + 1)
                  • Set VariableSet RingInventorySlots[RingsOwned] = InventorySlot
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • RingsOwned Equal to MergeEveryNItems
                    • Then - Actions
                      • For each (Integer SlotToRemove) from 1 to MergeEveryNItems, do (Actions)
                        • Loop - Actions
                          • Item - Remove (Item carried by ItemsMergingUnit in slot RingInventorySlots[SlotToRemove])
                      • Set VariableSet RingsOwned = 0
                      • Hero - Create RingsArray[(RingIndex + 1)] and give it to ItemsMergingUnit
                    • Else - Actions
                • Else - Actions
This trigger utilizes loops.
The basic logic is as following: For each possible item to merge, check each inventory slot to see if it contains the ring. If yes, increment counter (RingsOwned) by 1 and remember the inventory slot index of that item (RingInventorySlots array).
If counter was incremented, check if counter's value is 3 (MergeEveryNItems ... since we want to merge 3 same rings). If value is 3, then remove items from slots that contain the rings and create a more powerful version of the ring and give it to the unit.

This will allow you to merge 6 rings of the +1 variant into 2 rings of the +2 variant. Also, the trigger is set up to cascade the merging.
What I mean is for example this situation: Unit has +1 ring variant 3 times and +2 ring 2 times. If the unit casts merge, the +1 rings will merge into a single +2 ring. That will leave the unit with a total of 3 rings of the +2 variant, so the trigger will auto-merge them into single +3 variant.

Some other things to note:
  • The first loop ("For each (Integer RingIndex) from 1 to (NumberOfRingVariants - 1), do...") iterates over indices from 1 to 4 (since in Map Ini trigger the NumberOfRingVariants is set to be 5). The reason for that is because the +5 variants are the final variants and cannot be merged further.
  • Ordering in the RingsArray is important, because which new ring will be created is calculated as "(RingIndex + 1)". So when the trigger is merging +1 variants, the RingIndex value will be 1. The newly created item will be item RingsArray[(RingIndex + 1)] => RingsArray[(1 + 1)] => RingsArray[2] => Ring of Protection +2.
 
Status
Not open for further replies.
Back
Top