Snippet Smart Damage Detection

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Smart Damage Tracker

JASS:
============================================================
   _______     ______     _______                    
  /  _____\   |  ___ \   |___ ___|  SMART           
  | |_____    | |   \ \     | |       DAMAGE        
  \_____  \   | |   | |     | |         TRACKER
   _____| |   | |___/ /     | |                  
  \_______/   |______/      |_|   BY : kingking
============================================================
                                                
    FUNCTIONS PROVIDED :
    function GetTotalDamageDealt takes unit whichunit returns real
    function GetTotalDamageTaken takes unit whichunit returns real
    function GetU2UDamage takes unit targ, unit source returns real
    function GetDamageDealt takes unit whichunit, damagetype whichtype returns real
    function GetDamageTaken takes unit whichunit, damagetype whichtype returns real
    function GetLastPhysicalDamage takes unit whichunit returns real
    function GetLastAttackDamage takes unit whichunit returns real
    function GetLastSpellDamage takes unit whichunit returns real
    function GetLastPureDamage takes unit whichunit returns real
            
    Requires :
    AIDS   [thehelper.net/forums/showthread.php?t=130752]
    Damage [thehelper.net/forums/showthread.php?t=131287]
    NewGen
    Wc3 1.24b


JASS:
library SDT initializer Init requires AIDS, Damage
    
    globals
        private hashtable DamageTargetTracker
        private hashtable DamageDealt
        private hashtable DamageTaken
    endglobals
    
    private struct Data
        real dmgtaken
        real dmgdealt
        real lastspldmg
        real lastatkdmg
        real lastphydmg
        real lastpuredmg
        
        method AIDS_onDestroy takes nothing returns nothing
            call FlushChildHashtable(DamageTargetTracker,GetUnitId(this.unit))
            call FlushChildHashtable(DamageDealt,GetUnitId(this.unit))
            call FlushChildHashtable(DamageTaken,GetUnitId(this.unit))
            set this.dmgtaken = 0.
            set this.dmgdealt = 0.
            set this.lastspldmg = 0.
            set this.lastatkdmg = 0.
            set this.lastphydmg = 0.
            set this.lastpuredmg = 0.
        endmethod
        //! runtextmacro AIDS()
    endstruct

    function GetTotalDamageDealt takes unit whichunit returns real
        return Data[whichunit].dmgdealt
    endfunction
    
    function GetTotalDamageTaken takes unit whichunit returns real
        return Data[whichunit].dmgtaken
    endfunction
    
    function GetU2UDamage takes unit source, unit targ returns real
        return LoadReal(DamageTargetTracker,GetUnitId(source),GetUnitId(targ))
    endfunction
    
    function GetDamageDealt takes unit whichunit, damagetype whichtype returns real
        return LoadReal(DamageDealt,GetUnitId(whichunit),GetHandleId(whichtype))
    endfunction
        
    function GetDamageTaken takes unit whichunit, damagetype whichtype returns real
        return LoadReal(DamageTaken,GetUnitId(whichunit),GetHandleId(whichtype))
    endfunction
    
    function GetLastPhysicalDamage takes unit whichunit returns real
        return Data[whichunit].lastphydmg
    endfunction
    
    function GetLastSpellDamage takes unit whichunit returns real
        return Data[whichunit].lastspldmg
    endfunction
    
    function GetLastAttackDamage takes unit whichunit returns real
        return Data[whichunit].lastatkdmg
    endfunction
    
    function GetLastPureDamage takes unit whichunit returns real
        return Data[whichunit].lastpuredmg
    endfunction
    
    globals
        private unit damager
        private unit damaged
        private real amount
        private integer id
        private integer id2
        private integer dmgid
        private Data temp
    endglobals
    
    private function Record takes nothing returns boolean
        set damager = GetEventDamageSource()
        set damaged = GetTriggerUnit()
        set amount = GetEventDamage()
        set id = GetUnitId(damager)
        set id2 = GetUnitId(damaged)
        set dmgid = GetHandleId(Damage_GetType())
        set Data[damager].dmgdealt = Data[damager].dmgdealt + amount
        call SaveReal(DamageDealt,id,dmgid,LoadReal(DamageDealt,id,dmgid)+amount)
        set Data[damaged].dmgtaken = Data[damaged].dmgtaken + amount
        call SaveReal(DamageTaken,id2,dmgid,LoadReal(DamageTaken,id2,dmgid)+amount)
        call SaveReal(DamageTargetTracker,id,id2,LoadReal(DamageTargetTracker,id,id2) + amount)
        if Damage_IsAttack() then
            set Data[damaged].lastatkdmg = amount
        endif
        if Damage_IsPhysical() then
            set Data[damaged].lastphydmg = amount
        elseif Damage_IsSpell() then
            set Data[damaged].lastspldmg = amount
        elseif Damage_IsPure() then
            set Data[damaged].lastpuredmg = amount
        endif
        return false
    endfunction

    
    private function Init takes nothing returns nothing
        local trigger t 
        
        set DamageTargetTracker = InitHashtable()
        set DamageDealt = InitHashtable()
        set DamageTaken = InitHashtable()
        
        set t = CreateTrigger()
        call Damage_RegisterEvent(t)
        call TriggerAddCondition(t,Condition(function Record))
    endfunction
endlibrary


Required Systems :
AIDS
Damage
 

Steel

Software Engineer
Reaction score
109
Didn't J4L write his own damage detection with AIDS and Event...?
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
It's got some random stuff that DDS's don't tend to have, but it's lacking the essentials. Like the functionality to provide a method for differentiation between spell and attack damage.
 

Jesus4Lyf

Good Idea™
Reaction score
397
There's nothing seriously wrong with it. It is a damage tracker with an "any unit damaged" style event. It is 100% compatible with Damage and vice versa anyway, but...

I would recommend this actually be built on Damage. It looks like a nice coding exercise for yourself, and you've used AIDS well! But typically there is a benefit to making this use Damage's event, which is if both are implemented there is only one trigger per unit still. :thup:

So [LJASS]method fire[/LJASS] could be on a trigger that has the Damage_RegisterEvent called on it, and changes requirements to AIDS and Damage (not Event).

Actually, this could be cool as a damage tracker. You could make it register at what game time damage is dealt, and then enumerate all damage over the last x seconds (hashtables)... But this is probably overkill. XD

There is one fundemental issue. Getting the unit's last damage is not useful on its own, usually you want its last spell damage or last attack damage. If you used Damage, you could detect this, but otherwise you have more or less a lost cause. There are other ways to detect it... If you care to search. :thup: (They're all a pain in the a$$. :))
[lJASS]GetEventDamage()[/lJASS] doesn't do the job anymore?
His functions all take a unit. It's kind of neat but the applications in its current form are limited (as mentioned above). Very limited.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Updated. It has some new nice functions now. :D
And uses hashtable too.
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
LoadReal(DamageTaken,GetUnitId(whichunit),0)

-->
JASS:
DamageTaken[GetUnitId(whichunit)] // Some array.

And
There is one fundemental issue. Getting the unit's last damage is not useful on its own, usually you want its last spell damage or last attack damage. If you used Damage, you could detect this
Fundemental as in, fix or graveyard. :thup:
(Not hard to solve, just use the Damage methods - you could even hash based on unit and [LJASS]GetHandleId(Damage_GetType())[/LJASS] - but you probably want Damage_IsAttack somewhere too.)

>Putting damage type in GetHandleId does not work.
Are you sure? o_O
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
what. This does thing mine does but more. this is a copy of my idea and no credits or anything what so ever
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I am back now. Just now I went out for a while.

Putting damage type in GetHandleId does not work.
Nono, it works. :p

I will start working it now.

Update : 1.0b

what. This does thing mine does but more. this is a copy of my idea and no credits or anything what so ever
???
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
what. This does thing mine does but more. this is a copy of my idea and no credits or anything what so ever

...Millions of people have had your idea before you, are you copying them?
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
??? I havent seen any yet exept mine and this

Edit: Oh yea and can you have a demo map with all the systems and the snippit in it. It takes awhile if you dont know where to find the systems to find them and get them into your map.
 

UndeadDragon

Super Moderator
Reaction score
447
There have been plenty. You can't really claim to be the first.
 

Jesus4Lyf

Good Idea™
Reaction score
397
what. This does thing mine does but more.
You should use this instead. He got it leakless in the first couple of releases, while yours still leaks.

And this does not track damage over time. Which is all yours did?
Or are you claiming that registering damage was your original idea...
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
yea just leave that but what about my suggestion to put everything in a demomap?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top