All of a sudden, no one cares
Unless it is 100% precise, it's not useful.
that's why he asked for someone to check his work and figure out what's wrong with it...
All of a sudden, no one cares
Unless it is 100% precise, it's not useful.
// |===========================================================================================|
// |*******************************************************************************************|
// |***** PRECISE DAMAGE COUNTER *****|
// |*** ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ****|
// |** v1.4 by Furby ***|
// |***** v1.5 by 13lade619 *****|
// |*******************************************************************************************|
// | - Requirements - |
// | AIDS |
// | Damage |
// |*******************************************************************************************|
// | - Functions - |
/* | PDC_GetDamagePercentUnit takes unit whatUnit, player whatPlayer returns real |*/
// | - returns damage done to the unit in percent |
/* PDC_GetMostDamagePlayer takes unit whatUnit returns player |*/
// | - returns player who done the most damage to unit |
// |*******************************************************************************************|
// | more info at thehelper.net |
// |===========================================================================================|
library PDC requires AIDS, Damage
// If this function will return true, unit will be counted as valid
private function ValidUnit takes unit u returns boolean
return true
endfunction
// If this function will return true, damage will be counted as valid
// uses the usual damage event responses
private function ValidDamage takes nothing returns boolean
return true
endfunction
private struct DamageCount
real healhp = 0
real prevhp = 0
real dmg = 0
real hpbase = 0
player who
thistype next
thistype prev
private method onDestroy takes nothing returns nothing
set hpbase = 0
set healhp = 0.0
set prevhp = 0.0
set dmg = 0.0
set who = null
endmethod
endstruct
private struct VictimUnit extends array
//! runtextmacro AIDS()
DamageCount first
DamageCount last
private static method AIDS_filter takes unit u returns boolean
return ValidUnit(u)
endmethod
private method AIDS_onDestroy takes nothing returns nothing
local DamageCount dc = first
loop
exitwhen(dc.next == dc or dc == 0)
call dc.destroy()
set dc = dc.next
endloop
endmethod
private static method onDamage takes nothing returns nothing
local unit u = GetTriggerUnit()
local thistype this = VictimUnit<u>
local player p = GetOwningPlayer(GetEventDamageSource())
local real hp = GetWidgetLife(u)
local real dealt = GetEventDamage()
local DamageCount dc = 0
local DamageCount temp = 0
if dealt > hp then
set dealt = hp
endif
if first > 0 then
if last.who == p then
set dc = last
else
set dc = DamageCount.create()
set last.next = dc
set dc.next = dc
set dc.prev = last
set last = dc
endif
else
set dc = DamageCount.create()
set first = dc
set dc.next = dc
set dc.prev = dc
set last = dc
set dc.hpbase = GetUnitState(u, UNIT_STATE_MAX_LIFE)
endif
set dc.who = p
set dc.dmg = dc.dmg+dealt
//call BJDebugMsg(GetUnitName(u))
//call BJDebugMsg("PREV "+R2S(dc.prev.prevhp))
//call BJDebugMsg("DAMG "+R2S(dealt))
//call BJDebugMsg("THIS "+R2S(hpbeforedamage))
if (hp+dealt)>dc.prev.prevhp and dc.prev.prevhp!=0 then
//call BJDebugMsg("HEAL "+R2S(hp+dealt-dc.prev.prevhp)+"\n\n")
set dc.healhp = dc.healhp + (hp+dealt-dc.prev.prevhp)
endif
set dc.next.prevhp = hp
set u = null
endmethod
private static method AIDS_onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call Damage_RegisterEvent(t)
call TriggerAddCondition(t, Condition(function ValidDamage))
call TriggerAddAction(t, function thistype.onDamage)
endmethod
endstruct
//======================================================================================
public function GetDamagePercentUnit takes unit whatUnit, player whatPlayer returns real
local DamageCount dc = VictimUnit[whatUnit].first
local real damages = 0
local real maxlife = 0
local real regenhp = 0
local real percentage = 0
loop
set maxlife = maxlife + dc.hpbase
set regenhp = regenhp + dc.healhp
if dc.who == whatPlayer then
set damages = damages + dc.dmg
endif
exitwhen(dc.next == dc or dc == 0)
set dc = dc.next
endloop
return (damages/(maxlife+regenhp))*100
endfunction
public function GetMostDamagePlayer takes unit whatUnit returns player
local real temp = 0
local player result = null
local integer i = 0
loop
exitwhen(i>15)
if GetDamagePercentUnit(whatUnit, Player(i)) > temp then
set result = Player(i)
set temp = GetDamagePercentUnit(whatUnit, Player(i))
endif
set i = i + 1
endloop
return result
endfunction
endlibrary</u>
First Test:
Laiev has done - 25.441% of damage
Player 2 has done - 28.046% of damage
Player 3 has done - 28.731% of damage
= 82.218%
Second Test:
Laiev has done - 33.695% of damage
Player 2 has done - 38.291% of damage
Player 3 has done - 21.154% of damage
= 93.14%
Third Test:
Laiev has done - 13.305% of damage
Player 2 has done - 23.462% of damage
Player 3 has done - 20.783% of damage
= 57.55%
OK. Now, imagine a boss fight, where it's regenerating and casting heals upon itself. The DPS hits it the whole time, wearing it down and causing it to expend its mana. Then, the nukers rush in and finish it off. Should the DPS not receive credit because its their damage that was healed away? That's not right.I damage Blue player like 20 times but goes back a little heals or regenerates but he doesn't die. Those 20 times you hit him would kill him like 5 times already.. Then he goes back to base, heals and goes to another lane, where he dies by two hits from your ally and you would have an assistance.. that's not right.
Precise Damage Counter 1.5
//...
if (hp+dealt)>dc.prev.prevhp and dc.prev.prevhp!=0 then
set dc.healhp = dc.healhp + (hp+dealt-dc.prev.prevhp)
//...
if hp>dc.prev.prevhp-dc.prev.dealt and dc.prev.prevhp!=0 then
set dc.healhp = dc.healhp + (hp+dc.prev.dealt-dc.prev.prevhp)