Hello,
I've just posted a threat about my loops. But another thing is being a pain to code: my CombatState system.
First of, the code:
This should work like this:
-You set the unit in/out of combat.
-If the unit is already in combat, the combat timer is refreshed.
-You can GetUnitCombatState(whichUnit) which will return true if the unit is in combat.
Problems:
-When my hero dies 'in combat' the struct is not destroyed (it says so in the
I made a simple trigger just to show my hero combat state when I type '-reset', and it shows I'm in combat, even after the unit is dead and/or revived.
I used this trigger to set units out of combat when dead:
I've searched for some other systems that do the same. But I want a simple system that should work in my map, with my customizations. Any suggestions are welcome
I've just posted a threat about my loops. But another thing is being a pain to code: my CombatState system.
First of, the code:
JASS:
library CombatState requires TextTag, ABC, PUI
globals
private constant real COMBAT_PERIOD = 7.
endglobals
private struct CombatData
//! runtextmacro PUI()
timer Clock = CreateTimer()
unit Unit
player Owner
integer Index
static method Create takes unit whichUnit returns CombatData
local CombatData d = CombatData.allocate()
set d.Unit = whichUnit
set d.Owner = GetOwningPlayer(whichUnit)
set d.Index = GetPlayerId(d.Owner)
call SetTimerStructA(d.Clock, d)
if GetLocalPlayer() == GetOwningPlayer(d.Unit) then
call TextTag_Create(PlayerColor[d.Index], "<Entering combat>", d.Unit, 10, 90, 86, d.Owner, true)
endif
return d
endmethod
method onDestroy takes nothing returns nothing
if GetLocalPlayer() == GetOwningPlayer(.Unit) and not IsUnitType(.Unit, UNIT_TYPE_DEAD) then
call TextTag_Create(PlayerColor[.Index], "<Leaving combat>", .Unit, 10, 90, 86, .Owner, true)
endif
call ClearTimerStructA(.Clock)
call PauseTimer(.Clock)
call DestroyTimer(.Clock)
endmethod
endstruct
private function CombatExpired takes nothing returns nothing
local timer t = GetExpiredTimer()
local CombatData d = GetTimerStructA(t)
debug call BJDebugMsg("CombatData destroyed by CombatExpired() function")
call d.destroy()
endfunction
function GetUnitCombatState takes unit whichUnit returns boolean
return CombatData[whichUnit] != 0
endfunction
function SetUnitInCombat takes unit whichUnit returns nothing
local CombatData d = CombatData[whichUnit]
if d == 0 then
set d = CombatData.Create(whichUnit)
set CombatData[whichUnit] = d
debug call BJDebugMsg("CombatData() created.")
endif
call TimerStart(d.Clock, COMBAT_PERIOD, false, function CombatExpired)
endfunction
function SetUnitOutOfCombat takes unit whichUnit returns nothing
local CombatData d = CombatData[whichUnit]
if d != 0 then
call d.destroy()
debug call BJDebugMsg("SetUnitOutOfCombat() function destroyed current CombatData struct.")
else
debug call BJDebugMsg("|cffff0000 SetUnitOutOfCombat() function failed to destroy struct.")
endif
endfunction
endlibrary
This should work like this:
-You set the unit in/out of combat.
-If the unit is already in combat, the combat timer is refreshed.
-You can GetUnitCombatState(whichUnit) which will return true if the unit is in combat.
Problems:
-When my hero dies 'in combat' the struct is not destroyed (it says so in the
BJDebugMsg
but it doesn't seems to work.I made a simple trigger just to show my hero combat state when I type '-reset', and it shows I'm in combat, even after the unit is dead and/or revived.
I used this trigger to set units out of combat when dead:
JASS:
scope test initializer onInit
private function OnDeath takes nothing returns nothing
local unit whichUnit = GetDyingUnit()
call SetUnitOutOfCombat(whichUnit)
endfunction
private function onInit takes nothing returns nothing
local trigger death = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(death, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction(death, function OnDeath)
endfunction
endscope
I've searched for some other systems that do the same. But I want a simple system that should work in my map, with my customizations. Any suggestions are welcome