-
Map Initialization
-

Events
-

Conditions
-

Actions
-


Hashtable - Create a hashtable
-


Set VariableSet ResistanceHashtable = (Last created hashtable)
-


-------- ------------------------------------------------------ --------
-


Set VariableSet UnitType = Water Elemental (Level 1)
-


Custom script: set udg_RawCode = udg_UnitType
-


Hashtable - Save 150.00 as (Key WaterResistance.) of RawCode in ResistanceHashtable.
-


-------- ------------------------------------------------------ --------
-


Set VariableSet UnitType = Lava Spawn (Level 1)
-


Custom script: set udg_RawCode = udg_UnitType
-


Hashtable - Save -50.00 as (Key WaterResistance.) of RawCode in ResistanceHashtable.
-


-------- ------------------------------------------------------ --------
-


Set VariableSet ItemType = Ring of Protection +1
-


Custom script: set udg_RawCode = udg_ItemType
-


Hashtable - Save 25.00 as (Key WaterResistance.) of RawCode in ResistanceHashtable.
This initializes the 'Resistance' hashtable with data. Doing this in GUI bloats the trigger with many actions, I would advice creating a custom jass function and just calling that directly.
Anyway, in that trigger you can see that I initialize 'WaterResistance' for Water Elemental to 150.00, which stands for 150%, so the assumption here is that water damage would heal Water Elemental for half of the damage done instead of damaging it. On the other hand Lava Spawn would have -50% resistance, meaning it would take bonus 50% damage.
There's also a Ring of Protection stored, which give +25% water resistance.
-
Resistance Unit creation
-

Events
-


Unit - A unit enters (Playable map area)
-

Conditions
-

Actions
-


-------- assuming here that the unit has already been detected by unit indexer and has a unique number assigned to its custom value --------
-


-------- --------------------------------------------- --------
-


Set VariableSet CV = (Custom value of (Triggering unit))
-


Set VariableSet UnitType = (Unit-type of (Triggering unit))
-


Custom script: set udg_RawCode = udg_UnitType
-


-------- --------------------------------------------- --------
-


Set VariableSet WaterResistances[CV] = (Load (Key WaterResistance.) of RawCode from ResistanceHashtable.)
-


-------- ... the above would repeat for each elemental resistance --------
This trigger detects when a unit was created/appears in map. It loads all resistances tied to its type from the hashtable and stores that in an array. The array represents resistances of specific units.
For example, if this was Water Elemental (Level 1), it would load the '150%' water resistance.
-
Resistance Item acquisition
-

Events
-


Unit - A unit Acquires an item
-

Conditions
-

Actions
-


Set VariableSet CV = (Custom value of (Triggering unit))
-


Set VariableSet ItemType = (Item-type of (Item being manipulated))
-


Custom script: set udg_RawCode = udg_ItemType
-


-------- --------------------------------------------- --------
-


Set VariableSet Resistance = (Load (Key WaterResistance.) of RawCode from ResistanceHashtable.)
-


Set VariableSet WaterResistances[CV] = (WaterResistances[CV] + Resistance)
-


-------- ... the above would repeat for each elemental resistance --------
-
Resistance Item loss
-

Events
-


Unit - A unit Loses an item
-

Conditions
-

Actions
-


Set VariableSet CV = (Custom value of (Triggering unit))
-


Set VariableSet ItemType = (Item-type of (Item being manipulated))
-


Custom script: set udg_RawCode = udg_ItemType
-


-------- --------------------------------------------- --------
-


Set VariableSet Resistance = (Load (Key WaterResistance.) of RawCode from ResistanceHashtable.)
-


Set VariableSet WaterResistances[CV] = (WaterResistances[CV] - Resistance)
-


-------- ... the above would repeat for each elemental resistance --------
These two triggers showcase how item resistances could work. When unit acquires/loses an item, we load that item's resistances from hashtable and add/subtract it from total resistances of the unit manipulating that item.
A Water Elemental (Level 1) acquiring Ring of Protection +1 would gain +25% water resistance. It would add that to its base resistance of 150% for a total of 175%.
-
Damage Resistance Bonus
-

Events
-


Unit - A unit About to take damage
-

Conditions
-

Actions
-


-------- assuming we know that the damage done is 'water' damage --------
-


Set VariableSet CV = (Custom value of (Damage Target))
-


Set VariableSet Resistance = WaterResistances[CV]
-


If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-



If - Conditions
-




Resistance Greater than or equal to 100.00
-



Then - Actions
-




Set VariableSet HealAmount = ((Resistance - 100.00) x (0.01 x (Damage taken)))
-




Unit - Set life of (Damage Target) to ((Life of (Damage Target)) + HealAmount)
-




Event Response - Set Damage of Unit Damaged Event to 0.00
-



Else - Actions
-




Event Response - Set Damage of Unit Damaged Event to (((100.00 - Resistance) x 0.01) x (Damage taken))
Finally, this trigger detects damage about to be done, loads target's water resistance and check if that resistance is above 100% (in which case, the damage is completely absorbed and may heal the target instead). If resistance is below 100%, the damage done is modified.
For example, Water Elemental (Level 1) with Ring of Power +1 will have 175% water resistance. As it is above 100%, it would take the remaining 75% and for that amount heal the elemental, e.g. a 200 'water' damage would heal the unit for 150.