HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

My First Jass spells

06-04-2006, 04:27 AM#1
Do0mBringer
I was wondering is someone could perhaps glance over these and tell me if there are any leaks, or give me some tips and suggestions to get better at coding jass and all that.

Collapse JASS:
function Sacrifice_Filter takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetFilterUnit())) and GetWidgetLife(GetFilterUnit()) > 0.405
endfunction

function Sacrifice_CopyGroup takes group g returns group
    set bj_groupAddGroupDest = CreateGroup()
    call ForGroup(g, function GroupAddGroupEnum)
    return bj_groupAddGroupDest
endfunction

function Sacrifice_Move takes nothing returns nothing
    local string s = I2S(H2I(GetExpiredTimer()))
    local gamecache gc = udg_AbilityCache
    local real x = GetStoredReal(gc, s, "x")
    local real y = GetStoredReal(gc, s, "y")
    local integer i = GetStoredInteger(gc, s, "level")
    local group g = Sacrifice_CopyGroup(I2G(GetStoredInteger(gc, s, "effects")))
    local real dur = GetStoredReal(gc, s, "dur")+.1
    local real ux
    local real uy
    local  unit f
    local real fx = GetStoredReal(gc, s, "fx")+0.05
    if dur < 1+0.5*i then
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            set ux = GetUnitX(f)
            set uy = GetUnitY(f)
            call SetUnitPosition(f, ux+15*Cos(Deg2Rad(GetUnitFacing(f))), uy+15*Sin(Deg2Rad(GetUnitFacing(f))))
            call GroupRemoveUnit(g, f)
        endloop
        call StoreReal(gc, s, "dur", dur)
        call StoreReal(gc, s, "fx", fx)
    else
        loop
            set f = FirstOfGroup(g)
            exitwhen f == null
            call GroupRemoveUnit(g, f)
            call RemoveUnit(f)
        endloop
        call DestroyGroup(I2G(GetStoredInteger(gc, s, "effects")))
        call FlushStoredMission(gc, s)
        call DestroyTimer(GetExpiredTimer())
    endif
    set gc = null
    call DestroyGroup(g)
    set g = null
    set f = null
endfunction

function Trig_sacrifice1_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local real x = GetUnitX(target)
    local real y = GetUnitY(target)
    local integer i = GetUnitAbilityLevel(caster, Sacrifice_SpellId())
    local boolexpr b = Condition(function Stomp_Filter)
    local group g = CreateGroup()
    local group damages = CreateGroup()
    local unit f
    local gamecache gc = udg_AbilityCache
    local timer t = CreateTimer()
    local string s = I2S(H2I(t))
    local integer j = -1
    local real life
    local real target_life
    set target_life = GetUnitState(target,UNIT_STATE_LIFE)*1
    set life = GetUnitState(caster,UNIT_STATE_LIFE)    
    call SetUnitState(caster,UNIT_STATE_LIFE,life+target_life)
    call ExplodeUnitBJ(target)
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", x, y))
    call GroupEnumUnitsInRange(damages, x, y, 100+50*i, b)
    loop
        set j = j+1
        exitwhen j > 24
        call GroupAddUnit(g,CreateUnit(Player(12),'e001',x,y,j*(360/25)))
    endloop
    loop
        set f = FirstOfGroup(damages)
        exitwhen f == null
        set target_life = GetUnitState(f,UNIT_STATE_LIFE)*0.1
        set life = GetUnitState(caster,UNIT_STATE_LIFE)
        call SetUnitState(caster,UNIT_STATE_LIFE,life+target_life)
        call UnitDamageTarget(caster, f, 25*i, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, null)
        call GroupRemoveUnit(damages, f)
    endloop
    call StoreInteger(gc, s, "level", i)
    call StoreInteger(gc, s, "effects", H2I(g))
    call StoreReal(gc, s, "x", x)
    call StoreReal(gc, s, "y", y)
    call StoreReal(gc,s,"dur",0)
    call TimerStart(t, 0.05, true, function Sacrifice_Move)
    set caster = null
    set target = null
    call DestroyBoolExpr(b)
    set b = null
    set g = null
    call DestroyGroup(damages)
    set damages = null
    set f = null
    set gc = null
    set t = null
endfunction

and

Collapse JASS:
function IsInvuln takes unit u returns real
    local real hp = GetWidgetLife(u)
    local real r

    set r = hp
    call UnitDamageTarget(u,u,0.01,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNIVERSAL,null)
    set r= (r-GetWidgetLife(u))*100
    call SetWidgetLife(u,hp)
    return r
endfunction

function Trig_ControlCorpse_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'AHre'
endfunction

function ControlCorpse_Filter takes nothing returns boolean
    return IsInvuln(GetFilterUnit())==0
endfunction

function Trig_ControlCorpse_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    //local integer i = GetUnitAbilityLevel(caster, ControlCorpse_SpellId())
    local boolexpr b = Condition(function ControlCorpse_Filter)
    local group g = CreateGroup()
    local unit f
    local integer j = -1
    call GroupEnumUnitsInRange(g, x, y, 900, b)
    loop
        set f = FirstOfGroup(g)
        exitwhen f == null
        call SetUnitOwner(f,GetOwningPlayer(caster),true)
        call SetUnitInvulnerable(f,false)
        call GroupRemoveUnit(g, f)
    endloop
    set caster = null
    call DestroyBoolExpr(b)
    set b = null
    call DestroyGroup(g)
    set g = null
    set f = null
endfunction
06-04-2006, 08:14 AM#2
Captain Griffen
Can't see anything there at a first glace, except ExplodeUnitBJ, which can be replaced with:

Collapse JASS:
    call SetUnitExploded(whichUnit, true)
    call KillUnit(whichUnit)