• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Damage Detection

Status
Not open for further replies.
Level 10
Joined
Jan 21, 2007
Messages
576
Alright i have this script:

JASS:
function AnyUnitTakesDamage takes nothing returns nothing
call TriggerExecute(gg_trg_DamageDetector)
// 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

Which runs the trigger DamageDetector whenever a unit takes damage:

  • DamageDetector
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has buff 1Polymorph ) Equal to True
        • Then - Actions
          • Unit - Cause (Damage source) to damage (Triggering unit), dealing ((Damage taken) x 0.20) damage of attack type Hero and damage type Normal
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has buff 2Polymorph ) Equal to True
        • Then - Actions
          • Unit - Cause (Damage source) to damage (Triggering unit), dealing ((Damage taken) x 0.30) damage of attack type Hero and damage type Normal
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has buff 3Polymorph ) Equal to True
        • Then - Actions
          • Unit - Cause (Damage source) to damage (Triggering unit), dealing ((Damage taken) x 0.40) damage of attack type Hero and damage type Normal
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
        • Then - Actions
          • Unit - Cause (Damage source) to damage (Triggering unit), dealing ((Damage taken) x 0.50) damage of attack type Hero and damage type Normal
        • Else - Actions
But when i refer to Damage Taken in the GUI trigger it crashes wc3 does anyone know why and/or how i can fix it?
 
Level 11
Joined
Feb 18, 2004
Messages
394
using functions which refer to event-values in triggers called via methods other than by an event which uses that value will crash WC3.

In other words: You can not execute a trigger, and then use GetTriggerUnit() or whatever other trigger-based event functions, and expect it to work. (which includes whatever function (i forget..) "Damage Taken" is.) The same holds true for GetExpiredTimer(), if i recall correctly.
 
Status
Not open for further replies.
Top