• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Custom ARMOR

Level 4
Joined
Mar 7, 2024
Messages
59
Hello, please help me. Is there any way to convert all points (item - charges remaining) into the hero's armor? For example, when wearing an armor with 50 charges remaining, it will be 50 armor, but when you take it off, it will be deducted evenly from the number of charges remaining. Or is there any other way that the total item charges remaining in 6 boxes will all be counted as armor? When you lose 1 point of remaining charges, 1 armor will be deducted.
 
Level 25
Joined
Sep 26, 2009
Messages
2,397
There is no native way where item charges become armor.
You can modify armor via triggers, but that is IMO buggy and should be avoided.
A viable approach would be to use multiple "Item Armor Bonus" item abilities as these stack together.
  • You should determine an upper limit for the bonus armor provided by your item with charges (i.e. each item can have up to 50 charges, you can have 6 such items... so 50*6 = 300 max charges = 300 armor bonus).
  • Create a set of abilities based off "Item Armor Bonus" item ability. Each ability will have 10 levels
    • Each ability's level 1 will add 0 armor
    • for first ability, level 2+ will increase armor by 1s (so starting from level 1, it would increase as: 0, 1, 2, 3, 4, up to 9)
    • for second ability, level 2+ will increase armor by 10s (i.e. 0, 10, 20, ...)
    • for third ability, level 2+ will increase armor by 100s (i.e. 0, 100, 200, ...)
  • The sum of bonus armor from all three abilities at maximum level will be 9+90+900 => 999
  • When unit acquires the item with charges, check if it already carries other such items. If not, then add to the unit all 3 armor abilities
  • Similarly, when unit loses an item with charges, check if it carries other such items. If not, then remove all 3 armor abilities
  • At some point (when acquiring the item with charges, when losing a charge, etc.) you will need to recalculate bonus armor:
    • sum all charges
    • divide that number by 100, then run a (modulo 10)+1 on the result => you get level for the "third" ability that increments armor by hundreds
    • divide that number by 10, then run a (modulo 10)+1 on the result => you get the level for the "second" ability that increments in tens
    • finally, run a (modulo 10)+1 on the result => you get the level for the "first" ability that increments armor by units

Example calculation:
  • Sum of charges is 457, referred to as "total_charges"
  • "third" ability: mod(total_charges / 100, 10) + 1 = mod(457 / 100, 10) + 1 = mod(4, 10) + 1 = 4 + 1 = 5
  • "second" ability: mod(total_charges / 10, 10) + 1 = mod(457 / 10, 10) + 1 = mod(45, 10) + 1 = 5 + 1 = 6
  • "first" ability: mod(total_charges, 10) + 1 = mod(457, 10) + 1 = 7 + 1 = 8
  • note that each ability's level 1 increases armor by zero, so level 5 for "third" ability will actually increase armor by 400, not 500, etc.

Example triggers:
Item name is "Charged Armor". The three abilities will have an "Ability" suffix in the name.

  • CarriesAnotherSuchItem: boolean
  • ChargedArmorItem: item
  • ChargedArmorUnit: unit
  • IncludeManipulatedItem: boolean
  • TotalCharges: integer


  • Acquires Charged Armor
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Charged Armor
    • Actions
      • Set VariableSet ChargedArmorItem = (Item being manipulated)
      • Set VariableSet ChargedArmorUnit = (Triggering unit)
      • -------- ----------------------------- --------
      • -------- Check if unit carries another item of same item-type --------
      • Set VariableSet CarriesAnotherSuchItem = False
      • For each (Integer A) 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 ChargedArmorUnit in slot (Integer A))) Equal to Charged Armor
              • (Item carried by ChargedArmorUnit in slot (Integer A)) Not equal to ChargedArmorItem
            • Then - Actions
              • Set VariableSet CarriesAnotherSuchItem = True
            • Else - Actions
      • -------- ----------------------------- --------
      • -------- Add abilities if acquired item is first such item --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CarriesAnotherSuchItem Equal to False
        • Then - Actions
          • Unit - Add Charged Armor Ability (+1s) to ChargedArmorUnit
          • Unit - Add Charged Armor Ability (+10s) to ChargedArmorUnit
          • Unit - Add Charged Armor Ability (+100s) to ChargedArmorUnit
        • Else - Actions
      • -------- ----------------------------- --------
      • -------- Call trigger that recalculates level of armor abilities on the ChargedArmorUnit --------
      • Set VariableSet IncludeManipulatedItem = True
      • Trigger - Run Charged Armor Recalculate Bonus <gen> (checking conditions)


  • Loses Charged Armor
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Charged Armor
    • Actions
      • Set VariableSet ChargedArmorItem = (Item being manipulated)
      • Set VariableSet ChargedArmorUnit = (Triggering unit)
      • -------- ----------------------------- --------
      • -------- Check if unit carries another item of same item-type --------
      • Set VariableSet CarriesAnotherSuchItem = False
      • For each (Integer A) 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 ChargedArmorUnit in slot (Integer A))) Equal to Charged Armor
              • (Item carried by ChargedArmorUnit in slot (Integer A)) Not equal to ChargedArmorItem
            • Then - Actions
              • Set VariableSet CarriesAnotherSuchItem = True
            • Else - Actions
      • -------- ----------------------------- --------
      • -------- Remove abilities if lost item was last such item --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CarriesAnotherSuchItem Equal to False
        • Then - Actions
          • Unit - Remove Charged Armor Ability (+1s) from ChargedArmorUnit
          • Unit - Remove Charged Armor Ability (+10s) from ChargedArmorUnit
          • Unit - Remove Charged Armor Ability (+100s) from ChargedArmorUnit
        • Else - Actions
          • -------- ----------------------------- --------
          • -------- If lost item was not last, recalculate bonus --------
          • Set VariableSet IncludeManipulatedItem = False
          • Trigger - Run Charged Armor Recalculate Bonus <gen> (checking conditions)


  • Charged Armor Recalculate Bonus
    • Events
    • Conditions
    • Actions
      • Set VariableSet TotalCharges = 0
      • -------- ----------------------------- --------
      • -------- Get total charges --------
      • For each (Integer A) 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 ChargedArmorUnit in slot (Integer A))) Equal to Charged Armor
              • Or - Any (Conditions) are true
                • Conditions
                  • IncludeManipulatedItem Equal to True
                  • (Item carried by ChargedArmorUnit in slot (Integer A)) Not equal to ChargedArmorItem
            • Then - Actions
              • Set VariableSet TotalCharges = (TotalCharges + (Charges remaining in (Item carried by ChargedArmorUnit in slot (Integer A))))
            • Else - Actions
      • -------- ----------------------------- --------
      • -------- Calculate levels for all three abilities --------
      • Unit - Set level of Charged Armor Ability (+100s) for ChargedArmorUnit to (((TotalCharges / 100) mod 10) + 1)
      • Unit - Set level of Charged Armor Ability (+10s) for ChargedArmorUnit to (((TotalCharges / 10) mod 10) + 1)
      • Unit - Set level of Charged Armor Ability (+1s) for ChargedArmorUnit to ((TotalCharges mod 10) + 1)


  • Test Trigger
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set VariableSet ChargedArmorUnit = Paladin 0000 <gen>
      • Set VariableSet ChargedArmorItem = (Item carried by ChargedArmorUnit of type Charged Armor)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ChargedArmorItem Not equal to No item
        • Then - Actions
          • Item - Set charges remaining in ChargedArmorItem to ((Charges remaining in ChargedArmorItem) - 1)
          • Set VariableSet IncludeManipulatedItem = True
          • Trigger - Run Charged Armor Recalculate Bonus <gen> (checking conditions)
        • Else - Actions
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,628
Hello, please help me. Is there any way to convert all points (item - charges remaining) into the hero's armor? For example, when wearing an armor with 50 charges remaining, it will be 50 armor, but when you take it off, it will be deducted evenly from the number of charges remaining. Or is there any other way that the total item charges remaining in 6 boxes will all be counted as armor? When you lose 1 point of remaining charges, 1 armor will be deducted.
Alex, which patch are you on? The solutions all vary depending on what you can and cannot do, which depends on whether you've updated your game or not. You need at least v1.31 to get access to most of the useful stuff.

Anyway, this appears to be what you're trying to do:
  • Add Armor
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Charges remaining in (Item being manipulated)) Greater than 0
    • Actions
      • Unit - Set Armor of (Triggering unit) to ((Armor of (Triggering unit)) + (Real((Charges remaining in (Item being manipulated)))))
  • Lose Armor
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Charges remaining in (Item being manipulated)) Greater than 0
    • Actions
      • Unit - Set Armor of (Triggering unit) to ((Armor of (Triggering unit)) - (Real((Charges remaining in (Item being manipulated)))))
Item Charges is an Integer but Armor is a Real so to use them together in a Arithmetic function you'll have to use the Convert Integer To Real function to turn Charges into a Real.

Note that if the Item Charges change while you have the item equipped you will have to run another trigger to subtract the previous amount of Charges and Add the new amount of Charges.
 
Level 4
Joined
Mar 7, 2024
Messages
59
Alex, which patch are you on? The solutions all vary depending on what you can and cannot do, which depends on whether you've updated your game or not. You need at least v1.31 to get access to most of the useful stuff.

Anyway, this appears to be what you're trying to do:
  • Add Armor
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Charges remaining in (Item being manipulated)) Greater than 0
    • Actions
      • Unit - Set Armor of (Triggering unit) to ((Armor of (Triggering unit)) + (Real((Charges remaining in (Item being manipulated)))))
  • Lose Armor
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Charges remaining in (Item being manipulated)) Greater than 0
    • Actions
      • Unit - Set Armor of (Triggering unit) to ((Armor of (Triggering unit)) - (Real((Charges remaining in (Item being manipulated)))))
Item Charges is an Integer but Armor is a Real so to use them together in a Arithmetic function you'll have to use the Convert Integer To Real function to turn Charges into a Real.

Note that if the Item Charges change while you have the item equipped you will have to run another trigger to subtract the previous amount of Charges and Add the new amount of Charges.

Can you help me? When a hero receives an item above level 1 that is a level 2 or 3 or 4 item, the level 1 item will drop out.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,628
Can you help me? When a hero receives an item above level 1 that is a level 2 or 3 or 4 item, the level 1 item will drop out.
That's not enough of an explanation to know for certain but I believe you want this:
  • Drop Lower Level Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • -------- Only allow the highest level item to be equipped. --------
      • Set VariableSet Item_Hero = (Triggering unit)
      • Set VariableSet Item_Level = (Item level of (Item being manipulated))
      • -------- --------
      • -------- Find the highest level item: --------
      • Set VariableSet Item_Highest_Level = -1
      • For each (Integer Item_Slot) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet Item_In_Slot = (Item carried by Item_Hero in slot Item_Slot)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item level of Item_In_Slot) Greater than Item_Highest_Level
            • Then - Actions
              • Set VariableSet Item_Highest_Level = (Item level of Item_In_Slot)
              • Set VariableSet Item_To_Keep = Item_In_Slot
            • Else - Actions
      • -------- --------
      • -------- Drop all lower level items: --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Highest_Level Greater than -1
        • Then - Actions
          • For each (Integer Item_Slot) from 1 to 6, do (Actions)
            • Loop - Actions
              • Set VariableSet Item_In_Slot = (Item carried by Item_Hero in slot Item_Slot)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Item_In_Slot Not equal to Item_To_Keep
                • Then - Actions
                  • Hero - Drop Item_In_Slot from Item_Hero.
                • Else - Actions
        • Else - Actions
 

Attachments

  • Item Drop 1.w3m
    18.3 KB · Views: 2
Last edited:
Level 4
Joined
Mar 7, 2024
Messages
59
That's not enough of an explanation to know for certain but I believe you want this:
  • Drop Lower Level Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • -------- Only allow the highest level item to be equipped. --------
      • Set VariableSet Item_Hero = (Triggering unit)
      • Set VariableSet Item_Level = (Item level of (Item being manipulated))
      • -------- --------
      • -------- Find the highest level item: --------
      • Set VariableSet Item_Highest_Level = -1
      • For each (Integer Item_Slot) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet Item_In_Slot = (Item carried by Item_Hero in slot Item_Slot)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item level of Item_In_Slot) Greater than Item_Highest_Level
            • Then - Actions
              • Set VariableSet Item_Highest_Level = (Item level of Item_In_Slot)
              • Set VariableSet Item_To_Keep = Item_In_Slot
            • Else - Actions
      • -------- --------
      • -------- Drop all lower level items: --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Highest_Level Greater than -1
        • Then - Actions
          • For each (Integer Item_Slot) from 1 to 6, do (Actions)
            • Loop - Actions
              • Set VariableSet Item_In_Slot = (Item carried by Item_Hero in slot Item_Slot)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Item_In_Slot Not equal to Item_To_Keep
                • Then - Actions
                  • Hero - Drop Item_In_Slot from Item_Hero.
                • Else - Actions
        • Else - Actions
I'm sorry for making you misunderstand, in the hero's inventory there is a level 1 item, but when holding an item higher than level 1, the level 1 item will drop. I want level 1 items to be dropped when picking up items higher than level 1.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,628
I'm sorry for making you misunderstand, in the hero's inventory there is a level 1 item, but when holding an item higher than level 1, the level 1 item will drop. I want level 1 items to be dropped when picking up items higher than level 1.
Okay, you can use that previous trigger but change a few things:
  • Drop Lower Level Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set VariableSet Item_Hero = (Triggering unit)
      • -------- --------
      • -------- Find the highest level item: --------
      • Set VariableSet Item_Highest_Level = -1
      • For each (Integer Item_Slot) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet Item_In_Slot = (Item carried by Item_Hero in slot Item_Slot)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item level of Item_In_Slot) Greater than Item_Highest_Level
            • Then - Actions
              • Set VariableSet Item_Highest_Level = (Item level of Item_In_Slot)
            • Else - Actions
      • -------- --------
      • -------- Drop all Level 1 items: --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Highest_Level Greater than 1
        • Then - Actions
          • For each (Integer Item_Slot) from 1 to 6, do (Actions)
            • Loop - Actions
              • Set VariableSet Item_In_Slot = (Item carried by Item_Hero in slot Item_Slot)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item level of Item_In_Slot) Less than or equal to 1
                • Then - Actions
                  • Hero - Drop Item_In_Slot from Item_Hero.
                • Else - Actions
        • Else - Actions
Change this line here to modify it to drop items of different levels:
  • If - Conditions
    • (Item level of Item_In_Slot) Less than or equal to 1
 
Level 4
Joined
Mar 7, 2024
Messages
59
Okay, you can use that previous trigger but change a few things:
  • Drop Lower Level Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set VariableSet Item_Hero = (Triggering unit)
      • -------- --------
      • -------- Find the highest level item: --------
      • Set VariableSet Item_Highest_Level = -1
      • For each (Integer Item_Slot) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet Item_In_Slot = (Item carried by Item_Hero in slot Item_Slot)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item level of Item_In_Slot) Greater than Item_Highest_Level
            • Then - Actions
              • Set VariableSet Item_Highest_Level = (Item level of Item_In_Slot)
            • Else - Actions
      • -------- --------
      • -------- Drop all Level 1 items: --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Highest_Level Greater than 1
        • Then - Actions
          • For each (Integer Item_Slot) from 1 to 6, do (Actions)
            • Loop - Actions
              • Set VariableSet Item_In_Slot = (Item carried by Item_Hero in slot Item_Slot)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item level of Item_In_Slot) Less than or equal to 1
                • Then - Actions
                  • Hero - Drop Item_In_Slot from Item_Hero.
                • Else - Actions
        • Else - Actions
Change this line here to modify it to drop items of different levels:
  • If - Conditions
    • (Item level of Item_In_Slot) Less than or equal to 1
great, just what I wanted, thank you, can this be added: when there are 2 items of the same level in the hero's inventory, 1 will be dropped.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,628
Sure, but from here on out I want you to try to do it yourself and post your attempt when asking for help:
  • Drop Lower Level Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set VariableSet Item_Hero = (Triggering unit)
      • Set VariableSet Item_Acquired = (Item being manipulated)
      • Set VariableSet Item_Acquired_Level = (Item level of Item_Acquired)
      • -------- --------
      • -------- Drop all items with the same level and drop all Level 1 items if you have a higher level item: --------
      • For each (Integer Item_Slot_Number) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet Item_Slot = (Item carried by Item_Hero in slot Item_Slot_Number)
          • Set VariableSet Item_Slot_Level = (Item level of Item_Slot)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Slot Not equal to Item_Acquired
              • Or - Any (Conditions) are true
                • Conditions
                  • Item_Slot_Level Equal to Item_Acquired_Level
                  • Item_Slot_Level Less than or equal to 1
            • Then - Actions
              • Hero - Drop Item_Slot from Item_Hero.
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Acquired_Level Equal to 1
              • Item_Slot_Level Greater than 1
            • Then - Actions
              • Hero - Drop Item_Acquired from Item_Hero.
            • Else - Actions
Try to understand what this trigger is doing and learn from that.

Also, this may have bugs, something about the logic doesn't sit well with me, but the demo map seems to work fine.
 

Attachments

  • Item Drop 2.w3m
    18.5 KB · Views: 1
Level 4
Joined
Mar 7, 2024
Messages
59
Sure, but from here on out I want you to try to do it yourself and post your attempt when asking for help:
  • Drop Lower Level Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set VariableSet Item_Hero = (Triggering unit)
      • Set VariableSet Item_Acquired = (Item being manipulated)
      • Set VariableSet Item_Acquired_Level = (Item level of Item_Acquired)
      • -------- --------
      • -------- Drop all items with the same level and drop all Level 1 items if you have a higher level item: --------
      • For each (Integer Item_Slot_Number) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet Item_Slot = (Item carried by Item_Hero in slot Item_Slot_Number)
          • Set VariableSet Item_Slot_Level = (Item level of Item_Slot)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Slot Not equal to Item_Acquired
              • Or - Any (Conditions) are true
                • Conditions
                  • Item_Slot_Level Equal to Item_Acquired_Level
                  • Item_Slot_Level Less than or equal to 1
            • Then - Actions
              • Hero - Drop Item_Slot from Item_Hero.
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Acquired_Level Equal to 1
              • Item_Slot_Level Greater than 1
            • Then - Actions
              • Hero - Drop Item_Acquired from Item_Hero.
            • Else - Actions
Try to understand what this trigger is doing and learn from that.

Also, this may have bugs, something about the logic doesn't sit well with me, but the demo map seems to work fine.
Thank you 🥰 I promise to try harder even though my poor understanding of English makes the job more difficult.
 
Top