• 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] Does this function leak? (Will it even work?)

Status
Not open for further replies.
Level 4
Joined
May 6, 2007
Messages
87
JASS:
function RingHealAmmount takes nothing returns real
    local real heal
    set heal = 100                                   //The ammount of life gained in total.
    return (heal-25)/50                              //Note: It is not accurate, that's why "-25" is there.
endfunction

The ability has four levels, and each level is supposed to heal for 50 * level(i.e. Level 2 would heal for 100 (50*2)).

How do I set it so that the spell will heal for 50 * the level of the ability?

Thanks a bunch!
 
Last edited:
Level 20
Joined
Apr 22, 2007
Messages
1,960
That function does not leak, but it's unefficient.

If you want to use levels, then do this:
JASS:
function RingHealAmmount takes unit caster returns real
    return 50*GetUnitAbilityLevel(caster,'YOUR_ABIL_RAWCODE')
endfunction
Replace YOUR_ABIL_RAWCODE by the rawcode of the casted ability.
That function returns 50 * the level of the ability.
 
Level 4
Joined
May 6, 2007
Messages
87
When I changed it to that, I had about a million errors.

Here's the full code:

JASS:
function Trig_Ring_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00Q'             //Raw code of the ability.
endfunction
function RingUnitRawCode takes nothing returns integer
    return 'e002'                                    //Raw code of the ring dummy (blue).
endfunction
function RingHealAmmount takes nothing returns real
    local real heal = 100.0                          //The ammount of life gained in total.
    return (heal-25)/50                              //Note: It is not accurate, that's why "-25" is there.
endfunction
function RingCasterDummyRawCode takes nothing returns integer
    return 'e001'                                    //Raw code of your spellcaster dummy.
endfunction
function RingDummyAbilityRawCode takes nothing returns integer
    return 'A00R'                                    //Raw code of the dummy ability that deals the damage. Must base it on War Stomp!
endfunction

function Ring_Up takes nothing returns nothing
    local timer t   = GetExpiredTimer()    
    local unit array d
    local unit u    = GetHandleUnit(t, "unit") 
    local real h    = GetHandleReal(t, "h")
    local real a    = GetHandleReal(t, "a")
    local real dis  = GetHandleReal(t, "d")    
    local integer A = 1
    local real x    = GetUnitX(u)
    local real y    = GetUnitY(u)
    local real nx   = 0
    local real ny   = 0
    call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE) + RingHealAmmount())
    loop
        exitwhen A > 9
        set d[A] = GetHandleUnit(t, "dum"+I2S(A))
        set nx = x + dis * Cos(a * (3.14159/180))
        set ny = y + dis * Sin(a * (3.14159/180))
        call SetUnitFlyHeight(d[A], h, 0)
        call SetUnitPosition(d[A], nx, ny)
        call SetUnitFacing(d[A], A*40) 
        set d[A] = null
        set a = a + 40
        set A = A + 1
    endloop
    set a = GetHandleReal(t, "a")
    call SetHandleReal(t, "a", a + 10)
    call SetHandleReal(t, "h", h + 7)
    set u = null     
endfunction

function Ring_Roll takes nothing returns nothing
    local timer t   = GetExpiredTimer()    
    local unit array d
    local unit u    = GetHandleUnit(t, "unit")
    local real a    = GetHandleReal(t, "a")
    local real dis  = GetHandleReal(t, "d") 
    local integer A = 1
    local real x    = GetUnitX(u)
    local real y    = GetUnitY(u)
    local real nx   = 0
    local real ny   = 0
    loop
        exitwhen A > 9
        set d[A] = GetHandleUnit(t, "dum"+I2S(A))
        set nx = x + dis * Cos(a * (3.14159/180))
        set ny = y + dis * Sin(a * (3.14159/180))
        call SetUnitPosition(d[A], nx, ny)
        call SetUnitFacing(d[A], A*40) 
        set d[A] = null
        set a = a + 40
        set A = A + 1
    endloop
    set a = GetHandleReal(t, "a")
    call SetHandleReal(t, "a", a + 10)
    call SetHandleReal(t, "d", dis - 2)
    set t = null
    set u = null     
endfunction

function Ring_Down takes nothing returns nothing
    local timer t   = GetExpiredTimer()
    
    local unit array d
    local unit u    = GetHandleUnit(t, "unit") 
    local real h    = GetHandleReal(t, "h")
    local real a    = GetHandleReal(t, "a")
    local real dis  = GetHandleReal(t, "d")
    local real c    = GetHandleReal(t, "c")
    local integer A = 1
    local real x    = GetUnitX(u)
    local real y    = GetUnitY(u)
    local real nx   = 0
    local real ny   = 0
    loop
        exitwhen A > 9
        set d[A] = GetHandleUnit(t, "dum"+I2S(A))
        set nx = x + dis * Cos(a * (3.14159/180))
        set ny = y + dis * Sin(a * (3.14159/180))
        call SetUnitFlyHeight(d[A], h, 0)
        call SetUnitPosition(d[A], nx, ny)
        call SetUnitFacing(d[A], A*40) 
        set d[A] = null
        set a = a + 40
        set A = A + 1
    endloop
    set a = GetHandleReal(t, "a")
    call SetHandleReal(t, "c", c + 10)
    call SetHandleReal(t, "h", h - c)
    set t = null
    set u = null     
endfunction

function Trig_Ring_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetTriggerUnit()
    local unit array d
    local real x = 0
    local real y = 0
    local integer A = 1
    local unit dummy = null
//    call DisplayTextToPlayer(Player(0), 0, 0, "start")
    call SetHandleHandle(t, "unit", u)
    call SetHandleReal(t, "h", 50)
    call SetHandleReal(t, "a", 40)
    call SetHandleReal(t, "d", 100)
    call SetHandleReal(t, "c", 1)
    
    loop
        exitwhen A > 9
        set x = GetUnitX(u) + 100 * Cos((A*40) * (3.14159/180))
        set y = GetUnitY(u) + 100 * Sin((A*40) * (3.14159/180))
        set d[A] = CreateUnit(GetOwningPlayer(u), RingUnitRawCode(), x, y, A*40)
        call SetHandleHandle(t, "dum"+I2S(A), d[A])
        set A = A + 1
    endloop
    set A = 1
    
    call TimerStart(t, 0.02, true, function Ring_Up)    
    call TriggerSleepAction(1)
    call PauseTimer(t)
    
    call TimerStart(t, 0.02, true, function Ring_Roll)
    call TriggerSleepAction(0.1)
    call PauseTimer(t)
    
    call TimerStart(t, 0.02, true, function Ring_Down)
    call TriggerSleepAction(0.1)
    set x = GetUnitX(u)
    set y = GetUnitY(u)
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", x, y))
    call PauseTimer(t)
    set dummy = CreateUnit(GetOwningPlayer(u), RingCasterDummyRawCode(), GetUnitX(u), GetUnitY(u), 0)
    call UnitApplyTimedLife(dummy, 'BTLF', 1)
    call UnitAddAbility(dummy, RingDummyAbilityRawCode())
    call SetUnitAbilityLevel(dummy, RingDummyAbilityRawCode(), GetUnitAbilityLevel(u, GetSpellAbilityId()))
    call IssueImmediateOrder(dummy, "stomp")
    set dummy = null
    loop
        exitwhen A > 9
        call KillUnit(GetHandleUnit(t, "dum"+I2S(A)))
        set A = A + 1
    endloop
    call FlushHandleLocals(t)
    call PauseTimer(t)
    call DestroyTimer(t)    
    set t = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Ring takes nothing returns nothing
    set gg_trg_Ring = CreateTrigger(  )
//    call DisableTrigger( gg_trg_Ring )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ring, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Ring, Condition( function Trig_Ring_Conditions ) )
    call TriggerAddAction( gg_trg_Ring, function Trig_Ring_Actions )
    call Preload("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl")
endfunction

Sorry that the code is pretty long.:thumbs_down:
 
Level 1
Joined
Feb 21, 2005
Messages
5
JASS:
function RingHealAmmount takes unit caster returns real
    return I2R(50*GetUnitAbilityLevel(caster,'YOUR_ABIL_RAWCODE'))
endfunction
 
Level 4
Joined
May 6, 2007
Messages
87
Purplepoot, when I do that, I get one error.

JASS:
call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE) + RingHealAmmount())
    loop
        exitwhen A > 9

The exitwhen A > 9 is saying that it has an invalid number of arguments.

Any ideas why?
 
Level 4
Joined
May 6, 2007
Messages
87
Oh, right. I fixed that and it works now. I had to set it to this, though, because it's really inaccurate (if I didn't do it this way, it would heal for like 200 a second):

JASS:
(50.*GetUnitAbilityLevel(caster,'A00Q')-25)/50

Thanks a bunch!:grin:
 
Status
Not open for further replies.
Top