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

Damage Inflicted

Status
Not open for further replies.
Level 2
Joined
Jul 2, 2006
Messages
12
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:
 
Level 22
Joined
Jan 10, 2005
Messages
3,426
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
 
Level 2
Joined
Jul 2, 2006
Messages
12
i'm worried about future compatibility... besides, i need some triggers that are in the normal editor that aren't in WEU...
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Credits to Shadow1500 for the script

(put this in a trigger called AnyDmg)

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