• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 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!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

[Trigger] A Unit Takes Damage.

Not open for further replies.
Level 4
Aug 20, 2004
Apparently, this is a long running question, yet I can't find my answer anywhere. Here goes:

I have a passive skill that activates on a 20% chance whenever the unit that has the skill attacks. If I use the 'unit is attacked' trigger, as I'm sure you know, it is possible for the play to spam and stop attacks, making the trigger fire off more frequently. I can make a trigger that fixes this (I use GUI only), but I would need the 'unit takes damage' event. . . which only can be used on pre-placed units.

Here, someone needs the same sort of trigger, and at the bottom a guy named CHUNK says it's an often discussed topic, and the OP should search the forums. I did and found nothing. I tried here and also didn't find what I needed. I need to get that 'unit takes damage' event to work with a generic unit, but can't figure out how.
Level 19
Aug 24, 2007
trigger 1
no event
and has your actions

trigger 2
Unit Enters map
Add Triggering Unit takes damage event to trigger 1

well it will leak like hell (whatever)
Level 6
Jun 30, 2006
So there is no possible way to use this in GUI?

Not effectively, no. Well, I guess nearly anything is possible with GUI, you just will have a lot of Custom Script lines...

I've created this same detection using structs, which are considerably faster than a gamecache. Tell me what you need and I can do it for you, mate.
Level 4
Aug 20, 2004
I needed a way to make a passive skill that activates on 20% of the units attacks. Since 'Unit is attacked' has abusive properties, I wanted to use 'Unit takes damage' to ensure that the attack was delivered and not just clicked/canceled.
Level 6
Jun 30, 2006
Well... I can give you the basic template, but I doubt you will understand it. Also, it requires vJASS, which is included in the JASS NewGen World Editor.
scope FluidCriticalStrike

    private constant integer AID_FLUID_CRITICAL_STRIKE='A001'
    private constant string EFFECT_FLUID_CRITICAL_STRIKE="Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl"

struct CritStrike
    trigger trig=CreateTrigger()
    triggercondition c
    triggeraction a
    unit attacker
    unit target
    texttag tag=CreateTextTag()
    private method textTag takes real dmg returns nothing
        call SetTextTagText(.tag,I2S(R2I(dmg))+"!",0.024)
        call SetTextTagPos(.tag,GetUnitX(.attacker),GetUnitY(.attacker),0)
        call SetTextTagColor(.tag,255,0,0,255)
        call SetTextTagVelocity(.tag,0,0.04)
        call SetTextTagFadepoint(.tag,1.2)
        call SetTextTagLifespan(.tag,4.5)
        call SetTextTagPermanent(.tag,false)
        call SetTextTagVisibility(.tag,true)
	private method onDestroy takes nothing returns nothing
        call ClearTriggerStructA(.trig)
        call TriggerRemoveCondition(.trig,.c)
        call TriggerRemoveAction(.trig,.a)
        call DestroyTrigger(.trig)
    public method Damage takes real dmg returns nothing
		call this.destroy()
        call UnitDamageTarget(.attacker,.target,dmg,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
        call this.textTag(dmg)
        if EFFECT_FLUID_CRITICAL_STRIKE != "" then
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_FLUID_CRITICAL_STRIKE,.target,"chest"))

private function DamageConditions takes nothing returns boolean
    local CritStrike data=GetTriggerStructA(GetTriggeringTrigger())
    return GetEventDamageSource()==data.attacker

private function DamageActions takes nothing returns nothing
    local CritStrike data=GetTriggerStructA(GetTriggeringTrigger())
    call data.Damage(GetEventDamage()*(1.4+GetUnitAbilityLevel(data.attacker,AID_FLUID_CRITICAL_STRIKE)*.4))

private function Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(),AID_FLUID_CRITICAL_STRIKE) > 0 and not IsUnitType(GetTriggerUnit(),UNIT_TYPE_STRUCTURE)

private function Actions takes nothing returns nothing 
    local unit u=GetTriggerUnit()
    local real hp=GetUnitState(u,UNIT_STATE_LIFE) / GetUnitState(u,UNIT_STATE_MAX_LIFE)
    local integer chance=GetUnitAbilityLevel(GetAttacker(),AID_FLUID_CRITICAL_STRIKE)
    local boolexpr be
    local CritStrike data=CritStrike.create()
    if hp<0.25 then
        set chance=30 + chance * 15
    elseif hp>0.50 then
        set chance=10 + chance * 5
        set chance=20 + chance * 10
    if chance>=GetRandomInt(1,100) then
        set data.attacker=GetAttacker()
        set data.target=u
        call SetTriggerStructA(data.trig,data)
        call TriggerRegisterUnitEvent(data.trig,u,EVENT_UNIT_DAMAGED)
        set be=Condition(function DamageConditions)
        set data.c=TriggerAddCondition(data.trig,be)
        call DestroyBoolExpr(be)
        set be=null
        set data.a=TriggerAddAction(data.trig,function DamageActions)
    set u=null

public function InitTrig takes nothing returns nothing
    local trigger trig=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(trig,Condition(function Conditions))
    call TriggerAddAction(trig,function Actions)

I'm glad I decided to help you with this, my version of JASS NewGen was quite outdated... :) I get pretty syntax highlighting and find/replace capability! And the most important... undo/redo capability!

Post if you can't figure out how to use this template, I'll help.
Last edited:
Not open for further replies.