Warcraft III resources & community, 2003–2006 · archived

Damage Inflicted

10 posts
#1

Damage Inflicted

How would one get the damage inflicted to a unit when it is attacked?

'Event - Unit1 is attacked' will run each time the unit is hit right?

:shock:
#2
event - unit is attacked starts when a unit begins its attack animation, not when a unit gets damage

for the 'any unit gets damage event' u will need to dl WEU on this site
#3
...
#4
what is the part u dont understand? :P go to tools, world editors, WEUnlimited. dl it, open WEU Enchancer and find ur mapo with it, then allow advanced triggers (check the box) save it and open it with WEUnlimited. now find for the advanced function (below) that removes basic commands
#5
how do you do it without WEU...
#6
You'd probably need to use code, and it's much easier to just stick to GUI Triggers with WEU as Ramza suggested.
#7
i'm worried about future compatibility... besides, i need some triggers that are in the normal editor that aren't in WEU...
#8
why? WEU just has more events and conditions and stuff then WE has. the WEU actions r nice to but they can be done with GUI easy, but u will need WEU for that event, or jass
#9
Credits to Shadow1500 for the script

(put this in a trigger called AnyDmg)

function AnyUnitTakesDamage takes nothing returns nothing
    // your actions here
    // Sample Damage display:
    // call BJDebugMsg( "Damage: " + R2S(GetEventDamage()) )
endfunction

// part 1
function AddDamageTriggers takes nothing returns nothing
    local trigger takedamage = CreateTrigger()
    call TriggerRegisterUnitEvent(takedamage,GetTriggerUnit(),EVENT_UNIT_DAMAGED)
    call AttachObject(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
    call AttachObject(GetTriggerUnit(),"TakeDamageTrigger",takedamage)
endfunction

// part 2
function RemoveDamageTriggers takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local trigger me = GetAttachedTrigger(GetTriggerUnit(),"TakeDamageTrigger")
    local string t = GetAttachmentTable(me)
    local boolean revived = false

	if not IsUnitType(u,UNIT_TYPE_HERO) then
    	loop
        	set revived = (GetWidgetLife(u)>0.405)
        	exitwhen revived or GetUnitTypeId(u)==0
        	call TriggerSleepAction(0)
 		endloop
	endif

    if not revived then
        // delete action and trigger
        call TriggerRemoveAction(me,GetTableTriggerAction(t,"action"))
        call DestroyTable(t)
        call DestroyTrigger(me)
    endif
    set me = null
    set u = null
endfunction

// part 3
function InitTrig_AddDmg takes nothing returns nothing
    local trigger entermap = CreateTrigger()
    local group startingunits = CreateGroup()
    local unit u
    local trigger takedamage
    local trigger upondeath = CreateTrigger()
    call GroupEnumUnitsInRect(startingunits,bj_mapInitialPlayableArea,null)
    loop
        set u = FirstOfGroup(startingunits)
        exitwhen u == null
        set takedamage = CreateTrigger()
        call TriggerRegisterUnitEvent(takedamage,u,EVENT_UNIT_DAMAGED)
        call AttachObject(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
        call AttachObject(u,"TakeDamageTrigger",takedamage)
        call GroupRemoveUnit(startingunits,u)
    endloop
    set takedamage = null

    // unit enters the map/revives
    call TriggerRegisterAnyUnitEventBJ(entermap ,EVENT_PLAYER_HERO_REVIVE_FINISH)
    call TriggerRegisterEnterRectSimple(entermap, bj_mapInitialPlayableArea)
    call TriggerAddAction(entermap,function AddDamageTriggers)

    // unit dies
    call TriggerRegisterAnyUnitEventBJ(upondeath,EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddAction(upondeath,function RemoveDamageTriggers)
endfunction


you will need

The Local Handle Variables implemented in your map, and all actions from the Any Unit Takes Damage event should be enclosed in the Any Unit Takes Damage function

(ex. call ExecuteTrigger( gg_trg_MyTrig ))
#10
you can do this without weu and without jass.

ill show you soon.