• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Extension] Damage Source Type

Level 31
Joined
Jul 10, 2007
Messages
6,306
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: 385
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