• 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.

[Extension] Damage Source Type

All credits go to looking_for_help (gj man) for the idea of using spell damage reduction to determine whether damage was from a spell or not (http://www.hiveworkshop.com/forums/submissions-414/system-detection-physical-damage-228456/)

You may not use the Spell Damage Reduction ability when using this extension. Instead of using it, code spell resistance via a DDS.

Must invert Damage Return Factor for Locust Swarm based abilities.
Must invert healing portion of Life Drain based abilities.

Map contains the ability.

JASS:
library DamageSourceType /* v1.0.0.1
*************************************************************************************
*
*   Able to retrieve
*
*       Spell damage
*       Physical Damage
*       Code Damage (from allocateAttack in DamageEvent)
*
*************************************************************************************
*
*   Credits
*
*       looking_for_help
*       -----------------------
*
*           For idea of using spell damage reduction ability
*
*************************************************************************************
*
*   */uses/*
*
*       */ DamageEvent      /*          hiveworkshop.com/forums/jass-resources-412/snippet-damageevent-186829/
*       */ AdvDamageEvent   /*          hiveworkshop.com/forums/jass-resources-412/extension-advanced-damage-event-213572/
*
************************************************************************************
*
*   SETTINGS
*/
globals
    constant integer ABILITIES_DAMAGE_SOURCE_TYPE_SPELL_REDUCTION = 'A002'
endglobals
/*
*************************************************************************************
*
*   struct DamageSourceType extends array
*
*       static constant integer PHYSICAL
*       static constant integer SPELL
*       static constant integer CODE
*
*   DamageEvent (extends)
*
*       readonly static DamageSourceType damageSourceType
*
*************************************************************************************/
    struct DamageSourceType extends array
        static constant integer PHYSICAL = 0
        static constant integer SPELL = 1
        static constant integer CODE = 2
    endstruct
    
    private module Init
        private static method onInit takes nothing returns nothing
            call init()
        endmethod
    endmodule
    
    private struct AddAbility extends array
        private static method onIndex takes nothing returns boolean
            call UnitAddAbility(GetIndexedUnit(), ABILITIES_DAMAGE_SOURCE_TYPE_SPELL_REDUCTION)
            call UnitMakeAbilityPermanent(GetIndexedUnit(), true, ABILITIES_DAMAGE_SOURCE_TYPE_SPELL_REDUCTION)
            
            return false
        endmethod
    
        private static method init takes nothing returns nothing
            local integer playerId
            
            set playerId = 15
            loop
                call SetPlayerAbilityAvailable(Player(playerId), ABILITIES_DAMAGE_SOURCE_TYPE_SPELL_REDUCTION, false)
                
                exitwhen 0 == playerId
                set playerId = playerId - 1
            endloop
        
            call RegisterUnitIndexEvent(Condition(function thistype.onIndex), UnitIndexer.INDEX)
        endmethod
    
        implement Init
    endstruct
    
    //! textmacro DAMAGE_TYPE_EXT_FIELDS
        readonly static DamageSourceType damageSourceType = 0
    //! endtextmacro
    
    //! textmacro DAMAGE_TYPE_EXT_LOCALS
        local integer prevDamageSourceType = damageSourceType
    //! endtextmacro
    
    //! textmacro DAMAGE_TYPE_EXT
        if (amount < 0) then
            if (0 == damageType_p[runAttackCount_p]) then
                set damageSourceType = DamageSourceType.SPELL
            else
                set damageSourceType = DamageSourceType.CODE
            endif
            
            set amount = -amount
        elseif (0 == damageType_p[runAttackCount_p]) then
            set damageSourceType = DamageSourceType.PHYSICAL
        else
            set damageSourceType = DamageSourceType.CODE
        endif
    //! endtextmacro
    
    //! textmacro DAMAGE_TYPE_EXT_RESET
        set damageSourceType = prevDamageSourceType
    //! endtextmacro
endlibrary

Demonstration
JASS:
struct Test extends array
    private static method onDamage takes nothing returns nothing
        if (damageSourceType == DamageSourceType.SPELL) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"Spell")
        elseif (damageSourceType == DamageSourceType.PHYSICAL) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"Physical")
        else
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"Code")
        endif
        
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,R2S(amount))
        
        if (damageSourceType == DamageSourceType.SPELL) then
            call allocateAttack(1, 0, 0)
            call UnitDamageTarget(source, target, 50, true, false, null, DAMAGE_TYPE_UNIVERSAL, null)
        endif
    endmethod
    
    implement DamageEvent
endstruct
 

Attachments

  • DamageType.w3x
    58 KB · Views: 389
Last edited:
Level 14
Joined
Dec 12, 2012
Messages
1,007
Hi,

I did some testing yesterday and today and something seems to be wrong with the system. I did some tests with a few level 10 DHs and their immolation seemed to get disabled and enabled randomly during a stress test, although I did not activate or deactivate it.

Don't know if this affects other abilitys as well, I will continue testing.

Greetings,
lfh

EDIT:
Lol, forgot to delete an old trigger in the testmap, which caused that behaviour, sorry for that^^
So until now, everything is looking fine.
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
ooh, smart idea! :p no need to use orb effects anymore...

spell damage resist can be triggered anyway
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
lol, it's a pretty old system that's been used quite extensively. No need for you to test it : p.

I meant the new system itself, not your DDS ;)

Btw, I found an ugly bug with carrion swarm. The carrions damage the Crypt Lord, instead of healing him which is quite bad :D

Thankfully it is very easy to fix. Just change the damage-factor of the carrion swarm ability from 0.75 to -0.75.

It seems that the ability multiplies the dealt damage by the locusts and then heals the CL by thatamount. As their damage is negativ,
the multiplicator has to be negative too, so that the final healing is positiv (else you have a negative healing effect, which results in damage).
Crazy Wc3 :D

Greetings,
lfh
 
Last edited:
Top