• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Unit expiration-timer help

Status
Not open for further replies.

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Expiration timer works some nice wonders, call UnitApplyTimedLife(u, 'BTLF', 0.00).

Do you know how to remove this or how to prolong the time? I did call UnitRemoveAbility(u, 'BTLF') and it just killed the unit! It's laughable.

I tried modifying the life regeneration in the object editor field to -1.00 and setting the widget's life to the time I wanted it to expire at, but the regeneration is off-balance. I did this test:

JASS:
function TestDeath takes nothing returns nothing
    call BJDebugMsg("Killed")
endfunction

function InitTrig_Test takes nothing returns nothing
    call SetWidgetLife(CreateUnit(Player(0), 'hfoo', 0, 0, 0), 5.00)
    call TimerStart(CreateTimer(), 5.00, false, function TestDeath)
endfunction

The timer fired shortly after the unit died. I did another test with 10 seconds and the timer fired BEFORE the unit died. Obviously a widget's life decay is unreliable as an accurate time-scale measurement.

I think the solution may be found in UnitApplyTimedLife... that is, can the expiration timer on it be increased to prolong the life of the dummy unit?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Pausing the unit or the timer would definitely prolong the unit's life, but let me explain a little deeper.

Working on the most efficient way possible to do a projectile system and the projectile's "time remaining" is constantly fluctuating higher or lower if the target-unit moves. My attempt is to avoid real comparisons during the loop :-/

Real comparisons may still be the best option possible... but this timed-life thing is not the solution if it has no "undo" or "reset" option.

I did try this as well and only the first timeout was applied (indicating the second call did nothing):

JASS:
call UnitApplyTimedLife(u, 'BTLF', 1.)
call UnitApplyTimedLife(u, 'BTLF', 2.)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I tried that too and also Metamorphosis. No luck.

This is just a wild guess but could large integers be faster than small reals?

For example integer 1 represents 0.01 seconds. 100 represents 1.00 seconds. You could do integer comparisons. What speed advantage it would bring, I am not sure of.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Since it is for projectiles, which have probably the 'Aloc' ability the easiest way but the least efficient would be to use one timer per projectile and start it with a different timeout value each time it's needed.
But i guess you will hate this idea ^^
Plus i believe it wouldn't handle many units at the same time without losing many fps.

If someday you would have the real need of removing this buff, i suggest to add an instant passive revive ability to your unit, remove the buff, remove the revive ability (you coul do that all in the same thread without any wait, probably because the ability is truly instant or it isn't removed instantly, or both :p)

I hadn't try it like that but i did that for remove all effects of 'Aloc' (add revive ability, kill unit, remove revive ability)

Sure it would stop current orders, stop targets and such things.

PS : I used an ability based on 'AOre', and edited the time of casting to 0.
 
Last edited:
Level 10
Joined
Jul 12, 2009
Messages
318
Timed life can be paused, and then a new timed life can be applied. Still, only the first (paused) application will show if you select the unit, and I know of no way to remove it entirely without killing the unit...but for projectiles, this isn't really an issue.

I don't know of any direct way to get a unit's remaining duration, nor a way to make the bar move further to the right in the UI, since it's always the first-applied expiration that shows. I suppose the rate of expiration could be varied by periodically pausing and resuming it.

[edit] I forgot; casting Control Magic on a unit with expiration will set its timer bar back to full and to the duration of the Control Magic spell. If I remember right, the expiration timer will also be reset to full afterward? I forgot...

I did try this as well and only the first timeout was applied (indicating the second call did nothing):
Incorrect; it means it had two timers, and it died when the shorter timer expired.
 
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Yes, Control Magic resets the timed-life duration of a unit. So I could cast control magic with a rigged control magic dummy ability, then apply that shorter timed life duration. It would probably be less efficient than what I want to get involved with, if there are a lot of homing missiles, but this is a great solution next time I need to get rid of the Timed Life ability, and finally there is a solution!
 
Status
Not open for further replies.
Top