• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Windslash

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
The orc are powerful creatures, so powerful, that they can kick an enemy into the air, and then while he's up there, and hit him numerous times. After he finishes with the target, he stomps very hard dealing damage.

Level 1: Hits them 6 times. Does 6.25 Damage Per Slash, and 40 Landing Damage.
Level 2: Hits them 8 times. Does 13 Damage Per Slash, Does 80 Landing Damage.
Level 3: Hits them 10 times. Does 19.5 Damage Per Slash, Does 120 Landing Damage.
Level 4: Hits them 12 times. Does 25 Damage Per Slash, does 160 Landing Damage.

Requires: Key Timers 2 [http://www.thehelper.net/forums/showthread.php/78392-Key-Timers-2]

EDIT: Heres the code.
EDIT2: Updated with Purge's information.

Updates: Made it instant, no more waiting for the Caster to get to the unit, increased time between each attack by .22 seconds.
JASS:
   scope Windslash initializer init
    //========================================================================================
    //======================================SETUP============================================
    //========================================================================================
    globals
        //The effect that's played with every attack
        private constant string EFFECT_ON_HIT = "Objects\\Spawnmodels\\Orc\\Orcblood\\BattrollBlood.mdl"
        
        //The ability code of the ability, "Wind Slash"
        private constant integer ABILITY_CODE = 'A000'
        
        //The ability code of the Crow Form ability (Should be the same unless you tampered with)
        private constant integer CROW_FORM ='Arav'
        
        //The effect attached to the weapon.
        private constant string EFFECT_ON_WEAPON = "Abilities\\Spells\\Orc\\EtherealForm\\SpiritWalkerChange.mdl"
        
        //The effect at the location of the unit being slammed (Final attack)
        private constant string FINAL_EFFECT = "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl"
        
        //Attack type for the damage
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
        
        //Damage type for the damage
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
        
        //Weapon type for the damage
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
        
        //Animation to be played while the attack goes on.
        private constant string ANIMATION_ATTACK = "attack"
        
        //Attachment point for the EFFECT_ON_HIT
        private constant string ATTACHMENT_POINT = "origin"
        
        //Attachment point for the EFFECT_ON_WEAPON effect.
        private constant string CASTER_ATTACH_POINT = "origin"
        
        //The final effect to be played on each individual unit in the final AOE
        private constant string FINAL_AOE_EFFECT = "Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl"
        private constant string FINAL_ATTACHED = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl"
        
        private group tempgroup = CreateGroup()
    endglobals
    
    private function Units takes unit u, player casterOwner returns boolean
        return (not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)) and IsUnitEnemy(u, casterOwner)
    endfunction
    
    private function NUMBER_OF_SLASHES takes integer lvl returns real
        return 4 + (lvl * 2.)
    endfunction
        
    private function HEIGHT takes integer lvl returns real
        return 200 + (lvl * 25.)
    endfunction
        
    private function DAMAGE_PER_STRIKE takes integer lvl returns real
        return (lvl * 6.25)
    endfunction
        
    private function RATE_OF_FLYING takes integer lvl returns real
        return 600 + (lvl * 0.)
    endfunction
    
    private function FINAL_SPEED takes integer lvl returns real
        return 25 + (lvl * 0.)
    endfunction
    
    private function FINAL_AOE_DAMAGE takes integer lvl returns real
        return lvl * 40.
    endfunction
    
    private function FINAL_AOE takes integer lvl returns real
        return lvl * 60.
    endfunction
        
    //========================================================================================
    //=====================================ENDSETUP=========================================
    //========================================================================================
          
    private struct slash
        unit Caster
        unit Target
        integer Tempint = 1
        effect AttachedEffect
        effect FinalEffect
        static integer structtype
    endstruct
    
    private function FinalUnits takes nothing returns boolean
        local slash s = slash.structtype
        local unit f  = GetFilterUnit()
        local real damage = FINAL_AOE_DAMAGE(GetUnitAbilityLevel(s.Caster, ABILITY_CODE))
        if GetUnitTypeId(f) != GetUnitTypeId(s.Caster) and Units(f, GetOwningPlayer(s.Caster)) then
            call SetUnitX(s.Caster, GetUnitX(f))
            call SetUnitY(s.Caster, GetUnitY(f))
            call SetUnitAnimation(s.Caster, ANIMATION_ATTACK)
            call UnitDamageTarget(s.Caster, f, damage, true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            call DestroyEffect(AddSpecialEffectTarget(FINAL_AOE_EFFECT, f, ATTACHMENT_POINT))
        endif
        set f = null
        return false
    endfunction
        
        
    private function userFunc takes nothing returns boolean
        local slash s = KT_GetData()
        local integer ability_level = GetUnitAbilityLevel(s.Caster, ABILITY_CODE)
        local real fly_height = HEIGHT(ability_level) + 12.5 * s.Tempint
        local real rate = RATE_OF_FLYING(ability_level)
        local real damage = DAMAGE_PER_STRIKE(ability_level)
        local real num_slashes = NUMBER_OF_SLASHES(ability_level)
        local real final_attack_speed = FINAL_SPEED(ability_level)
        local real radius = FINAL_AOE(ability_level)
        local real offsetx
        local real offsety
        local real coffsetx
        local real coffsety
        local real angle
        local real casterX = GetUnitX(s.Caster)
        local real casterY = GetUnitY(s.Caster)
        local real targetX = GetUnitX(s.Target)
        local real targetY = GetUnitY(s.Target)
        if s.Tempint < num_slashes and GetWidgetLife(s.Target) > .405 then
            set angle = Atan2(targetY - casterY, targetX - casterX)
            call SetUnitFlyHeight(s.Target, fly_height, rate)
            call SetUnitFlyHeight(s.Caster, fly_height, (rate * .75))
            set offsetx = targetX + 20 * Cos(angle)
            set offsety = targetY + 20 * Sin(angle)
            call SetUnitFacing(s.Caster, angle * bj_RADTODEG)
            call SetUnitAnimation(s.Caster, ANIMATION_ATTACK)
            call UnitDamageTarget(s.Caster, s.Target, damage, true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            call SetUnitX(s.Target, offsetx)
            call SetUnitY(s.Target, offsety)
            set s.Tempint = s.Tempint + 1
        elseif s.Tempint >= num_slashes or GetWidgetLife(s.Target) < .405 then
            call SetUnitFlyHeight(s.Target, 0, 1000)
            call SetUnitFlyHeight(s.Caster, 0, (rate * .75))
            set s.FinalEffect = AddSpecialEffectTarget(FINAL_ATTACHED, s.Caster, ATTACHMENT_POINT)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            call DestroyEffect(AddSpecialEffect(FINAL_EFFECT, targetX, targetY))
            set slash.structtype = s
            call GroupEnumUnitsInRange(tempgroup, targetX, targetY, radius, Filter(function FinalUnits))
            call SelectUnit(s.Caster, true)
            call DestroyEffect(s.AttachedEffect)
            call DestroyEffect(s.FinalEffect)
            call PauseUnit(s.Caster, false)
            call PauseUnit(s.Target, false)
            call SetUnitPathing(s.Caster, true)
            call SetUnitPathing(s.Target, true)
            call s.destroy()
            return true
        endif
        return false
    endfunction
        
    private function OnCast takes nothing returns boolean
        local slash s
        local real x
        local real y
        if GetSpellAbilityId() == ABILITY_CODE then
            set s = slash.create()
            set s.Caster = GetTriggerUnit()
            set s.Target = GetSpellTargetUnit()
            call ClearSelectionForPlayer(GetTriggerPlayer())
            call PauseUnit(s.Caster, true)
            call PauseUnit(s.Target, true)
            call UnitAddAbility(s.Caster, CROW_FORM)
            call UnitAddAbility(s.Target, CROW_FORM)
            call UnitRemoveAbility(s.Caster, CROW_FORM)
            call UnitRemoveAbility(s.Target, CROW_FORM)
            set s.AttachedEffect = AddSpecialEffectTarget(EFFECT_ON_WEAPON, s.Caster, CASTER_ATTACH_POINT)
            set x = GetUnitX(s.Target) + 50 * Cos(GetRandomReal(0, 360))
            set y = GetUnitY(s.Target) + 50 * Sin(GetRandomReal(0, 360))
            call SetUnitX(s.Caster, x)
            call SetUnitY(s.Caster, y)
            call SetUnitPathing(s.Caster, false)
            call SetUnitPathing(s.Target, false)
            call KT_Add(function userFunc, s, .25)
        endif
        return false
    endfunction

    //===========================================================================
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddCondition( t, Condition(function OnCast) )
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    endfunction
endscope

Keywords:
vJass, Key Timers, Key Timers 2, Key, Timers, Slash, Omnislash, Multiple Attack, Attack, melee, strike, weapon, fast, fast attack
Contents

Just another Warcraft III map (Map)

Reviews
12th Dec 2015 IcemanBo: Too long as NeedsFix. Rejected. 17:25 GMT, 1st Jun 2011 Bribe: You can shorten this from 6 lines to two lines: local real x local real y set x = GetUnitX(s.Target) + 50 * Cos(GetRandomReal(0, 360)) set y =...

Moderator

M

Moderator

12th Dec 2015
IcemanBo: Too long as NeedsFix. Rejected.

17:25 GMT, 1st Jun 2011
Bribe:

You can shorten this from 6 lines to two lines:

JASS:
local real x
local real y
set x = GetUnitX(s.Target) + 50 * Cos(GetRandomReal(0, 360))
set y = GetUnitY(s.Target) + 50 * Sin(GetRandomReal(0, 360))
call SetUnitX(s.Caster, x)
call SetUnitY(s.Caster, y)

I recommend "null" than WEAPON_TYPE_WHOKNOWS.

KT is overkill for this. In fact KT shouldn't even be used, for anything.
 
Here is my review. :)

1)
JASS:
private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction( t, function OnCast )
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    endfunction

TriggerAddAction( t, function OnCast ) should actually be TriggerAddCondition( t, Condition(function OnCast)) for you to gain the benefit of the merge. So that part would look like this:
JASS:
private function OnCast takes nothing returns boolean
        local slash s
        if GetSpellAbilityId() == ABILITY_CODE then
            set s = slash.create()
            set s.Caster = GetTriggerUnit()
            set s.Target = GetSpellTargetUnit()
            call ClearSelectionForPlayer(GetOwningPlayer(GetTriggerUnit()))
            call PauseUnit(s.Caster, true)
            call PauseUnit(s.Target, true)
            set s.AttachedEffect = AddSpecialEffectTarget(EFFECT_ON_WEAPON, s.Caster, CASTER_ATTACH_POINT)
            call KT_Add(function userFunc, s, .03)
        endif
        return false
    endfunction

    //===========================================================================
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddCondition( t, Condition(function OnCast) )
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    endfunction

2) call ClearSelectionForPlayer(GetOwningPlayer(GetTriggerUnit()))
That can be reduced down to:
call ClearSelectionForPlayer(GetTriggerPlayer())

3)
JASS:
        local real fly_height = HEIGHT(GetUnitAbilityLevel(s.Caster, ABILITY_CODE))
        local real rate = RATE_OF_FLYING(GetUnitAbilityLevel(s.Caster, ABILITY_CODE))
        local real damage = DAMAGE_PER_STRIKE(GetUnitAbilityLevel(s.Caster, ABILITY_CODE))
        local real num_slashes = NUMBER_OF_SLASHES(GetUnitAbilityLevel(s.Caster, ABILITY_CODE))
        local real final_attack_speed = FINAL_SPEED(GetUnitAbilityLevel(s.Caster, ABILITY_CODE))
        local real radius = FINAL_AOE(GetUnitAbilityLevel(s.Caster, ABILITY_CODE))

GetUnitAbilityLevel(s.Caster, ABILITY_CODE) should be saved to a variable before used, otherwise it is retrieved separately for each declaration. So it would look like this:

JASS:
        local integer ability_level = GetUnitAbilityLevel(s.Caster, ABILITY_CODE)
        local real fly_height = HEIGHT(ability_level)
        local real rate = RATE_OF_FLYING(ability_level)
        local real damage = DAMAGE_PER_STRIKE(ability_level)
        local real num_slashes = NUMBER_OF_SLASHES(ability_level)
        local real final_attack_speed = FINAL_SPEED(ability_level)
        local real radius = FINAL_AOE(ability_level)

4) The variable tempreal doesn't seem to have a use:
JASS:
set tempreal = SquareRoot(dx * dx + dy * dy)
        set dist_to_go = tempreal

Just set dist_to_go to the distance instead:
set dist_to_go = SquareRoot(dx * dx + dy * dy)

5) Instead of adding and removing the storm crow ability each time, just add it once when the spell is cast:
JASS:
    private function OnCast takes nothing returns boolean
        local slash s
        if GetSpellAbilityId() == ABILITY_CODE then
            set s = slash.create()
            set s.Caster = GetTriggerUnit()
            set s.Target = GetSpellTargetUnit()
            call ClearSelectionForPlayer(GetOwningPlayer(GetTriggerUnit()))
            call PauseUnit(s.Caster, true)
            call PauseUnit(s.Target, true)
            call UnitAddAbility(s.Caster, CROW_FORM)
            call UnitAddAbility(s.Target, CROW_FORM)
            call UnitRemoveAbility(s.Caster, CROW_FORM)
            call UnitRemoveAbility(s.Target, CROW_FORM)
            set s.AttachedEffect = AddSpecialEffectTarget(EFFECT_ON_WEAPON, s.Caster, CASTER_ATTACH_POINT)
            call KT_Add(function userFunc, s, .03)
        endif
        return false
    endfunction

Then you can remove it from the instances where you use it in the periodic.
JASS:
        if cond and s.Tempint < num_slashes and GetWidgetLife(s.Target) > .405 then
            set angle = bj_RADTODEG * Atan2(s.TargetY - s.CasterY, s.TargetX - s.CasterX)
            //I removed the unitaddability/unitremoveability from here
            call SetUnitFlyHeight(s.Target, fly_height + 50 * s.Tempint, rate)
            call SetUnitFlyHeight(s.Caster, fly_height + 50 * s.Tempint, (rate * .75))

6) s.CasterX, s.CasterY, s.TargetX, and s.TargetY do not need to be struct members. They can just be normal local variables:
JASS:
private struct slash
        unit Caster
        unit Target
        integer Tempint = 1
        effect AttachedEffect
        effect FinalEffect
        static integer structtype
    endstruct

And then in the periodic:
JASS:
private function userFunc takes nothing returns boolean
        local slash s = KT_GetData()
        local real dist_to_go
        local boolean cond
        local real dx
        local real dy
        local integer ability_level = GetUnitAbilityLevel(s.Caster, ABILITY_CODE)
        local real fly_height = HEIGHT(ability_level)
        local real rate = RATE_OF_FLYING(ability_level)
        local real damage = DAMAGE_PER_STRIKE(ability_level)
        local real num_slashes = NUMBER_OF_SLASHES(ability_level)
        local real final_attack_speed = FINAL_SPEED(ability_level)
        local real radius = FINAL_AOE(ability_level)
        local real offsetx
        local real offsety
        local real coffsetx
        local real coffsety
        local real angle
        local group tempgroup
        
        local real casterX = GetUnitX(s.Caster)
        local real casterY = GetUnitY(s.Caster)
        local real targetX = GetUnitX(s.Target)
        local real targetY = GetUnitY(s.Target)
        set dx = targetX - casterX
        set dy = targetY - casterY
        set tempreal = SquareRoot(dx * dx + dy * dy)
        set dist_to_go = tempreal
        set cond = (dist_to_go <= 100)
        if cond and s.Tempint < num_slashes and GetWidgetLife(s.Target) > .405 then
            set angle = bj_RADTODEG * Atan2(targetY - casterY, targetX - casterX)
            call SetUnitFlyHeight(s.Target, fly_height + 50 * s.Tempint, rate)
            call SetUnitFlyHeight(s.Caster, fly_height + 50 * s.Tempint, (rate * .75))
            set offsetx = targetX + 20 * Cos(angle * bj_DEGTORAD)
            set offsety = targetY + 20 * Sin(angle * bj_DEGTORAD)
            call SetUnitFacing(s.Caster, angle)
            call SetUnitAnimation(s.Caster, ANIMATION_ATTACK)
            call UnitDamageTarget(s.Caster, s.Target, damage, true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            call SetUnitX(s.Target, offsetx)
            call SetUnitY(s.Target, offsety)
            set s.Tempint = s.Tempint + 1
        elseif dist_to_go > 100 then
            set angle = bj_RADTODEG * Atan2(targetY - casterY, targetX - casterX)
            set casterX = GetUnitX(s.Caster)
            set casterY = GetUnitY(s.Caster)
            set coffsetx = casterX + 20 * Cos(angle * bj_DEGTORAD)
            set coffsety = casterY + 20 * Sin(angle * bj_DEGTORAD)
            call SetUnitFacing(s.Caster, angle)
            call SetUnitX(s.Caster, coffsetx)
            call SetUnitY(s.Caster, coffsety)
        elseif s.Tempint >= 12 or GetWidgetLife(s.Target) < .405 then
            call SetUnitFlyHeight(s.Target, 0, 1000)
            call SetUnitFlyHeight(s.Caster, 0, (rate * .75))
            set s.FinalEffect = AddSpecialEffectTarget(FINAL_ATTACHED, s.Caster, ATTACHMENT_POINT)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            set targetX = GetUnitX(s.Target)
            set targetY = GetUnitY(s.Target)
            set tempgroup = CreateGroup()
            call DestroyEffect(AddSpecialEffect(FINAL_EFFECT, targetX, targetY))
            set tempgroup = GetUnitsInRangeOfLocMatching(radius, Location(targetX, targetY), Filter(function Units))
            set slash.structtype = s
            call ForGroup(tempgroup, function FinalUnits)
            call DestroyBoolExpr(Filter(function Units))
            call DestroyGroup(tempgroup)
            call SelectUnit(s.Caster, true)
            call DestroyEffect(s.AttachedEffect)
            call DestroyEffect(s.FinalEffect)
            call PauseUnit(s.Caster, false)
            call PauseUnit(s.Target, false)
            call s.destroy()
            return true
        endif
        return false
    endfunction

7) Since you already calculate dy and dx, your angle calculations can be simplified. Also, you can leave it in radians, and instead convert it to deg for SetUnitFacing:
JASS:
if cond and s.Tempint < num_slashes and GetWidgetLife(s.Target) > .405 then
            set angle = bj_RADTODEG * Atan2(dy, dx)
            call SetUnitFlyHeight(s.Target, fly_height + 50 * s.Tempint, rate)
            call SetUnitFlyHeight(s.Caster, fly_height + 50 * s.Tempint, (rate * .75))
            set offsetx = targetX + 20 * Cos(angle)
            set offsety = targetY + 20 * Sin(angle)
            call SetUnitFacing(s.Caster, angle * bj_RADTODEG)
            call SetUnitAnimation(s.Caster, ANIMATION_ATTACK)
            call UnitDamageTarget(s.Caster, s.Target, damage, true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            call SetUnitX(s.Target, offsetx)
            call SetUnitY(s.Target, offsety)
            set s.Tempint = s.Tempint + 1
        elseif dist_to_go > 100 then
            set angle = Atan2(dy, dx)
            set casterX = GetUnitX(s.Caster)
            set casterY = GetUnitY(s.Caster)
            set coffsetx = casterX + 20 * Cos(angle)
            set coffsety = casterY + 20 * Sin(angle)
            call SetUnitFacing(s.Caster, angle * bj_RADTODEG)
            call SetUnitX(s.Caster, coffsetx)
            call SetUnitY(s.Caster, coffsety)

That way, you can use it just as Cos(angle)/Sin(angle) instead of Cos(angle*bj_DEGTORAD) and Sin(angle*bj_DEGTORAD).

8) Replace fly_height's declaration to fly_height + 50 * s.Tempint. That way, you can just use the input fly_height for setting the unit's fly height.
local real fly_height = HEIGHT(ability_level) + 50 * s.Tempint
And then:
JASS:
call SetUnitFlyHeight(s.Target, fly_height, rate)
            call SetUnitFlyHeight(s.Caster, fly_height, (rate * .75))

9) In this:
JASS:
        elseif dist_to_go > 100 then
            set angle = Atan2(dy, dx)
            set casterX = GetUnitX(s.Caster)
            set casterY = GetUnitY(s.Caster)
casterX and casterY are already set to the X/Y of the caster, so you can just remove that.

Right here as well:
JASS:
            set s.FinalEffect = AddSpecialEffectTarget(FINAL_ATTACHED, s.Caster, ATTACHMENT_POINT)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            set targetX = GetUnitX(s.Target)
            set targetY = GetUnitY(s.Target)

You can remove targetX and targetY since it is already removed before the if-block.

9) GetUnitsInRangeOfLoc creates a new group, so you are leaking a bit. Also, Location(x,y) returns a new location, so that is another leak. Instead, use one global group and just use GroupEnumUnitsInRange.
JASS:
private constant string FINAL_ATTACHED = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl"
        
        private group tempgroup = CreateGroup() //add this
    endglobals

And then fix the code accordingly:
JASS:
call DestroyEffect(AddSpecialEffect(FINAL_EFFECT, targetX, targetY))
            call GroupEnumUnitsInRange(tempgroup, targetX, targetY, radius, Filter(function Units))
            set slash.structtype = s

And that is all you need to do. Remove the "tempgroup" local declaration as well, otherwise that might bring up syntax errors.

10) Your filter doesn't make sense. lol. :ogre_haosis:
JASS:
return IsUnitType(f, UNIT_TYPE_MAGIC_IMMUNE) == false and GetOwningPlayer(GetFilterUnit()) != GetFilterUnit()

You can't compare a player to a unit. Also, you should use IsUnitEnemy instead, because otherwise it will not take into consideration allies and neutral units. The group also doesn't need a ForGroup(), DestroyGroup(), or DestroyBoolexpr(). You can use filter enumeration, as described in this thread:
http://www.thehelper.net/forums/showthread.php/138374-How-to-use-Groups-without-leaking

You can actually change Units() to take a unit and return a boolean, (so it could still be easily modified) and then just handle the enumeration stuff inside final units. So your code would look something like:
JASS:
scope Windslash initializer init
    //========================================================================================
    //======================================SETUP============================================
    //========================================================================================
    globals
        //The effect that's played with every attack
        private constant string EFFECT_ON_HIT = "Objects\\Spawnmodels\\Orc\\Orcblood\\BattrollBlood.mdl"
        //The ability code of the ability, "Wind Slash"
        private constant integer ABILITY_CODE = 'A000'
        //The ability code of the Crow Form ability (Should be the same unless you tampered with)
        private constant integer CROW_FORM ='Arav'
        //The effect attached to the weapon.
        private constant string EFFECT_ON_WEAPON = "Abilities\\Spells\\Orc\\EtherealForm\\SpiritWalkerChange.mdl"
        //The effect at the location of the unit being slammed (Final attack)
        private constant string FINAL_EFFECT = "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl"
        //Attack type for the damage
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
        //Damage type for the damage
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
        //Weapon type for the damage
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
        //Animation to be played while the attack goes on.
        private constant string ANIMATION_ATTACK = "attack"
        //Attachment point for the EFFECT_ON_HIT
        private constant string ATTACHMENT_POINT = "origin"
        //Attachment point for the EFFECT_ON_WEAPON effect.
        private constant string CASTER_ATTACH_POINT = "origin"
        //The final effect to be played on each individual unit in the final AOE
        private constant string FINAL_AOE_EFFECT = "Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl"
        private constant string FINAL_ATTACHED = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl"
        
        private group tempgroup = CreateGroup()
    endglobals
    
    private function Units takes unit u, player casterOwner returns boolean
        return (not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)) and IsUnitEnemy(u, casterOwner)
    endfunction
    
    private function NUMBER_OF_SLASHES takes integer lvl returns real
        return 4 + (lvl * 2.)
    endfunction
        
    private function HEIGHT takes integer lvl returns real
        return 200 + (lvl * 100.)
    endfunction
        
    private function DAMAGE_PER_STRIKE takes integer lvl returns real
        return (lvl * 6.25)
    endfunction
        
    private function RATE_OF_FLYING takes integer lvl returns real
        return 600 + (lvl * 0.)
    endfunction
    
    private function FINAL_SPEED takes integer lvl returns real
        return 25 + (lvl * 0.)
    endfunction
    
    private function FINAL_AOE_DAMAGE takes integer lvl returns real
        return lvl * 40.
    endfunction
    
    private function FINAL_AOE takes integer lvl returns real
        return lvl * 60.
    endfunction
        
    //========================================================================================
    //=====================================ENDSETUP=========================================
    //========================================================================================
        
    private struct slash
        unit Caster
        unit Target
        integer Tempint = 1
        effect AttachedEffect
        effect FinalEffect
        static integer structtype
    endstruct
    
    private function FinalUnits takes nothing returns boolean
        local slash s = slash.structtype
        local unit f  = GetFilterUnit()
        if GetUnitTypeId(f) != GetUnitTypeId(s.Caster) and Units(f, GetOwningPlayer(s.Caster)) then
            call SetUnitX(s.Caster, GetUnitX(f))
            call SetUnitY(s.Caster, GetUnitY(f))
            call SetUnitAnimation(s.Caster, ANIMATION_ATTACK)
            call UnitDamageTarget(s.Caster, f, FINAL_AOE_DAMAGE(GetUnitAbilityLevel(f, GetOwningPlayer(s.Caster)), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            call DestroyEffect(AddSpecialEffectTarget(FINAL_AOE_EFFECT, f, ATTACHMENT_POINT))
        endif
        set f = null
        return false
    endfunction
        
        
    private function userFunc takes nothing returns boolean
        local slash s = KT_GetData()
        local real dist_to_go
        local boolean cond
        local real dx
        local real dy
        local integer ability_level = GetUnitAbilityLevel(s.Caster, ABILITY_CODE)
        local real fly_height = HEIGHT(ability_level) + 50 * s.Tempint
        local real rate = RATE_OF_FLYING(ability_level)
        local real damage = DAMAGE_PER_STRIKE(ability_level)
        local real num_slashes = NUMBER_OF_SLASHES(ability_level)
        local real final_attack_speed = FINAL_SPEED(ability_level)
        local real radius = FINAL_AOE(ability_level)
        local real offsetx
        local real offsety
        local real coffsetx
        local real coffsety
        local real angle
        
        local real casterX = GetUnitX(s.Caster)
        local real casterY = GetUnitY(s.Caster)
        local real targetX = GetUnitX(s.Target)
        local real targetY = GetUnitY(s.Target)
        set dx = targetX - casterX
        set dy = targetY - casterY 
        set dist_to_go = SquareRoot(dx * dx + dy * dy)
        set cond = (dist_to_go <= 100)
        if cond and s.Tempint < num_slashes and GetWidgetLife(s.Target) > .405 then
            set angle = Atan2(dy, dx)
            call SetUnitFlyHeight(s.Target, fly_height, rate)
            call SetUnitFlyHeight(s.Caster, fly_height, (rate * .75))
            set offsetx = targetX + 20 * Cos(angle)
            set offsety = targetY + 20 * Sin(angle)
            call SetUnitFacing(s.Caster, angle * bj_RADTODEG)
            call SetUnitAnimation(s.Caster, ANIMATION_ATTACK)
            call UnitDamageTarget(s.Caster, s.Target, damage, true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            call SetUnitX(s.Target, offsetx)
            call SetUnitY(s.Target, offsety)
            set s.Tempint = s.Tempint + 1
        elseif dist_to_go > 100 then
            set angle = Atan2(dy, dx)
            set coffsetx = casterX + 20 * Cos(angle)
            set coffsety = casterY + 20 * Sin(angle)
            call SetUnitFacing(s.Caster, angle * bj_RADTODEG)
            call SetUnitX(s.Caster, coffsetx)
            call SetUnitY(s.Caster, coffsety)
        elseif s.Tempint >= 12 or GetWidgetLife(s.Target) < .405 then
            call SetUnitFlyHeight(s.Target, 0, 1000)
            call SetUnitFlyHeight(s.Caster, 0, (rate * .75))
            set s.FinalEffect = AddSpecialEffectTarget(FINAL_ATTACHED, s.Caster, ATTACHMENT_POINT)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            call DestroyEffect(AddSpecialEffect(FINAL_EFFECT, targetX, targetY))
            set slash.structtype = s
            call GroupEnumUnitsInRange(tempgroup, targetX, targetY, radius, Filter(function FinalUnits))
            call SelectUnit(s.Caster, true)
            call DestroyEffect(s.AttachedEffect)
            call DestroyEffect(s.FinalEffect)
            call PauseUnit(s.Caster, false)
            call PauseUnit(s.Target, false)
            call s.destroy()
            return true
        endif
        return false
    endfunction
        
    private function OnCast takes nothing returns boolean
        local slash s
        if GetSpellAbilityId() == ABILITY_CODE then
            set s = slash.create()
            set s.Caster = GetTriggerUnit()
            set s.Target = GetSpellTargetUnit()
            call ClearSelectionForPlayer(GetTriggerPlayer())
            call PauseUnit(s.Caster, true)
            call PauseUnit(s.Target, true)
            call UnitAddAbility(s.Caster, CROW_FORM)
            call UnitAddAbility(s.Target, CROW_FORM)
            call UnitRemoveAbility(s.Caster, CROW_FORM)
            call UnitRemoveAbility(s.Target, CROW_FORM)
            set s.AttachedEffect = AddSpecialEffectTarget(EFFECT_ON_WEAPON, s.Caster, CASTER_ATTACH_POINT)
            call KT_Add(function userFunc, s, .03)
        endif
        return false
    endfunction

    //===========================================================================
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddCondition( t, Condition(function OnCast) )
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    endfunction
endscope

11) s.FinalEffect is destroyed immediately. Thus, you can just remove that member and destroy it as you create it.

12) offsetx, offsety, coffsetx, and coffsety can be inlined. You can also inline cond.

13) If dist_to_go >= 100, and dist_to_go = SquareRoot(dx*dx+dy*dy), then that means that dist_to_go*dist_to_go >= 100*100. dist_to_go*dist_to_go = dx*dx+dy*dy, it is essentially removes the square root. So you would instead compare that:
JASS:
set dist_to_go = dx * dx + dy * dy
if dist_to_go >= 10000 then //10000 = 100 * 100

--------------
After final, little optimizations, it should look like this:
JASS:
scope Windslash initializer init
    //========================================================================================
    //======================================SETUP============================================
    //========================================================================================
    globals
        //The effect that's played with every attack
        private constant string EFFECT_ON_HIT = "Objects\\Spawnmodels\\Orc\\Orcblood\\BattrollBlood.mdl"
        //The ability code of the ability, "Wind Slash"
        private constant integer ABILITY_CODE = 'A000'
        //The ability code of the Crow Form ability (Should be the same unless you tampered with)
        private constant integer CROW_FORM ='Arav'
        //The effect attached to the weapon.
        private constant string EFFECT_ON_WEAPON = "Abilities\\Spells\\Orc\\EtherealForm\\SpiritWalkerChange.mdl"
        //The effect at the location of the unit being slammed (Final attack)
        private constant string FINAL_EFFECT = "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl"
        //Attack type for the damage
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
        //Damage type for the damage
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
        //Weapon type for the damage
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
        //Animation to be played while the attack goes on.
        private constant string ANIMATION_ATTACK = "attack"
        //Attachment point for the EFFECT_ON_HIT
        private constant string ATTACHMENT_POINT = "origin"
        //Attachment point for the EFFECT_ON_WEAPON effect.
        private constant string CASTER_ATTACH_POINT = "origin"
        //The final effect to be played on each individual unit in the final AOE
        private constant string FINAL_AOE_EFFECT = "Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl"
        private constant string FINAL_ATTACHED = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl"
        
        private group tempgroup = CreateGroup()
    endglobals
    
    private function Units takes unit u, player casterOwner returns boolean
        return (not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)) and IsUnitEnemy(u, casterOwner)
    endfunction
    
    private function NUMBER_OF_SLASHES takes integer lvl returns real
        return 4 + (lvl * 2.)
    endfunction
        
    private function HEIGHT takes integer lvl returns real
        return 200 + (lvl * 100.)
    endfunction
        
    private function DAMAGE_PER_STRIKE takes integer lvl returns real
        return (lvl * 6.25)
    endfunction
        
    private function RATE_OF_FLYING takes integer lvl returns real
        return 600 + (lvl * 0.)
    endfunction
    
    private function FINAL_SPEED takes integer lvl returns real
        return 25 + (lvl * 0.)
    endfunction
    
    private function FINAL_AOE_DAMAGE takes integer lvl returns real
        return lvl * 40.
    endfunction
    
    private function FINAL_AOE takes integer lvl returns real
        return lvl * 60.
    endfunction
        
    //========================================================================================
    //=====================================ENDSETUP=========================================
    //========================================================================================
        
    private struct slash
        unit Caster
        unit Target
        integer Tempint = 1
        effect AttachedEffect
        static integer structtype
    endstruct
    
    private function FinalUnits takes nothing returns boolean
        local slash s = slash.structtype
        local unit f  = GetFilterUnit()
        local player p = GetOwningPlayer(s.Caster)
        if GetUnitTypeId(f) != GetUnitTypeId(s.Caster) and Units(f, p) then
            call SetUnitX(s.Caster, GetUnitX(f))
            call SetUnitY(s.Caster, GetUnitY(f))
            call SetUnitAnimation(s.Caster, ANIMATION_ATTACK)
            call UnitDamageTarget(s.Caster, f, FINAL_AOE_DAMAGE(GetUnitAbilityLevel(f, p), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            call DestroyEffect(AddSpecialEffectTarget(FINAL_AOE_EFFECT, f, ATTACHMENT_POINT))
        endif
        set f = null
        return false
    endfunction
        
        
    private function userFunc takes nothing returns boolean
        local slash s = KT_GetData()
        local real dist_to_go
        local real dx
        local real dy
        local integer ability_level = GetUnitAbilityLevel(s.Caster, ABILITY_CODE)
        local real fly_height = HEIGHT(ability_level) + 50 * s.Tempint
        local real rate = RATE_OF_FLYING(ability_level)
        local real damage = DAMAGE_PER_STRIKE(ability_level)
        local real num_slashes = NUMBER_OF_SLASHES(ability_level)
        local real final_attack_speed = FINAL_SPEED(ability_level)
        local real radius = FINAL_AOE(ability_level)
        local real angle
        
        local real casterX = GetUnitX(s.Caster)
        local real casterY = GetUnitY(s.Caster)
        local real targetX = GetUnitX(s.Target)
        local real targetY = GetUnitY(s.Target)
        set dx = targetX - casterX
        set dy = targetY - casterY
        set dist_to_go = dx * dx + dy * dy
        if (dist_to_go <= 10000) and s.Tempint < num_slashes and GetWidgetLife(s.Target) > .405 then
            set angle = Atan2(dy, dx)
            call SetUnitFlyHeight(s.Target, fly_height, rate)
            call SetUnitFlyHeight(s.Caster, fly_height, (rate * .75))
            call SetUnitFacing(s.Caster, angle * bj_RADTODEG)
            call SetUnitAnimation(s.Caster, ANIMATION_ATTACK)
            call UnitDamageTarget(s.Caster, s.Target, damage, true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            call SetUnitX(s.Target, targetX + 20 * Cos(angle))
            call SetUnitY(s.Target, targetY + 20 * Sin(angle))
            set s.Tempint = s.Tempint + 1
        elseif dist_to_go > 10000 then
            set angle = Atan2(dy, dx)
            call SetUnitFacing(s.Caster, angle * bj_RADTODEG)
            call SetUnitX(s.Caster, casterX + 20 * Cos(angle))
            call SetUnitY(s.Caster, casterY + 20 * Sin(angle))
        elseif s.Tempint >= 12 or GetWidgetLife(s.Target) < .405 then
            call SetUnitFlyHeight(s.Target, 0, 1000)
            call SetUnitFlyHeight(s.Caster, 0, (rate * .75))
            call DestroyEffect(AddSpecialEffectTarget(FINAL_ATTACHED, s.Caster, ATTACHMENT_POINT))
            call DestroyEffect(AddSpecialEffectTarget(EFFECT_ON_HIT, s.Target, ATTACHMENT_POINT))
            call DestroyEffect(AddSpecialEffect(FINAL_EFFECT, targetX, targetY))
            set slash.structtype = s
            call GroupEnumUnitsInRange(tempgroup, targetX, targetY, radius, Filter(function FinalUnits))
            call SelectUnit(s.Caster, true)
            call DestroyEffect(s.AttachedEffect)
            call PauseUnit(s.Caster, false)
            call PauseUnit(s.Target, false)
            call s.destroy()
            return true
        endif
        return false
    endfunction
        
    private function OnCast takes nothing returns boolean
        local slash s
        if GetSpellAbilityId() == ABILITY_CODE then
            set s = slash.create()
            set s.Caster = GetTriggerUnit()
            set s.Target = GetSpellTargetUnit()
            if GetLocalPlayer() == GetTriggerPlayer() then
                call ClearSelection()
            endif
            call PauseUnit(s.Caster, true)
            call PauseUnit(s.Target, true)
            call UnitAddAbility(s.Caster, CROW_FORM)
            call UnitAddAbility(s.Target, CROW_FORM)
            call UnitRemoveAbility(s.Caster, CROW_FORM)
            call UnitRemoveAbility(s.Target, CROW_FORM)
            set s.AttachedEffect = AddSpecialEffectTarget(EFFECT_ON_WEAPON, s.Caster, CASTER_ATTACH_POINT)
            call KT_Add(function userFunc, s, .03)
        endif
        return false
    endfunction

    //===========================================================================
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddCondition( t, Condition(function OnCast) )
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    endfunction
endscope

It should work, but I have not tested it, nor have I tested if it even compiles. xD Hopefully it will work, though. Anyway, nice job on the spell. :ogre_haosis:


Final suggestion: You may want to look into T32 for this instead of KT, because T32 covers around the area of your interval. (It has a period of 0.03125)

EDIT: I put it in hidden tags now. xD
 
Last edited:
private group tempgroup = CreateGroup()

bj_lastCreatedGroup is fine, use that instead of creating your own global group.

JASS:
        //The effect that's played with every attack
        private constant string EFFECT_ON_HIT = "Objects\\Spawnmodels\\Orc\\Orcblood\\BattrollBlood.mdl"
        
        //The ability code of the ability, "Wind Slash"
        private constant integer ABILITY_CODE = 'A000'
        
        //The ability code of the Crow Form ability (Should be the same unless you tampered with)
        private constant integer CROW_FORM ='Arav'
        
        //The effect attached to the weapon.
        private constant string EFFECT_ON_WEAPON = "Abilities\\Spells\\Orc\\EtherealForm\\SpiritWalkerChange.mdl"
        
        //The effect at the location of the unit being slammed (Final attack)
        private constant string FINAL_EFFECT = "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl"
        
        //Attack type for the damage
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
        
        //Damage type for the damage
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
        
        //Weapon type for the damage
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
        
        //Animation to be played while the attack goes on.
        private constant string ANIMATION_ATTACK = "attack"
        
        //Attachment point for the EFFECT_ON_HIT
        private constant string ATTACHMENT_POINT = "origin"
        
        //Attachment point for the EFFECT_ON_WEAPON effect.
        private constant string CASTER_ATTACH_POINT = "origin"
        
        //The final effect to be played on each individual unit in the final AOE
        private constant string FINAL_AOE_EFFECT = "Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl"
        private constant string FINAL_ATTACHED = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl"

Much more readable with some good line spacing.

This should also run on Timer32, not KeyTimers2.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
good spell but is this suppose to be in the OnCast?...
JASS:
set ability_level = GetUnitAbilityLevel(s.Caster, ABILITY_CODE)
set fly_height = HEIGHT(ability_level)
set rate = RATE_OF_FLYING(ability_level)
set damage = DAMAGE_PER_STRIKE(ability_level)
set num_slashes = NUMBER_OF_SLASHES(ability_level)
set final_attack_speed = FINAL_SPEED(ability_level)
set radius = FINAL_AOE(ability_level)
 
Top