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

[Trigger] A Unit Takes Damage.

Status
Not open for further replies.
Level 4
Joined
Aug 20, 2004
Messages
65
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
Joined
Aug 24, 2007
Messages
2,888
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
Joined
Jun 30, 2006
Messages
230
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
Joined
Aug 20, 2004
Messages
65
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
Joined
Jun 30, 2006
Messages
230
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.
JASS:
scope FluidCriticalStrike

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

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)
    endmethod
	private method onDestroy takes nothing returns nothing
        call ClearTriggerStructA(.trig)
        call TriggerRemoveCondition(.trig,.c)
        call TriggerRemoveAction(.trig,.a)
        call DestroyTrigger(.trig)
	endmethod
    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"))
        endif
    endmethod
    
endstruct

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

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))
endfunction

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

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
    else
        set chance=20 + chance * 10
    endif
    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)
    endif
    set u=null
endfunction

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)
    call Preload(EFFECT_FLUID_CRITICAL_STRIKE)
endfunction

endscope
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:
Status
Not open for further replies.
Top