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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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