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

[Solved] Damage Event

Status
Not open for further replies.
Easiest one for me to use is:
http://www.hiveworkshop.com/forums/jass-resources-412/snippet-damageevent-186829/

But it depends, are you familiar with vJass? If not, I recommend you use Bribe's Damage Engine instead, and read the documentation on how to implement it. You can also use Weep's, but his doesn't have the feature of damage modification yet. (I'm pretty sure he has a version that does, but I don't think he released it yet)

If you are familiar with vJass, then simply import UnitIndexer (don't forget to import the ability, you can use the non-lua version for simpler importing) as well as the Event trigger. Then import DamageEvent.

To use it, you basically use this function to register any damage:
JASS:
call DamageEvent.ANY.register( Filter( function MyFunctionName ) )
Whenever damage occurs, it will fire the function within the parentheses. You can replace "MyFunctionName" with whatever function you want to fire.

For example:
JASS:
function DamageEventFunction takes nothing returns boolean
// i don't remember if it is necessary to return boolean, i forgot
// i'm just doing it just in case
    
    return false
endfunction

function InitTrig_DamageEventTrigger takes nothing returns nothing
    call DamageEvent.ANY.register( Filter( function DamageEventFunction ) )
endfunction

Then you can access the members of the struct as the trigger data:
  • Source - Unit who deals the damage. Use: DamageEvent.source
  • Target - Unit who takes the damage. Use: DamageEvent.target
  • Amount - Amount of damage dealt. Use: DamageEvent.amount

There are two others, but those are just the user id's of the source/target.

For example, this would display the amount of damage dealt, and then it would kill both units.
JASS:
scope DamageKill initializer Init
    private function onDamage takes nothing returns boolean
        call BJDebugMsg( R2S( DamageEvent.amount ) )
        call KillUnit( DamageEvent.source )
        call KillUnit( DamageEvent.target )
        return false
    endfunction

    private function Init takes nothing returns nothing
        call DamageEvent.ANY.register( Filter( function onDamage ) )
    endfunction
endscope
 
Status
Not open for further replies.
Top