• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Creation of elemental resistance

Level 5
Joined
Oct 9, 2024
Messages
69
To make magical encounters more tactical and diverse, I would like to be able to create specific categories of magical damage, such as fire, ice, poison, and so on. Instead of all magic in the game just dealing standard, pure magical damage, this categorization will allow for the creation of magical items and equipment that offer specific resistances to certain types of damage. For example, an enchanted shield might grant 50% resistance to fire magical damage, while halving the damage dealt by spells in that category. This system will bring more strategic depth to the game, allowing characters to better prepare for different types of enemies and situations, and will also place a premium on equipment selection and prior knowledge of the type of threat they will face.
 
Level 5
Joined
Jan 19, 2023
Messages
38
In theory certain spells do different type of damage already, and maybe damage engine can detect it but I'm not near WE to check.
But in either case I think you would just have to trigger all spell damage in the whole map to make this work and add conditions to check if damage shoud be altered.
 
Level 29
Joined
Sep 26, 2009
Messages
2,598
What @Chonky Dwarf wrote is correct. Each damage has attack type (normal, piercing, spells, hero,...) and damage type (normal, fire, sonic, ...).
When you deal damage via trigger, you can specify attack and damage type, like so:
  • Unit - Cause unit_a to damage unit_b, dealing 500.00 damage of attack type Spells and damage type Fire
As for object editor spells, those have hard-coded attack and damage type, so you cannot change it easily.
However it is possible to use the "Unit is about to take damage" event and in it you can change the attack and damage type.
For example this will change damage type to "Fire" for any spell damage done by Firelord:
  • Firelord Spell Damage
    • Events
      • Unit - A unit About to take damage
    • Conditions
      • (Unit-type of (Damage source)) Equal to Firelord
      • (Damage From Normal Attack) Equal to False
    • Actions
      • Event Response - Set Damage Type of Unit Damaged Event to Fire
You can also change attack/damage type for selected spells as long as you can identify them via damage amount and/or its original attack/damage type.
For example let's say I have a custom Shockwave spell that I want to deal "Lightning" damage type.
If only Mountain Kings have this custom spell and I know that this spell originally deals attack type "Spells" and damage type "Sonic" - and it is the only spell on Mountain King that does that, then I can just swap the damage type via trigger, like so:
  • Modified Shockwave
    • Events
      • Unit - A unit About to take damage
    • Conditions
      • (Unit-type of (Damage source)) Equal to Mountain King
      • (Damage From Normal Attack) Equal to False
    • Actions
      • Set VariableSet dmgType = (Damage Type)
      • Custom script: set udg_isSonicDamageType = udg_dmgType == DAMAGE_TYPE_SONIC
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • isSonicDamageType Equal to True
        • Then - Actions
          • Event Response - Set Damage Type of Unit Damaged Event to Lightning
        • Else - Actions
GUI triggers do not have conditions to compare damage type, so the comparison must be done via custom script.

However the above has one issue - the attack/damage pair of the spell must be unique for given unit.
For example Mountain King has Thunder Clap spell which also deals attack type Spells, damage type Sonic. So the above trigger would change Thunder Clap's damage type to Lightning as well, which may not be desired.
In such situations, comparing the amount of damage may help resolve which spell it is: Thunder clap deals for example 60.00 damage, while shockwave deals 75.00 damage, so I just compare if damage is > 74.50 and < 75.50 and if so, I can reasonable assume it is the Shockwave spell, so I can change the damage type.
 
Level 5
Joined
Oct 9, 2024
Messages
69
I understand your entire theory, although for now I'm not yet able to fully implement it. My goal is to create something for my mage hero in the game. Since he will use various spells with different elements — such as ice, fire, and lightning — I need a trigger or event system that defines the element of each spell. This is important so that, for example, when he casts a fireball at a dragon, the dragon takes reduced damage because it's resistant to fire, but still takes full damage from lightning. I also want to be able to create items that grant elemental resistance.
 
Level 30
Joined
Aug 29, 2012
Messages
1,389
My approach is to trigger all the spells and have them cast by different dummy units, e.g. you have a dummy fire element unit that launches the fireball, and via trigger you can easily detect if the source of the damage = your fire caster, then it means it's fire elemental and then you modify the damage accordingly

For resistances, you can create abilities based on claws of attack that do essentially nothing, e.g. fire resistance 50%, and then via trigger you detect if the unit has this ability, then reduce the damage from your fire dummy by 50%

The only drawback is that all your spell damage needs to be done via trigger
 
Level 5
Joined
Oct 9, 2024
Messages
69
I thought about creating a variant for each type of magic and putting triggers for when events happen like throwing a fireball at the fire elemental.
 
Level 5
Joined
Oct 9, 2024
Messages
69
I came up with a simple idea: if a spell X belongs to a list categorized as "Fire Spells" and it targets a creature Y that is included in a list of "Fire-Resistant Creatures," then the damage dealt should be reduced by 50%.
 
Level 29
Joined
Sep 26, 2009
Messages
2,598
There is no built-in way to reduce damage based on the type of damage being dealt. But you can still do it yourself via triggers. As I've shown in my previous post, you can get the damage type while the damage is about to be applied to a unit.
Using that + something that will tell you if the unit is resistant to given damage type (i.e. a passive skill) will allow you to modify the amount of damage before it is applied.
For example:
  • I've created 3 passive abilities: Fire Resistant, Frost Resistant, Thunder Resistant.
  • I can give any of those abilities to any unit via object editor or triggers
  • I have trigger that reacts to "Unit is about to take damage" event. It checks damage type and whether unit has relevant "xx Resistant" spell or not. If both are true, the trigger reduces damage amount by half.

  • Resist Damage
    • Events
      • Unit - A unit About to take damage
    • Conditions
      • (Damage From Normal Attack) Equal to False
    • Actions
      • Custom script: set udg_DamageType = ConvertDamageTypeToInteger( BlzGetEventDamageType() )
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • And - All (Conditions) are true
                • Conditions
                  • DamageType Equal to DAMAGE_TYPE_FIRE
                  • (Level of Fire Resistant for (Damage Target)) Greater than 0
              • And - All (Conditions) are true
                • Conditions
                  • DamageType Equal to DAMAGE_TYPE_COLD
                  • (Level of Frost Resistant for (Damage Target)) Greater than 0
              • And - All (Conditions) are true
                • Conditions
                  • DamageType Equal to DAMAGE_TYPE_LIGHTNING
                  • (Level of Thunder Resistant for (Damage Target)) Greater than 0
        • Then - Actions
          • Event Response - Set Damage of Unit Damaged Event to ((Damage taken) x 0.50)
        • Else - Actions
The "ConvertDamageTypeToInteger" function is a helper function I wrote and placed in map header. It converts damageType back into integer so that I can do an integer comparison in GUI since I cannot do damageType comparison there.
The DAMAGE_TYPE_... gui variables are integer variables that have same value that the helper function returns.
Here is the helper function:

JASS:
function ConvertDamageTypeToInteger takes damagetype dt returns integer
    if dt == DAMAGE_TYPE_UNKNOWN then
        return 0
    elseif dt == DAMAGE_TYPE_NORMAL then
        return 4
    elseif dt == DAMAGE_TYPE_ENHANCED then
        return 5
    elseif dt == DAMAGE_TYPE_FIRE then
        return 8
    elseif dt == DAMAGE_TYPE_COLD then
        return 9
    elseif dt == DAMAGE_TYPE_LIGHTNING then
        return 10
    elseif dt == DAMAGE_TYPE_POISON then
        return 11
    elseif dt == DAMAGE_TYPE_DISEASE then
        return 12
    elseif dt == DAMAGE_TYPE_DIVINE then
        return 13
    elseif dt == DAMAGE_TYPE_MAGIC then
        return 14
    elseif dt == DAMAGE_TYPE_SONIC then
        return 15
    elseif dt == DAMAGE_TYPE_ACID then
        return 16
    elseif dt == DAMAGE_TYPE_FORCE then
        return 17
    elseif dt == DAMAGE_TYPE_DEATH then
        return 18
    elseif dt == DAMAGE_TYPE_MIND then
        return 19
    elseif dt == DAMAGE_TYPE_PLANT then
        return 20
    elseif dt == DAMAGE_TYPE_DEFENSIVE then
        return 21
    elseif dt == DAMAGE_TYPE_DEMOLITION then
        return 22
    elseif dt == DAMAGE_TYPE_SLOW_POISON then
        return 23
    elseif dt == DAMAGE_TYPE_SPIRIT_LINK then
        return 24
    elseif dt == DAMAGE_TYPE_SHADOW_STRIKE then
        return 25
    elseif dt == DAMAGE_TYPE_UNIVERSAL then
        return 26
    else
        return -1
    endif
endfunction
Conditions in the "Resist Damage" gui trigger could be better handled, like via Hashtable or array. But I just wrote it this way to give an example.

Edit:
actually, scratch the helper script, I just found out that the handleId of damage type is equivalent to the integer value it was created with, i.e. this will print 17 for Force, 8 for Fire, etc.
  • Set VariableSet DamageType = Force
  • Custom script: set udg_HandleId = GetHandleId(udg_DamageType)
  • Game - Display to (All players) the text: (String(HandleId))
 
Last edited:
Top