• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Expiration timers...

Status
Not open for further replies.
Level 3
Joined
Jul 15, 2007
Messages
36
Dear all, sorry to bother....

Trying to create a summoned unit, which has the "raise dead" timeout (blue bar thingy) on it, and then have it die 2 seconds later. I thought I would be using:

JASS:
function Undead_Actions takes unit u, integer level returns nothing
    local location loc = GetUnitLoc(u)
    local integer uid
    local unit dummy
    if level == 1 then
        set uid = 'u001'
    endif
    if level == 2 then
        set uid = 'u002'
    endif
    if level == 3 then
        set uid = 'u003'
    endif
    if level == 4 then
        set uid = 'u004'
    endif
    if level == 5 then
        set uid = 'u005'
    endif
    if level == 6 then
        set uid = 'u000'
    endif
    call CreateUnitAtLoc(Player(0), uid, loc, 270.0)
    set dummy = GetLastCreatedUnit()
    call IssuePointOrderLoc(dummy, "attack", loc)
    call UnitApplyTimedLife( dummy, 'Brai', 2.0 )    
    set dummy = null
    call RemoveUnit(dummy)
    call RemoveLocation(loc)
endfunction

(or call UnitApplyTimedLifeBJ( 2.00, 'BUan', dummy ) )

but doesn't seem to do what I want... do I need to add the ability/buff 'BUan' or 'Brai' to the unit? i.e. (doesn't seem to work

JASS:
function Undead_Actions takes unit u, integer level returns nothing
    local location loc = GetUnitLoc(u)
    local integer uid
    local unit dummy
    if level == 1 then
        set uid = 'u001'
    endif
    if level == 2 then
        set uid = 'u002'
    endif
    if level == 3 then
        set uid = 'u003'
    endif
    if level == 4 then
        set uid = 'u004'
    endif
    if level == 5 then
        set uid = 'u005'
    endif
    if level == 6 then
        set uid = 'u000'
    endif
    call CreateUnitAtLoc(Player(0), uid, loc, 270.0)
    set dummy = GetLastCreatedUnit()
    call IssuePointOrderLoc(dummy, "attack", loc)
    call UnitAddAbility(dummy, 'Brai')
    call UnitApplyTimedLife( dummy, 'Brai', 2.0 )    
    set dummy = null
    call RemoveUnit(dummy)
    call RemoveLocation(loc)
endfunction

thank-you for your help

*edit - changed to native
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
GetLastCreatedUnit only works for CreateNUnitsAtLocBJ

use

set dummy = CreateUnitAtLoc( Player(0), uid, loc, 270 )

Or, if you want to be more efficient, remove the loc completely, and...

set dummy = CreateUnit( Player( 0 ), uid, GetUnitX( u ), GetUnitY( u ), 270 )

Oh, and call RemoveUnit( dummy ) after set dummy=null is useless.
 
Level 3
Joined
Jul 15, 2007
Messages
36
Thanks - I thought you had to remove a unnit var to stop it leaking.

Wouldn't GetUnitX() GetUnitY() be calling more functions (even though they are natives) and be mildly less efficient?
 
Level 15
Joined
Feb 15, 2006
Messages
851
Thanks - I thought you had to remove a unnit var to stop it leaking.

Wouldn't GetUnitX() GetUnitY() be calling more functions (even though they are natives) and be mildly less efficient?
GetUnitX() and GetUnitY() is better and cleaner because you get directly the coordinates of the unit and you save one handle (the location)

BTW, why did you added the 'Brai' buff to the unit?? it's not necessary, that buff is only used to show the name of the unit/ability/buff in the timed life bar. so you can do something like this:

call UnitApplyTimedLife( dummy, uid, 2.0 )it will show the name of the unit in the timer bar, or:
call UnitApplyTimedLife( dummy, SpellID, 2.0 ), where SpellID is the rawcode of the spell.
 
Level 11
Joined
Oct 13, 2005
Messages
233
GetUnitX() and GetUnitY() is better and cleaner because you get directly the coordinates of the unit and you save one handle (the location)

Just to expand on this, native functions differ from non-natives. Some natives will be faster than a call to DoNothing, for instance. While normally 2 function calls is slower than 1, things can change when using natives.

As moyack said before, using GetUnitX/Y tends to be faster because those functions don't create a location. Using the location the way you do, it still takes 2 function calls:
  • Get the location
  • Destroy the location
In addition, you also have to null the local variable you use to store the location. This just reinforces that GetUnitX/Y is faster and more convenient.

BTW, why did you added the 'Brai' buff to the unit?? it's not necessary, that buff is only used to show the name of the unit/ability/buff in the timed life bar. so you can do something like this:

call UnitApplyTimedLife( dummy, uid, 2.0 )it will show the name of the unit in the timer bar, or:
call UnitApplyTimedLife( dummy, SpellID, 2.0 ), where SpellID is the rawcode of the spell.

I never knew you could do that; so thanks for pointing out the possibility of using other ids for the UnitApplyTimedLife function. I'll be sure to take advantage of this at some point.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
call UnitApplyTimedLife( dummy, uid, 2.0 )it will show the name of the unit in the timer bar, or:
call UnitApplyTimedLife( dummy, SpellID, 2.0 ), where SpellID is the rawcode of the spell.
Handy (doubt I'll ever use it, but still cool). Thanks, I never knew you could do that. +rep!

Thanks - I thought you had to remove a unnit var to stop it leaking.
That's what you're doing by nulling it

Wouldn't GetUnitX() GetUnitY() be calling more functions (even though they are natives) and be mildly less efficient?
Instead of calling GetUnitLoc, creating a variable, referencing a variable, calling RemoveLocation, then nulling a variable? =/
 
Status
Not open for further replies.
Top