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

Simple Damage Detection

Status
Not open for further replies.
Level 5
Joined
Feb 22, 2013
Messages
161
I am wanting to create a simple but efficient damage detection system, I saw the tutorial on it but that is really outdated and the newest one in JASS Resources is too complex and I don't need all of what it does in my map. I just want to know how to start one that detects the damage, nothing special and maybe once I figure out how it all works I can make modifications to it that suits my map. Also would like if this can be shown with vJass.
 
In essence, all you have to do is create a trigger with actions that point to the damage handler

In the damage handler, refer to GetEventDamageSource(), GetEventDamage(), and GetTriggerUnit() (which is the damaged unit)

Then, every unit that you want 'indexed' in the damage system should have its own event added to it: TriggerRegisterUnitEvent(t, u, EVENT_UNIT_DAMAGED)

That's really all there is to it. The reason other systems are so complicated is because this trigger now leaks an event - if the unit dies, it will never be removed from the trigger.

However, many production maps (even Eve of the Apocalypse: Twilight until ca. 2013) don't bother clearing this leak - if you don't have a lot of units, or you recycle units, this might never become a lag problem.

If you do have lag, the correct way to fix it is to destroy the trigger and rebuild it

DestroyTrigger(t)

set t = CreateTrigger()

// now add all the units again

This is where the complexity in contemporary damage detection systems come from - they all try to optimize this trigger rebuilding phase.

Best of luck!
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
This is the most simple Damage Detection System that exists.
What it does is making a trigger that runs when any unit on the map takes damage.
It resets every 300 seconds which is enough.

JASS:
globals
    trigger udg_DDS_Trigger = null
endglobals

//Modify this function.
function Taking_Damage takes nothing returns boolean
    call BJDebugMsg("Unit takes damage")
    return false
endfunction



function Add_Picked_Unit takes nothing returns nothing
    call TriggerRegisterUnitEvent(udg_DDS_Trigger, GetEnumUnit(), EVENT_UNIT_DAMAGED)
endfunction

function Add_Entering_Unit takes nothing returns boolean
    call TriggerRegisterUnitEvent(udg_DDS_Trigger, GetEnteringUnit(), EVENT_UNIT_DAMAGED)
    return false
endfunction

function Init_Damage_System takes nothing returns nothing
    local group g = CreateGroup()
    
    call DestroyTrigger(udg_DDS_Trigger)
    set udg_DDS_Trigger = CreateTrigger()
    call TriggerAddCondition(udg_DDS_Trigger, Filter(function Taking_Damage))
    
    call GroupEnumUnitsInRect(g, GetWorldBounds(), null)
    call ForGroup(g, function Add_Picked_Unit)
    call DestroyGroup(g)
endfunction

function InitTrig_Init_Damage_System takes nothing returns nothing
    local trigger t = CreateTrigger()
    local region r = CreateRegion()
    
    call RegionAddRect(r, GetWorldBounds())
    call TriggerRegisterEnterRegion(t, r, null)
    call TriggerAddCondition(t, Filter(function Add_Entering_Unit))
    
    call TimerStart(CreateTimer(), 300, true, function Init_Damage_System)
    call Init_Damage_System()
endfunction

Be aware that this also detects 0 damage which occurs more often than you would imagine.
Almost every effect in WC3 deals damage.
The ones that should not deal damage deal 0 damage.
Don't ask me why.

EDIT:
Utter garbage
Imo, every single DDS is garbage. Not because of how they are created but of how limited the "A unit takes damage" event from WC3 is.
I never use a DDS in my maps any more. I just trigger all damage and do that via custom triggers that I call an Alternative Damage-Engine.
 
it is the most efficient DDS system on hive that uses no jass code.

That's like saying it's the fastest race car without an engine.

RupTure_QS specifically asked for vJass.

Even though it's GUI friendly, the actual code uses loads of inline JASS.

i always use it and never had problems with it. everything works fine, it's really easy to use. why garbage?

Poor, hacky API using variable equality event.

No way to arbitrate execution order if you use multiple event handlers.

Extremely hacky inline jass implementation with things like custom script endfunction.

No support for spell damage/basic attack classification.

GUI Friendly is the bane of THW
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
That's like saying it's the fastest race car without an engine.

RupTure_QS specifically asked for vJass.

Even though it's GUI friendly, the actual code uses loads of inline JASS.



Poor, hacky API using variable equality event.

No way to arbitrate execution order if you use multiple event handlers.

Extremely hacky inline jass implementation with things like custom script endfunction.

No support for spell damage/basic attack classification.

GUI Friendly is the bane of THW


first of all, thanks for your kind words ;)


I just want to know how to start one that detects the damage, nothing special
he said it just needs to detect damage, and you can detect spell damage/basic damage if all the damage sources are done in trigger editor.
 
Status
Not open for further replies.
Top