Omnislash Ending before all slashes are done

killingdyl

Active Member
Reaction score
6
Ok so im making an omnislash ability but i cant seem to figure out how to make the whole spell stop when there arent any units in range. heres my code. Please dont point out leaks, the code is unfinished and i dont remove leaks til im done.

JASS:
function Trig_Omnislash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00C'  
endfunction

function Trig_Omnislash_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local player p = GetOwningPlayer(caster)
    local real x
    local real y
    local real angle
    local integer random
    local integer Loop = GetUnitAbilityLevel(caster, 'A00C')*10
    local integer i = 1
    local group g = CreateGroup()
    local unit fog
    local effect fx = AddSpecialEffectTarget("Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl", caster, "weapon")
    call SetUnitVertexColor(caster, 255, 255, 255, 125)
    loop
        exitwhen i > Loop
        set angle = GetRandomInt(0, 35) * 10 + GetRandomInt(0, 18) * 10
        call SetUnitFacing(caster, angle-180)
        set x = GetUnitX(target) + 50 * Cos(angle * bj_DEGTORAD)
        set y = GetUnitY(target) + 50 * Sin(angle * bj_DEGTORAD)
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl", x, y))
        call SetUnitX(caster, x)
        call SetUnitY(caster, y)
        call GroupEnumUnitsInRange(g, x, y, 600, null)
        loop
            set fog = GroupPickRandomUnit(g)
            exitwhen fog == null
            if (IsUnitAlly(fog, p) == false) and (IsUnitType(fog, UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(fog, UNIT_TYPE_STRUCTURE) == false) and not(GetUnitState(fog, UNIT_STATE_LIFE) <=0) then
                set target = fog
                set fog = null
                loop
                    set fog = FirstOfGroup(g)
                    exitwhen fog == null
                    call GroupRemoveUnit(g, fog)
                endloop
            else
                call GroupRemoveUnit(g, fog)
            endif
        endloop
        set i = i + 1
        call SetUnitAnimationByIndex(caster, 2)
        call TriggerSleepAction(0.40)
    endloop
endfunction

//===========================================================================
function InitTrig_Omnislash takes nothing returns nothing
    local trigger Omnislash = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Omnislash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( Omnislash, Condition( function Trig_Omnislash_Conditions ) )
    call TriggerAddAction( Omnislash, function Trig_Omnislash_Actions )
endfunction
 

Bribe

vJass errors are legion
Reaction score
67
Maybe this helps you get started:

JASS:
function Trig_Omnislash_Filter takes nothing returns boolean
    local unit fog = GetFilterUnit()
    if bj_groupRandomConsidered >= 0 and IsUnitEnemy(fog,bj_groupEnumOwningPlayer) and not IsUnitType(fog,UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitType(fog, UNIT_TYPE_STRUCTURE) and GetWidgetLife(fog) > 0 then
        set bj_groupRandomConsidered = bj_groupRandomConsidered -1
        // Do the Omnislash actions here
    endif
    return false
endfunction

function Trig_Omnislash_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local real x2 = GetUnitX(target)
    local real y2 = GetUnitY(target)
    local player p = GetTriggerPlayer()
    local real x
    local real y
    local real angle
    local integer Loop = GetUnitAbilityLevel(caster, 'A00C')*10
    local effect fx = AddSpecialEffectTarget("Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl", caster, "weapon")
    call SetUnitVertexColor(caster, 255, 255, 255, 125)
    loop
        set angle = GetRandomReal(0.,6.282)
        call SetUnitFacing(caster,angle *bj_RADTODEG +180.)
        set x = x2 +50. *Cos(angle)
        set y = y2 +50. *Sin(angle)
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl", x, y))
        call SetUnitX(caster, x)
        call SetUnitY(caster, y)
        set bj_groupRandomConsidered = Loop
        set bj_groupEnumOwningPlayer = p
        call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, 600., Filter(function Trig_Omnislash_Filter))
        call SetUnitAnimationByIndex(caster, 2)
        if bj_groupRandomConsidered < Loop then
            set Loop = bj_groupRandomConsidered
            exitwhen Loop <= 0
            call TriggerSleepAction(0.40)
        else
            exitwhen true
        endif
    endloop
    call DestroyEffect(fx)
endfunction

function Trig_Omnislash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00C'
endfunction

//===========================================================================
function InitTrig_Omnislash takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction(t,function Trig_Omnislash_Actions)
    call TriggerAddCondition( t, Condition( function Trig_Omnislash_Conditions ) )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
endfunction


Are you using NewGen?
 

tooltiperror

Super Moderator
Reaction score
231
I 'vJASS'd' your code, but only what you gave us, far too lazy to finish it.

JASS:
 library Omnislash initializer onInit
    private function Filter takes nothing returns boolean
        local unit fog=GetFilterUnit()
        if bj_groupRandomConsidered >= 0 and IsUnitEnemy(fog,bj_groupEnumOwningPlayer) and not IsUnitType(fog,UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitType(fog, UNIT_TYPE_STRUCTURE) and GetWidgetLife(fog) > 0 then
            set bj_groupRandomConsidered = bj_groupRandomConsidered -1
            // Do the Omnislash actions here
        endif
        return false
    endfunction
    private function Actions takes nothing returns nothing
        local unit caster=GetTriggerUnit()
        local unit target=GetSpellTargetUnit()
        local real x2=GetUnitX(target)
        local real y2=GetUnitY(target)
        local player p=GetTriggerPlayer()
        local real x
        local real y
        local real angle
        local integer Loop=GetUnitAbilityLevel(caster, 'A00C')*10
        local effect fx=AddSpecialEffectTarget("Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl", caster, "weapon")
        call SetUnitVertexColor(caster, 255, 255, 255, 125)
          loop
            set angle = GetRandomReal(0.,6.282)
            call SetUnitFacing(caster,angle *bj_RADTODEG +180.)
            set x = x2 +50. *Cos(angle)
            set y = y2 +50. *Sin(angle)
            call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl",x,y))
            call SetUnitX(caster, x)
            call SetUnitY(caster, y)
            set bj_groupRandomConsidered = Loop
            set bj_groupEnumOwningPlayer = p
            call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, 600., Filter(function Filter))
            call SetUnitAnimationByIndex(caster, 2)
              if bj_groupRandomConsidered < Loop then
                set Loop = bj_groupRandomConsidered
                exitwhen Loop <= 0
                call TriggerSleepAction(0.40)
                exitwhen true
              endif
          endloop
        call DestroyEffect(fx)
        set caster=null
        set target=null
        set x2=0.00
        set y2=0.00
        set p=null
        set x=0.00
        set y=0.00
        set angle=0.00
        set Loop=0
        set fx=null
    endfunction
    private function Condition takes nothing returns boolean
        return GetSpellAbilityId() == 'A00C'
    endfunction
    private function onInit takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerAddAction(t,function Actions)
        call TriggerAddCondition(t,Condition(function Condition))
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    endfunction
 endlibrary


You also use TSA :thdown:
 

Bribe

vJass errors are legion
Reaction score
67
FYI:

JASS:

        set x2=0.00 // useless 
        set y2=0.00 // useless
        set p=null   // useless as Players never get destroyed, so they don't leak handles.
        set x=0.00   //useless
        set y=0.00  //useless
        set angle=0.00 //useless
        set Loop=0  //useless
 

tooltiperror

Super Moderator
Reaction score
231
I'll give you the point that players is pointless, but I like to null my integer based variables. After all, they're at the end, so why does it matter?
 

Bribe

vJass errors are legion
Reaction score
67
It matters because you're telling the computer to do more work than necessary. A good optimization should use only the minimum: no leaks & fastest execution possible. That's why we use benchmarks.

local integers/strings/reals/booleans never need any attention at the end of the function, as no local variables are ever saved past the end of the function. The only attention locals need at the end are ones that have handles (dummy units/special effects/dynamic triggers/etc.)

If you use parameters, you don't need to null their values.
 

killingdyl

Active Member
Reaction score
6
does this work? it works for me, but like is it efficient and wont cause too much problem?

JASS:
function Trig_Omnislash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00C'  
endfunction

function Trig_Omnislash_Filter takes nothing returns boolean
    local unit fog = GetFilterUnit()
    local player p = GetOwningPlayer(GetTriggerUnit())
    if (IsUnitAlly(fog, p) == false) and (IsUnitType(fog, UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(fog, UNIT_TYPE_STRUCTURE) == false) and not(GetUnitState(fog, UNIT_STATE_LIFE) <=0) then
        return true
    endif
    return false
endfunction

function Trig_Omnislash_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local player p = GetOwningPlayer(caster)
    local real x
    local real y
    local real angle
    local integer random
    local integer Loop = GetUnitAbilityLevel(caster, 'A00C')*10
    local integer i = 1
    local group g = CreateGroup()
    local unit fog
    local effect fx = AddSpecialEffectTarget("Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl", caster, "weapon")
    call SetUnitVertexColor(caster, 255, 255, 255, 125)
    call SetUnitPathing(caster, false)
    loop
        exitwhen i > Loop
        call SelectUnit(caster, false)
        set angle = GetRandomInt(0, 35) * 10 + GetRandomInt(0, 18) * 10
        call SetUnitFacing(caster, angle-180)
        set x = GetUnitX(target) + 50 * Cos(angle * bj_DEGTORAD)
        set y = GetUnitY(target) + 50 * Sin(angle * bj_DEGTORAD)
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl", x, y))
        call SetUnitX(caster, x)
        call SetUnitY(caster, y)
        call GroupEnumUnitsInRange(g, x, y, 600, Filter(function Trig_Omnislash_Filter))
        set target = GroupPickRandomUnit(g)
        if target == null then
            exitwhen target == null
        endif
        call BJDebugMsg(UnitId2String(GetUnitTypeId(target)))
        set i = i + 1
        call SetUnitAnimationByIndex(caster, 2)
        call TriggerSleepAction(0.40)
    endloop
    call DestroyEffect(fx)
    set fx = null
    call SetUnitVertexColor(caster, 255, 255, 255, 255)
    call SetUnitPathing(caster, true)
    call SelectUnit(caster, true)
endfunction

//===========================================================================
function InitTrig_Omnislash takes nothing returns nothing
    local trigger Omnislash = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Omnislash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( Omnislash, Condition( function Trig_Omnislash_Conditions ) )
    call TriggerAddAction( Omnislash, function Trig_Omnislash_Actions )
endfunction
 

Bribe

vJass errors are legion
Reaction score
67
JASS:
function Trig_Omnislash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00C'  
endfunction

function Trig_Omnislash_GetRandomUnit takes nothing returns boolean
    local unit fog = GetFilterUnit()
    if GetRandomInt(0,bj_groupRandomConsidered) == 0 and IsUnitEnemy(fog,bj_groupEnumOwningPlayer) and not IsUnitType(fog, UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitType(fog, UNIT_TYPE_STRUCTURE) and not GetWidgetLife(fog) > 0. then
        set bj_groupRandomConsidered = bj_groupRandomConsidered + 1
        set bj_groupRandomCurrentPick = fog
    endif
    // return false so no units are ever added (saves useless extra function calls)
    return false
endfunction

function Trig_Omnislash_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local player p = GetTriggerPlayer() //It's faster and returns same value as GetOwningPlayer(caster) because you can do
    local real x                        //with a player-unit event.
    local real y
    local real angle
    local integer Loop = GetUnitAbilityLevel(caster, 'A00C')*10
    local integer i = 0
    local unit fog
    local effect fx = AddSpecialEffectTarget("Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl", caster, "weapon")
    call SetUnitVertexColor(caster, 255, 255, 255, 125)
    call SetUnitPathing(caster, false)
    loop
        call SelectUnit(caster, false)
        set angle = GetRandomInt(0, 35) * 10 + GetRandomInt(0, 18) * 10
        call SetUnitFacing(caster, angle-180)
        set x = GetUnitX(target) + 50 * Cos(angle * bj_DEGTORAD)
        set y = GetUnitY(target) + 50 * Sin(angle * bj_DEGTORAD)
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl", x, y))
        call SetUnitX(caster, x)
        call SetUnitY(caster, y)
        
        set bj_groupRandomConsidered = 0        //Inline the "GroupPickRandomUnit" into the filter for efficiency
        set bj_groupRandomCurrentPick = null    //Use a global for the group enum;
        set bj_groupEnumOwningPlayer = p        //"GetOwningPlayer(GetTriggerUnit())" will not work after so many "TriggerSleepAction" calls

        call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, 600, Filter(function Trig_Omnislash_GetRandomUnit))
                                    // Use a global group so you don't ever have to destroy it.
        set target = bj_groupRandomCurrentPick
        exitwhen target == null
        //Do things with the random unit from the group (now set to the local variable "target"):
        //
        set i = i + 1
        exitwhen i == Loop
        call SetUnitAnimationByIndex(caster, 2)
        call TriggerSleepAction(0.40)
    endloop
    call DestroyEffect(fx)
    set fx = null
    set caster = null
    set target = null
    call SetUnitVertexColor(caster, 255, 255, 255, 255)
    call SetUnitPathing(caster, true)
    call SelectUnit(caster, true)
endfunction

//===========================================================================
function InitTrig_Omnislash takes nothing returns nothing
    local trigger Omnislash = CreateTrigger(  )
    call TriggerAddCondition( Omnislash, Condition( function Trig_Omnislash_Conditions ) )
    call TriggerAddAction( Omnislash, function Trig_Omnislash_Actions )
    call TriggerRegisterAnyUnitEventBJ( Omnislash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top