Prometheus
Everything is mutable; nothing is sacred
- Reaction score
- 589
I wouldn't compeltely trust the syntax checker, I've had infinite loops and it misses them. =(
That's odd, maybe CSData was already placed before the library. I don't know.
I'll be back later to go over the code.
1) I see you are using 1 timer per struct (unit). This not a big deal but could be swapped to using index arrays and a single timer looping through a main "loop" function, lowering the unit's "combat status duration".
2) I've not tested the attached map, but how will your system handle multiple tries to set a unit "In Combat"? (I'm a little lost with timers )
set this.u = null
set this.t = null
Yeah, it would need to loop through several units instead --> but you could do more things in between. And no, it shouldn't be an inaccurate timer -- unless you make some 3 sec interval with it..That kind of defeats the purpose of the timer. If I used a global timer, it would either have to be a very fast timer and looping through a lot of units, or it would be an inaccurate timer
Good to know.if you pause a timer, and try to unpause it,
Yeah, it would need to loop through several units instead --> but you could do more things in between. And no, it shouldn't be an inaccurate timer -- unless you make some 3 sec interval with it..
Struct members don't need to be nulled, they're globals.
Also, I think the "Conditions" function should go at the top, so it's easier to find and edit.
Yeah, and that timer would only need to be executed every 0.1 second, then it checks if "duration" is >= MaxDuration, if it is then destroy else add + 0.1 to duration. And it would only need to loop until "UnitsInCombat" is reached, not 8190 times ^^through all the possible units that could have a struct attached to it
Question I dont understand how this system works, i copied the cs data and the incombat file, do i have to do anything more?
function GetUnitInCombat takes unit u returns boolean
return IsUnitInGroup (UnitsInCombat, u)
//or
return CombatState<u> != 0
endfunction
function GroupCallback takes nothing returns nothing
local CombatState a = CombatState[GetEnumUnit ()]
set a.combatdur = a.combatdur + TIMER_INTERVAL
if a.combatdur >= COMBAT_DURATION then
call a.release ()
call GroupRemoveUnit (UnitsInCombat, a.u)
if IsGroupEmpty (UnitsInCombat) then
call PauseTimer (GlobalTimer)
endif
endif
endfunction
function TimerFunc takes nothing returns nothing
call ForGroup (UnitsInCombat, function GroupCallback)
endfunction
function SetUnitInCombat takes unit u returns nothing
local CombatState a = CombatState<u>
if a == 0 then
set a = CombatState.create (...)
if IsGroupEmpty (GlobalTimer) then
call TimerStart (GlobalTimer, TIMER_INTERVAL, true, function TimerFunc)
endif
call GroupAddUnit (UnitsInCombat, u)
//rest of the add-to-system stuff
else
//Reset the combat duration
set a.combatdur = 0
endfunction</u></u>
local CombatState cs = CombatState<u>
return cs != 0</u>
return CombatState<u> != 0</u>
call SetCSData(this.t,0)
even though the greatest discrepancy in actual time spent flagged in combat is TIMER_INTERVAL/2
New features? I don't really see why new features would be needed. It's a system which detects combat, it does that (albeit slightly flawed at the moment, but that's rectifiable), it doesn't need to be able to make me breakfast (although that would be great ). It's a simple concept, but it's the kind of simplicity I like - it does one particular thing, but it does it right (or, at least, it will, if/when you bring in damage events), does it really need anything more than that?Maybe some new features?
Bleh, wasn't thinking straight Not sure where I got that idea. Either way, 0.5s is safe enough I would imagine (if a player has an issue with half a second, they're a bit of a nerd to be honest )Actually, it would be anything less than the TIMER_INTERVAL, since a unit could technically enter combat immediately before the Timer loop starts incrementing unit's time spent in combat. Then, the timer loop would increment the unit's time by the full TIMER_INTERVAL.
I don't think you need to rename the trigger to the library's name, the initializer should work regardless of what the trigger name is (at least it does for me )3. Rename it "InCombat"
Ever gonna fix it?