- Joined
- Jul 26, 2008
- Messages
- 1,009
Here is my current damage detection system:
http://www.wc3c.net/showpost.php?p=1024305&postcount=2
Right now what happens is if a unit recieves or deals damage, he will be place in a group for 3 seconds, then removed.
Only problem is, right now it doesn't stack. If the unit takes damage he's removed 3 seconds after the first initial damage, even if he's damaged 2 seconds later, he'll be removed from the group in 1 second.
I'm wondering how I can fix this. I haven't had to worry about stacking effects yet.
This is important since some of the AI I'm creating relies on inBattle detection, as well as the custom healing. It's obviously buggy without stacking.
Thanks
http://www.wc3c.net/showpost.php?p=1024305&postcount=2
Right now what happens is if a unit recieves or deals damage, he will be place in a group for 3 seconds, then removed.
Only problem is, right now it doesn't stack. If the unit takes damage he's removed 3 seconds after the first initial damage, even if he's damaged 2 seconds later, he'll be removed from the group in 1 second.
I'm wondering how I can fix this. I haven't had to worry about stacking effects yet.
This is important since some of the AI I'm creating relies on inBattle detection, as well as the custom healing. It's obviously buggy without stacking.
Thanks
JASS:
scope InBattleDetector initializer Init
globals
group inBattle
endglobals
private struct Data
unit c
unit d
static method create takes unit battler, unit hurtingbattler returns Data
local Data D = Data.allocate()
set D.c = battler
set D.d = hurtingbattler
return D
endmethod
endstruct
private function Timer takes nothing returns nothing
local timer tim = GetExpiredTimer()
local Data D = Data(GetTimerData(tim))
call GroupRemoveUnit(inBattle, D.c)
call GroupRemoveUnit(inBattle, D.d)
call ReleaseTimer(tim)
call D.destroy()
endfunction
private function Conditions takes nothing returns boolean
local timer tim = NewTimer()
local real d = GetEventDamage()
local Data D = Data.create(GetTriggerUnit(), GetEventDamageSource())
set inBattle = CreateGroup()
if d > 0 then
call GroupAddUnit(inBattle, D.c)
call GroupAddUnit(inBattle, D.d)
call SetTimerData(tim,D)
call TimerStart(tim, 3.0, false, function Timer)
endif
return false
endfunction
private function Init takes nothing returns nothing
call AddDamageCondition(Condition(function Conditions))
endfunction
endscope