I tried to make a script for map that judges who killed unit with damage dealt instead of just last hit so I wrote this:
but when I do:
ps: there is a GetUnitCount() which counts unit on map and the whole DmgSys is wrote by me also but they are flawless, if I print the damage[..].real[..] it prints the damage unit dealt to other unit and GetUnitcount also returns unit on map correctly. lastindex variable is an attempt to overcome UnitIndexer deindexing the unit
Please, if you spot any error I didnt spot let me know
JASS:
library GetKiller uses UnitIndexer, DmgSys, TimerUtils, GetUnitCountOnMap //by edo494
globals
private TableArray damage
private unit array killer
private integer array lastindex
endglobals
function GetDamageDoneToUnit takes unit tounit, unit which returns real
return damage[GetUnitUserData(tounit)].real[GetUnitUserData(which)]
endfunction
function GetKiller takes unit deadunit returns unit
return killer[lastindex[GetUnitUserData(deadunit)]]
endfunction
function GetKillerId takes unit deadunit returns integer
return GetUnitId(killer[lastindex[GetUnitUserData(deadunit)]])
endfunction
private function setKiller takes nothing returns nothing
local unit u = GetUnitById(GetTimerData(GetExpiredTimer()))
local integer i = 1
local integer o = GetTimerData(GetExpiredTimer())
local integer unitsonmap = GetUnitCount()
call ReleaseTimer(GetExpiredTimer())
if IsUnitType(u, UNIT_TYPE_DEAD) then
loop
exitwhen i > unitsonmap
if damage[o].real[i] > damage[o].real[i-1] then
set killer[o] = GetUnitById(i)
endif
set i = i + 1
endloop
endif
set u = null
endfunction
private function IncreaseDamageDone takes nothing returns nothing
local integer take = GetUnitUserData(GetTriggerUnit())
local integer deal = GetUnitUserData(GetEventDamageSource())
set damage[take].real[deal] = damage[take].real[deal] + GetEventDamage()
set lastindex[take] = take
call TimerStart(NewTimerEx(take), 0, false, function setKiller)
endfunction
private module init
static method onInit takes nothing returns nothing
local code c = function IncreaseDamageDone
call DmgSys.register(c)
set damage = TableArray[0x2000]
endmethod
endmodule
private struct s_init extends array
implement init
endstruct
endlibrary
-
Untitled Trigger 001
-
Events
- Unit - A unit Dies
- Conditions
-
Actions
- Custom script: call BJDebugMsg(GetUnitName(GetKiller(GetTriggerUnit())))
-
Events
ps: there is a GetUnitCount() which counts unit on map and the whole DmgSys is wrote by me also but they are flawless, if I print the damage[..].real[..] it prints the damage unit dealt to other unit and GetUnitcount also returns unit on map correctly. lastindex variable is an attempt to overcome UnitIndexer deindexing the unit
Please, if you spot any error I didnt spot let me know