• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Just Checking

Status
Not open for further replies.
Level 31
Joined
May 3, 2008
Messages
3,155
Although this spells was working fine and I am 100% sure it was bugless. It would be better to play safe than be sorry. I hope some JASSER could view it and see if there is any part that could use improvement.

JASS:
function Trig_Demonic_Rampage_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62U'
endfunction

function Trig_Demonic_Rampage_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit lastcreated
 local location loc=GetSpellTargetLoc()
 local effect sfx
 local real x1=GetLocationX(loc)
 local real y1=GetLocationY(loc)
 local real x2
 local real y2
 local real facingangle
 local integer index=1
    set lastcreated=CreateUnit(GetOwningPlayer(caster),'n61P',x1,y1,270)
    call UnitApplyTimedLife(lastcreated,'BTLF',3)
    call IssuePointOrder(lastcreated,"stasistrap",x1,y1)
    set lastcreated=null
    set sfx=AddSpecialEffect("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl",x1,y1)
    call DestroyEffect(sfx)
    loop
        exitwhen index>(GetUnitAbilityLevel(caster,'A62U')*3)
        set x2=x1+700*Cos((udg_angle+(120.00/I2R(GetUnitAbilityLevel(caster,'A62U'))))*bj_DEGTORAD)
        set y2=y1+700*Sin((udg_angle+(120.00/I2R(GetUnitAbilityLevel(caster,'A62U'))))*bj_DEGTORAD)
        set facingangle=bj_RADTODEG*Atan2(y1-y2,x1-x2)
        set lastcreated=CreateUnit(GetOwningPlayer(caster),'n61O',x2,y2,facingangle)
        call SetUnitTimeScale(lastcreated,1.3)
        call UnitApplyTimedLife(lastcreated,'BTLF',6)
        set lastcreated=null
        set udg_angle=(udg_angle+(120.00/I2R(GetUnitAbilityLevel(caster,'A62U'))))
        set index=index+1
    endloop
    call RemoveLocation(loc)
    set udg_angle=0.00
    set sfx=null
    set caster=null
    set loc=null
endfunction

//===========================================================================

constant function DRDF takes nothing returns boolean
    return true
endfunction

function InitTrig_Demonic_Rampage takes nothing returns nothing
    local trigger T = CreateTrigger()
    local integer TI = 0
    local filterfunc FF = Filter(function DRDF)
    loop
    exitwhen (TI >= bj_MAX_PLAYER_SLOTS)
    call TriggerRegisterPlayerUnitEvent(T, Player(TI), EVENT_PLAYER_UNIT_SPELL_EFFECT, FF)
    set TI = TI + 1
    endloop
    call DestroyBoolExpr(FF)
    call DestroyFilter(FF)
    call TriggerAddAction(T,function Trig_Demonic_Rampage_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Demonic_Rampage_Conditions))
    set FF = null
    set T = null
endfunction

JASS:
function Trig_Energy_Greed_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),'A62F')>0
endfunction

function Trig_Energy_Greed_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local integer level=GetUnitAbilityLevel(caster,'A62F')
 local real manabefore=GetUnitState(caster,UNIT_STATE_MANA)
 local real manaafter
 local real manaadd
 local real x
 local real y
 local effect sfx=null
    call TriggerSleepAction(0.05)
    set manaafter=GetUnitState(caster,UNIT_STATE_MANA)
    call TriggerSleepAction(0.02)
    set manaadd=((manabefore-manaafter)/2)
    if GetRandomInt(1,10)<=level then
        set x=GetUnitX(caster)
        set y=GetUnitY(caster)
        call SetUnitState(caster,UNIT_STATE_MANA,(GetUnitState(caster,UNIT_STATE_MANA)+manaadd))
        set sfx=AddSpecialEffect("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",x,y)
        call TriggerSleepAction(0.01)
        call DestroyEffect(sfx)
        set sfx=null
    endif
   set caster=null 
endfunction

//===========================================================================

constant function EGDF takes nothing returns boolean
    return true
endfunction

function InitTrig_Energy_Greed takes nothing returns nothing
    local trigger T = CreateTrigger()
    local integer TI = 0
    local filterfunc FF = Filter(function EGDF)
    loop
    exitwhen (TI >= bj_MAX_PLAYER_SLOTS)
    call TriggerRegisterPlayerUnitEvent(T, Player(TI), EVENT_PLAYER_UNIT_SPELL_EFFECT, FF)
    set TI = TI + 1
    endloop
    call DestroyBoolExpr(FF)
    call DestroyFilter(FF)
    call TriggerAddAction(T,function Trig_Energy_Greed_Conditions)
    call TriggerAddCondition(T,Condition(function Trig_Energy_Greed_Actions))
    set FF = null
    set T = null
endfunction

JASS:
function Trig_Massive_Conversion_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62J'
endfunction

function Boolean takes nothing returns boolean
    return (IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE)==false) and (IsUnitType(GetFilterUnit(),UNIT_TYPE_MAGIC_IMMUNE)==false) and (GetWidgetLife(GetFilterUnit())>.415) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO)==false) and (IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit()))==true)
endfunction

function Trig_Massive_Conversion_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit target
 local effect sfx
 local real x1=GetUnitX(caster)
 local real y1=GetUnitY(caster)
 local real x2
 local real y2
    call GroupEnumUnitsInRange(udg_MC_Group,x1,y1,500,Condition(function Boolean))
    set target=FirstOfGroup(udg_MC_Group)
    loop
        exitwhen target==null
        call SetUnitOwner(target,GetOwningPlayer(caster),true)
        set x2=GetUnitX(target)
        set y2=GetUnitY(target)
        set sfx=AddSpecialEffect("Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl",x2,y2)
        call GroupRemoveUnit(udg_MC_Group,target)
        set target=FirstOfGroup(udg_MC_Group)
        call DestroyEffect(sfx)
        set sfx=null
    endloop
    set caster=null
endfunction

//===========================================================================

constant function MCDF takes nothing returns boolean
    return true
endfunction

function InitTrig_Massive_Conversion takes nothing returns nothing
    local trigger T = CreateTrigger()
    local integer TI = 0
    local filterfunc FF = Filter(function MCDF)
    loop
    exitwhen (TI >= bj_MAX_PLAYER_SLOTS)
    call TriggerRegisterPlayerUnitEvent(T, Player(TI), EVENT_PLAYER_UNIT_SPELL_EFFECT, FF)
    set TI = TI + 1
    endloop
    call DestroyBoolExpr(FF)
    call DestroyFilter(FF)
    call TriggerAddAction(T,function Trig_Massive_Conversion_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Massive_Conversion_Conditions))
    set FF = null
    set T = null
endfunction

JASS:
function Trig_Multiple_Shot_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62P'
endfunction

function Trig_Multiple_Shot_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit lastcreated
 local location loc=GetSpellTargetLoc()
 local real x1=GetUnitX(caster)
 local real y1=GetUnitY(caster)
 local real x2=GetLocationX(loc)
 local real y2=GetLocationY(loc)
 local real missilefacing=bj_RADTODEG*Atan2(y2-y1,x2-x1)
 local real angle=(GetUnitFacing(caster)-(GetUnitAbilityLevel(caster,'A62P') * 10.00 ))
 local real offsetx
 local real offsety
 local integer index=1
    loop
        exitwhen index>(GetUnitAbilityLevel(caster,'A62P')*5)
        set lastcreated=CreateUnit(GetOwningPlayer(caster),'e605',x1,y1,missilefacing)
        call UnitApplyTimedLife(lastcreated,'BTLF',2)
        set offsetx=x2+150*Cos(angle*bj_DEGTORAD)
        set offsety=y2+150*Sin(angle*bj_DEGTORAD)
        call IssuePointOrder(lastcreated,"breathoffire",offsetx,offsety)
        set lastcreated=null
        set angle=angle+4.00
        set index=index+1
    endloop
    call RemoveLocation(loc)
    set caster=null
    set loc=null
endfunction

//===========================================================================

constant function MSDF takes nothing returns boolean
    return true
endfunction

function InitTrig_Multiple_Shot takes nothing returns nothing
    local trigger T = CreateTrigger()
    local integer TI = 0
    local filterfunc FF = Filter(function MSDF)
    loop
    exitwhen (TI >= bj_MAX_PLAYER_SLOTS)
    call TriggerRegisterPlayerUnitEvent(T, Player(TI), EVENT_PLAYER_UNIT_SPELL_EFFECT, FF)
    set TI = TI + 1
    endloop
    call DestroyBoolExpr(FF)
    call DestroyFilter(FF)
    call TriggerAddAction(T,function Trig_Multiple_Shot_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Multiple_Shot_Conditions))
    set FF = null
    set T = null
endfunction

JASS:
function Trig_Napalm_Shock_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62A'
endfunction

function Trig_Napalm_Shock_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit target=GetSpellTargetUnit()
 local unit lastcreated
 local real x1=GetUnitX(caster)
 local real y1=GetUnitY(caster)
 local real x2=GetUnitX(target)
 local real y2=GetUnitY(target)
 local real x3
 local real y3
 local real damage=40+(GetUnitAbilityLevel(caster,'A62A')*15)
 local integer index=1
 local real dx=x2-x1
 local real dy=y2-y1
 local real distance=SquareRoot(dx*dx+dy*dy)/100
 local real angle=bj_RADTODEG*Atan2(y2-y1,x2-x1)
    call UnitDamageTarget(caster,target,damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Other\\Volcano\\VolcanoDeath.mdl",x1,y1))
    loop
        exitwhen index>R2I(distance)
        set x3=x1+(udg_NS_Distance+100)*Cos(angle*bj_DEGTORAD)
        set y3=y1+(udg_NS_Distance+100)*Sin(angle*bj_DEGTORAD)
        set lastcreated=CreateUnit(GetOwningPlayer(caster),'n61G',x3,y3,angle)
        set udg_NS_Distance=udg_NS_Distance+100
        call UnitApplyTimedLife(lastcreated,'BTLF',0.2)
        set lastcreated=null
        set index=index+1
    endloop
    set lastcreated=CreateUnit(GetOwningPlayer(caster),'n61E',x2,y2,angle)
    call UnitApplyTimedLife(lastcreated,'BTLF',3)
    call UnitAddAbility(lastcreated,'A629')
    call SetUnitAbilityLevel(lastcreated,'A629',GetUnitAbilityLevel(caster,'A62A'))
    call IssueTargetOrder(lastcreated,"shadowstrike",target)
    set udg_NS_Distance=0.00
endfunction

//===========================================================================

constant function NSDF takes nothing returns boolean
    return true
endfunction

function InitTrig_Napalm_Shock takes nothing returns nothing
    local trigger T = CreateTrigger()
    local integer TI = 0
    local filterfunc FF = Filter(function NSDF)
    loop
    exitwhen (TI >= bj_MAX_PLAYER_SLOTS)
    call TriggerRegisterPlayerUnitEvent(T, Player(TI), EVENT_PLAYER_UNIT_SPELL_EFFECT, FF)
    set TI = TI + 1
    endloop
    call DestroyBoolExpr(FF)
    call DestroyFilter(FF)
    call TriggerAddAction(T,function Trig_Napalm_Shock_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Napalm_Shock_Conditions))
    set FF = null
    set T = null
endfunction

JASS:
function Trig_Phoenix_Swap_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A634'
endfunction

function Trig_Phoenix_Swap_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit target=GetSpellTargetUnit()
    local real x1=GetUnitX(caster)
    local real x2=GetUnitX(target)
    local real y1=GetUnitY(caster)
    local real y2=GetUnitY(target)
    call SetUnitX(caster,x2)
    call SetUnitX(target,x1)
    call SetUnitY(caster,y2)
    call SetUnitY(target,y1)
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl",x1,y1))
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl",x2,y2))
    if IsUnitEnemy(target,GetOwningPlayer(caster))==true then
        call UnitDamageTarget(caster,target,50.00,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    endif
    set caster=null
    set target=null
endfunction

//===========================================================================

constant function PSDF takes nothing returns boolean
    return true
endfunction

function InitTrig_Phoenix_Swap takes nothing returns nothing
    local trigger T = CreateTrigger()
    local integer TI = 0
    local filterfunc FF = Filter(function PSDF)
    loop
    exitwhen (TI >= bj_MAX_PLAYER_SLOTS)
    call TriggerRegisterPlayerUnitEvent(T, Player(TI), EVENT_PLAYER_UNIT_SPELL_EFFECT, FF)
    set TI = TI + 1
    endloop
    call DestroyBoolExpr(FF)
    call DestroyFilter(FF)
    call TriggerAddAction(T,function Trig_Phoenix_Swap_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Phoenix_Swap_Conditions))
    set FF = null
    set T = null
endfunction

JASS:
constant function Trig_Wind_Slash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62D'
endfunction

function WS_Filter takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) != true and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) >= .415 and IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == true and IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING) != true and UnitIsSleeping(GetFilterUnit()) != true and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) != true and IsUnitHidden(GetFilterUnit()) != true)
endfunction

function Trig_Wind_Slash_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit v = GetSpellTargetUnit()
    local real x = GetUnitX(v)
    local real y = GetUnitY(v)
    local integer loops = GetUnitAbilityLevel(u, 'A62D') * 2
    local group g = CreateGroup()
    local boolexpr bx = Filter(function WS_Filter)
    
    call SetUnitInvulnerable( u, true )
    call SetUnitVertexColor( u, 255, 255, 255, 127 )
    call SelectUnit(u, false)
    call PauseUnit( u, true )
    call SetUnitPosition(u, x, y)
    call PauseUnit(u, false)
    call SetUnitAnimation( u, "attack" )
    call UnitDamageTarget( u, v, GetRandomReal(150.00, 250.00), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    call DestroyEffect(AddSpecialEffectTarget( "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl", u, "chest" ))
    
    loop
    exitwhen (loops == 0)
        call TriggerSleepAction( 0.20 )
        set x = GetUnitX(v)
        set y = GetUnitY(v)
        set u = u
        call GroupEnumUnitsInRange(g, x, y, 700., bx)
        set v = GroupPickRandomUnit(g)
        if ( v != null ) then
            call SelectUnit(u, false)
            call PauseUnit( u, true )
            call SetUnitPosition( u, GetUnitX(v), GetUnitY(v) )
            call PauseUnit( u, false )
            call SetUnitAnimation( u, "attack" )
            call UnitDamageTarget( u, v, GetRandomReal(150.00, 250.00), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            call DestroyEffect(AddSpecialEffectTarget( "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl", u, "chest" ))
        else
            exitwhen (true)
        endif
        set loops = loops - 1
    endloop
    if (GetLocalPlayer() == GetOwningPlayer(u)) then
        call SelectUnit(u, true)
    endif
    call SetUnitVertexColor( u, 255, 255, 255, 255 )
    call SetUnitInvulnerable( u, false )
    call DestroyGroup(g)
    call DestroyBoolExpr(bx)
    
    set g = null
    set bx = null
    set u = null
    set v = null
endfunction

//===========================================================================

constant function WSDF takes nothing returns boolean
    return true
endfunction

function InitTrig_Wind_Slash takes nothing returns nothing
    local trigger T = CreateTrigger()
    local integer TI = 0
    local filterfunc FF = Filter(function WSDF)
    loop
    exitwhen (TI >= bj_MAX_PLAYER_SLOTS)
    call TriggerRegisterPlayerUnitEvent(T, Player(TI), EVENT_PLAYER_UNIT_SPELL_EFFECT, FF)
    set TI = TI + 1
    endloop
    call DestroyBoolExpr(FF)
    call DestroyFilter(FF)
    call TriggerAddAction(T,function Trig_Wind_Slash_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Wind_Slash_Conditions))
    set FF = null
    set T = null
endfunction
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
JASS:
constant function Demonic_Rampage_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62U'
endfunction
 
constant function DarkR takes nothing returns string
    return "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl"
endfunction
 
function Demonic_Rampage_Actions takes nothing returns nothing
    local unit caster=GetTriggerUnit()
    local player p = GetOwningPlayer(caster)
    local real x=GetSpellTargetX()
    local real y=GetSpellTargetY()
    local unit lastcreated = CreateUnit(p,'n61P',x,y,270)
    local real x2
    local real y2
    local integer level = GetUnitAbilityLevel(caster,'A62U')
    local integer index=1
    local integer angle = 0
 
    call UnitApplyTimedLife(lastcreated,'BTLF',3)
    call IssuePointOrder(lastcreated,"stasistrap",x,y)
    call DestroyEffect(AddSpecialEffect(DarkR(),x,y))
 
    loop
      exitwhen index>(level*3)
        set x2=x+700*Cos((angle+(120.00/I2R(level)))*bj_DEGTORAD)
        set y2=y+700*Sin((angle+(120.00/I2R(level)))*bj_DEGTORAD)
        set lastcreated=CreateUnit(p,'n61O',x2,y2, bj_RADTODEG*Atan2(y-y2,x-x2) )
        call SetUnitTimeScale(lastcreated,1.3)
        call UnitApplyTimedLife(lastcreated,'BTLF',6)
        set angle=(angle+(120.00/I2R(level)))
      set index=index+1
    endloop
 
    set lastcreated=null
    set caster=null
    set p = null
endfunction
 
function InitTrig_Demonic_Rampage takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Demonic_Rampage_Actions)
    call TriggerAddCondition(T,Condition(function Demonic_Rampage_Conditions))
    set T = null
endfunction

JASS:
constant function Energy_Greed_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),'A62F')>0
endfunction
 
constant function ResourceT takes nothing returns string
    return "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
endfunction
 
function Energy_Greed_Actions takes nothing returns nothing
 local unit u=GetTriggerUnit()
 local integer level=GetUnitAbilityLevel(u,'A62F')
 local real x=GetUnitState(u,UNIT_STATE_MANA)
 local real y
    call TriggerSleepAction(.05)
    set y=GetUnitState(u,UNIT_STATE_MANA)
    call TriggerSleepAction(.02)
    set y=((x-y)/2)
    if GetRandomInt(1,10)<=level then
        call SetUnitState(u,UNIT_STATE_MANA,(GetUnitState(u,UNIT_STATE_MANA)+y))
        call DestroyEffect(AddSpecialEffect(ResourceT(),GetUnitX(u),GetUnitY(u)))
    endif
   set u=null 
endfunction
 
function InitTrig_Energy_Greed takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Energy_Greed_Conditions)
    call TriggerAddCondition(T,Condition(function Energy_Greed_Actions))
    set T = null
endfunction

JASS:
constant function Massive_Conversion_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62J'
endfunction
 
constant function CharT takes nothing returns string
    return "Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl"
endfunction
 
constant function Boolean takes unit u returns boolean
    return IsUnitType(u,UNIT_TYPE_STRUCTURE) or IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) or GetWidgetLife(u)<= 0 or IsUnitType(u, UNIT_TYPE_HERO) or IsUnitAlly(u,GetOwningPlayer(GetTriggerUnit()))
endfunction
 
function Massive_Conversion_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit u
 local group g = CreateGroup( )
    call GroupEnumUnitsInRange(g,GetUnitX(caster),GetUnitY(caster),500., null)
    loop
      set u=FirstOfGroup(g)
      call GroupRemoveUnit(g,u)
        exitwhen u == null
      if Boolean(u) == false then 
        call SetUnitOwner(u,GetOwningPlayer(caster),true)
        call DestroyEffect(AddSpecialEffect(CharT(),GetUnitX(u),GetUnitY(u)))
      endif
    endloop
    call DestroyGroup(g)
    set caster=null
    set g = null
endfunction
 
function InitTrig_Massive_Conversion takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Massive_Conversion_Actions)
    call TriggerAddCondition(T,Condition(function Massive_Conversion_Conditions))
    set T = null
endfunction

JASS:
constant function Trig_Multiple_Shot_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62P'
endfunction
 
function Trig_Multiple_Shot_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit lastcreated
 local real x1=GetUnitX(caster)
 local real y1=GetUnitY(caster)
 local real x2=GetSpellTargetX()
 local real y2=GetSpellTargetY()
 local real missilefacing=bj_RADTODEG*Atan2(y2-y1,x2-x1)
 local real angle=(GetUnitFacing(caster)-(GetUnitAbilityLevel(caster,'A62P') * 10.00 ))
 local integer index=1
    loop
        exitwhen index>(GetUnitAbilityLevel(caster,'A62P')*5)
        set lastcreated=CreateUnit(GetOwningPlayer(caster),'e605',x1,y1,missilefacing)
        call UnitApplyTimedLife(lastcreated,'BTLF',2)
        call IssuePointOrder(lastcreated,"breathoffire",x2+150*Cos(angle*bj_DEGTORAD),y2+150*Sin(angle*bj_DEGTORAD))
        set angle=angle+4.00
        set index=index+1
    endloop
    set lastcreated=null
    set caster=null
endfunction
 
function InitTrig_Multiple_Shot takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Trig_Multiple_Shot_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Multiple_Shot_Conditions))
    set T = null
endfunction

JASS:
constant function Trig_Napalm_Shock_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62A'
endfunction
 
constant function VolcD takes nothing returns string
    return "Abilities\\Spells\\Other\\Volcano\\VolcanoDeath.mdl"
endfunction 
 
function Trig_Napalm_Shock_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit target=GetSpellTargetUnit()
 local unit lastcreated
 local real x1=GetUnitX(caster)
 local real y1=GetUnitY(caster)
 local real x2=GetUnitX(target)
 local real y2=GetUnitY(target)
 local real x3
 local real y3
 local real damage=40+(GetUnitAbilityLevel(caster,'A62A')*15)
 local integer index=1
 local real dx=x2-x1
 local real dy=y2-y1
 local real distance=SquareRoot(dx*dx+dy*dy)/100
 local real NSDistance = 0
 local real angle=bj_RADTODEG*Atan2(y2-y1,x2-x1)
    call UnitDamageTarget(caster,target,damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    call DestroyEffect(AddSpecialEffect(VolcD(),x1,y1))
    loop
        exitwhen index>R2I(distance)
        set x3=x1+(NSDistance+100)*Cos(angle*bj_DEGTORAD)
        set y3=y1+(NSDistance+100)*Sin(angle*bj_DEGTORAD)
        set lastcreated=CreateUnit(GetOwningPlayer(caster),'n61G',x3,y3,angle)
        set NSDistance=NSDistance+100
        call UnitApplyTimedLife(lastcreated,'BTLF',0.2)
        set index=index+1
    endloop
 
    set lastcreated=CreateUnit(GetOwningPlayer(caster),'n61E',x2,y2,angle)
    call UnitApplyTimedLife(lastcreated,'BTLF',3)
    call UnitAddAbility(lastcreated,'A629')
    call SetUnitAbilityLevel(lastcreated,'A629',GetUnitAbilityLevel(caster,'A62A'))
    call IssueTargetOrder(lastcreated,"shadowstrike",target)
    set target=null
    set caster = null
    set lastcreated=null
endfunction
 
function InitTrig_Napalm_Shock takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Trig_Napalm_Shock_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Napalm_Shock_Conditions))
    set T = null
endfunction

JASS:
constant function Trig_Phoenix_Swap_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A634'
endfunction
 
constant function DoomD takes nothing returns string
    return "Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl"
endfunction
 
function Trig_Phoenix_Swap_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit target=GetSpellTargetUnit()
    local real x1=GetUnitX(caster)
    local real x2=GetUnitX(target)
    local real y1=GetUnitY(caster)
    local real y2=GetUnitY(target)
    call SetUnitX(caster,x2)
    call SetUnitX(target,x1)
    call SetUnitY(caster,y2)
    call SetUnitY(target,y1)
    call DestroyEffect(AddSpecialEffect(DoomD(),x1,y1))
    call DestroyEffect(AddSpecialEffect(DoomD(),x2,y2))
    if IsUnitEnemy(target,GetOwningPlayer(caster)) then
        call UnitDamageTarget(caster,target,50.00,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    endif
    set caster=null
    set target=null
endfunction
 
function InitTrig_Phoenix_Swap takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Trig_Phoenix_Swap_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Phoenix_Swap_Conditions))
    set T = null
endfunction

JASS:
constant function Trig_Wind_Slash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62D'
endfunction
 
constant function BlinkC takes nothing returns string
    return "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
endfunction
 
constant function WS_Filter takes unit u returns boolean
    return IsUnitType(u, UNIT_TYPE_STRUCTURE) != true and GetUnitState(u, UNIT_STATE_LIFE) > 0 and IsUnitEnemy(u, GetOwningPlayer(GetTriggerUnit())) and IsUnitType(u, UNIT_TYPE_FLYING) != true and UnitIsSleeping(u) != true and IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) != true and IsUnitHidden(u) != true
endfunction
 
function Trig_Wind_Slash_Actions takes nothing returns nothing
    local group g
    local unit E
    local unit u = GetTriggerUnit()
    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()
    local unit v = GetSpellTargetUnit()
    local integer i = GetUnitAbilityLevel(u, 'A62D') * 2
    local integer o
 
    call SetUnitInvulnerable( u, true )
    call SetUnitVertexColor( u, 255, 255, 255, 127 )
    call SelectUnit(u, false)
    call PauseUnit( u, true )
    call SetUnitPosition(u, x, y)
    call PauseUnit(u, false)
    call SetUnitAnimation( u, "attack" )
    call UnitDamageTarget( u, v, GetRandomReal(150.00, 250.00), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    call DestroyEffect(AddSpecialEffectTarget( BlinkC(), u, "chest" ))
 
    loop
        call TriggerSleepAction( 0.20 )
        set o = 1
        set g = CreateGroup()
        call GroupEnumUnitsInRange(g, GetUnitX(v), GetUnitY(v), 700., null)
            set v = null
            loop
              set E = FirstOfGroup(g)
                exitwhen E == null
                  call GroupRemoveUnit( g , E )
                  if WS_Filter( E ) then
                    if GetRandomInt( 1 , o ) == 1 then
                      set v = E
                      set o = o + 1
                    endif
                  endif
            endloop
            call DestroyGroup(g)
            exitwhen v == null
                call SelectUnit(u, false)
                call PauseUnit( u, true )
            call SetUnitPosition( u, GetUnitX(v), GetUnitY(v) )
            call PauseUnit( u, false )
            call SetUnitAnimation( u, "attack" )
            call UnitDamageTarget( u, v, GetRandomReal(150.00, 250.00), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            call DestroyEffect(AddSpecialEffectTarget( BlinkC(), u, "chest" ))
        set i = i - 1
        exitwhen i == 0
    endloop
 
    if (GetLocalPlayer() == GetOwningPlayer(u)) then
        call SelectUnit(u, true)
    endif
    call SetUnitVertexColor( u, 255, 255, 255, 255 )
    call SetUnitInvulnerable( u, false )
 
    set g = null
    set u = null
    set v = null
    set E = null
endfunction
 
function InitTrig_Wind_Slash takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Trig_Wind_Slash_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Wind_Slash_Conditions))
    set T = null
endfunction
 
Last edited:
Level 10
Joined
Mar 31, 2009
Messages
732
Not all BJs leak. Theres quite a lot that are okay to use, and save you duplicating whats in the BJ function. Changing elevator heights comes to mind.

The leaky ones are mostly ones that deal with unitgroups and forces, where they don't destroy the forces after use.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Looks ok, but you should either use globals or constant functions to hold the paths for the effects. Makes it easier to edit ^^

Edit: You don't need this in the filter:
JASS:
local unit u = GetFilterUnit()
Somehow it doesn't leak when inside filters like that :D


Another edit :D
Your filter could look like this instead:
JASS:
function WS_Filter takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) != true and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 and IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) and IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING) != true and UnitIsSleeping(GetFilterUnit()) != true and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) != true and IsUnitHidden(GetFilterUnit()) != true
endfunction

Yeah, there will be a lot of function calls to GetFilterUnit(), but I think it's better this way.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
I've heard GetFilterUnit() can lag slightly, so I replace him with unit u for a quick variable whenever it requires more than a couple calls.

I +rep'd you for the tip on strings, yeah, I can see how that is 1029483 times better :p I remember having a lot of problems editing my effects in previous maps because the mouse would slide off the screen and cause the code to scroll when trying to select that long body.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
constant makes the function call faster. It's exponentially more efficient as a normal function the more you call it.

edit: the only counter is that you can't use it for too many functions. Like you can't make a constant function that creates a unit, but you can make a constant function that checks if the unit is a footman.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Anyway, put this at the top of your map initialization script:

JASS:
function SpellEvent takes trigger T returns nothing
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(T, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
endfunction

I'll go ahead and replace all those AnyUnitBJ events with this function call. That way you don't have to keep typing the same thing over and over
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,199
As far as I am aware, constant functions do nothing more than normal functions as they can return variable data (atleast last time I tried).
It is far better to use constant variables as it prevents a dump to stack and then function call (just loads a storage location) which is why all vJass spells use them.

BJs generally leak handle indexes due to the local handles not being nulled at function end so the index recycler stores ghost references (thinks there is a variable holding the index when there is not). This is only a problem with regually run BJs on large ammounts of different handles which are constantly being removed or destroyed. For anything once off or handles which never are removed it is not a problem.

Generally it is still better to avoid BJ usage as it ends up an extra function call and dump to stack opperation which is logically slower than not doing that.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Yeah, I think the best way to define a constant function against a standard function is that constant functions cannot create handles - they can only evaluate them.

You should be able to:
JASS:
constant function primitive takes nothing returns boolean
    return IsUnit( GetTriggerUnit() , someUnit )
endfunction
But you will not be able to:
JASS:
constant function prototype takes nothing returns unit
    local unit u = someUnit
    return u
endfunction
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,199
And how does that make them any faster? Or are you saying they basically get inlined when compiled?

The whole problem with function calls in general is that they require the current registers to be dumped to stack, new values loaded and then the function called (a lot like goto but stores an exitpoint for when return is evaluated) which is why its generally best to avoid unnescescary function calls. Inorder for a constant function to be any faster, something must be different and more simple in the way it is called. What I would like to know is what the actual logical difference is that makes them faster.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Here:

Jass: Advanced Tips by Daelin said:
Constant Functions

Other JASS subtleties are the constant functions. By adding the prefix constant, in front of the keyword function, you make a function constant. What does this mean? That the function returns a constant value, and that its value does not vary. For example, GetTriggerUnit() is a constant function, because it always returns the unit which triggered the actions.

The advantage is that constant functions are slightly faster. Sometimes it is significant, sometimes it is not. I suggest you make rawcode functions constant, because those truly return a constant value. Example:

JASS:
constant function Dummy_Raw takes nothing returns integer
    return 'h000'
endfunction

Note: Functions calling other functions that are not constant cannot be made constant themselves. Also, constant functions do not modify the value of the parameters.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Anyway, put this at the top of your map initialization script:

JASS:
function SpellEvent takes trigger T returns nothing
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(T, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
endfunction
I'll go ahead and replace all those AnyUnitBJ events with this function call. That way you don't have to keep typing the same thing over and over
I'm pretty sure you don't really need to replace TriggerRegisterAnyUnitEventBJ with the inlined version.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
So I herd u wanted Bribe's reply in hidden tags.


JASS:
constant function Demonic_Rampage_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62U'
endfunction
 
constant function DarkR takes nothing returns string
    return "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl"
endfunction
 
function Demonic_Rampage_Actions takes nothing returns nothing
    local unit caster=GetTriggerUnit()
    local player p = GetOwningPlayer(caster)
    local real x=GetSpellTargetX()
    local real y=GetSpellTargetY()
    local unit lastcreated = CreateUnit(p,'n61P',x,y,270)
    local real x2
    local real y2
    local integer level = GetUnitAbilityLevel(caster,'A62U')
    local integer index=1
    local integer angle = 0
 
    call UnitApplyTimedLife(lastcreated,'BTLF',3)
    call IssuePointOrder(lastcreated,"stasistrap",x,y)
    call DestroyEffect(AddSpecialEffect(DarkR(),x,y))
 
    loop
      exitwhen index>(level*3)
        set x2=x+700*Cos((angle+(120.00/I2R(level)))*bj_DEGTORAD)
        set y2=y+700*Sin((angle+(120.00/I2R(level)))*bj_DEGTORAD)
        set lastcreated=CreateUnit(p,'n61O',x2,y2, bj_RADTODEG*Atan2(y-y2,x-x2) )
        call SetUnitTimeScale(lastcreated,1.3)
        call UnitApplyTimedLife(lastcreated,'BTLF',6)
        set angle=(angle+(120.00/I2R(level)))
      set index=index+1
    endloop
 
    set lastcreated=null
    set caster=null
    set p = null
endfunction
 
function InitTrig_Demonic_Rampage takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Demonic_Rampage_Actions)
    call TriggerAddCondition(T,Condition(function Demonic_Rampage_Conditions))
    set T = null
endfunction


JASS:
constant function Energy_Greed_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),'A62F')>0
endfunction
 
constant function ResourceT takes nothing returns string
    return "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
endfunction
 
function Energy_Greed_Actions takes nothing returns nothing
 local unit u=GetTriggerUnit()
 local integer level=GetUnitAbilityLevel(u,'A62F')
 local real x=GetUnitState(u,UNIT_STATE_MANA)
 local real y
    call TriggerSleepAction(.05)
    set y=GetUnitState(u,UNIT_STATE_MANA)
    call TriggerSleepAction(.02)
    set y=((x-y)/2)
    if GetRandomInt(1,10)<=level then
        call SetUnitState(u,UNIT_STATE_MANA,(GetUnitState(u,UNIT_STATE_MANA)+y))
        call DestroyEffect(AddSpecialEffect(ResourceT(),GetUnitX(u),GetUnitY(u)))
    endif
   set u=null 
endfunction
 
function InitTrig_Energy_Greed takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Energy_Greed_Conditions)
    call TriggerAddCondition(T,Condition(function Energy_Greed_Actions))
    set T = null
endfunction


JASS:
constant function Massive_Conversion_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62J'
endfunction
 
constant function CharT takes nothing returns string
    return "Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl"
endfunction
 
constant function Boolean takes unit u returns boolean
    return IsUnitType(u,UNIT_TYPE_STRUCTURE) or IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) or GetWidgetLife(u)<= 0 or IsUnitType(u, UNIT_TYPE_HERO) or IsUnitAlly(u,GetOwningPlayer(GetTriggerUnit()))
endfunction
 
function Massive_Conversion_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit u
 local group g = CreateGroup( )
    call GroupEnumUnitsInRange(g,GetUnitX(caster),GetUnitY(caster),500., null)
    loop
      set u=FirstOfGroup(g)
      call GroupRemoveUnit(g,u)
        exitwhen u == null
      if Boolean(u) == false then 
        call SetUnitOwner(u,GetOwningPlayer(caster),true)
        call DestroyEffect(AddSpecialEffect(CharT(),GetUnitX(u),GetUnitY(u)))
      endif
    endloop
    call DestroyGroup(g)
    set caster=null
    set g = null
endfunction
 
function InitTrig_Massive_Conversion takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Massive_Conversion_Actions)
    call TriggerAddCondition(T,Condition(function Massive_Conversion_Conditions))
    set T = null
endfunction


JASS:
constant function Trig_Multiple_Shot_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62P'
endfunction
 
function Trig_Multiple_Shot_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit lastcreated
 local real x1=GetUnitX(caster)
 local real y1=GetUnitY(caster)
 local real x2=GetSpellTargetX()
 local real y2=GetSpellTargetY()
 local real missilefacing=bj_RADTODEG*Atan2(y2-y1,x2-x1)
 local real angle=(GetUnitFacing(caster)-(GetUnitAbilityLevel(caster,'A62P') * 10.00 ))
 local integer index=1
    loop
        exitwhen index>(GetUnitAbilityLevel(caster,'A62P')*5)
        set lastcreated=CreateUnit(GetOwningPlayer(caster),'e605',x1,y1,missilefacing)
        call UnitApplyTimedLife(lastcreated,'BTLF',2)
        call IssuePointOrder(lastcreated,"breathoffire",x2+150*Cos(angle*bj_DEGTORAD),y2+150*Sin(angle*bj_DEGTORAD))
        set angle=angle+4.00
        set index=index+1
    endloop
    set lastcreated=null
    set caster=null
endfunction
 
function InitTrig_Multiple_Shot takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Trig_Multiple_Shot_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Multiple_Shot_Conditions))
    set T = null
endfunction


JASS:
constant function Trig_Napalm_Shock_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62A'
endfunction
 
constant function VolcD takes nothing returns string
    return "Abilities\\Spells\\Other\\Volcano\\VolcanoDeath.mdl"
endfunction 
 
function Trig_Napalm_Shock_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit target=GetSpellTargetUnit()
 local unit lastcreated
 local real x1=GetUnitX(caster)
 local real y1=GetUnitY(caster)
 local real x2=GetUnitX(target)
 local real y2=GetUnitY(target)
 local real x3
 local real y3
 local real damage=40+(GetUnitAbilityLevel(caster,'A62A')*15)
 local integer index=1
 local real dx=x2-x1
 local real dy=y2-y1
 local real distance=SquareRoot(dx*dx+dy*dy)/100
 local real NSDistance = 0
 local real angle=bj_RADTODEG*Atan2(y2-y1,x2-x1)
    call UnitDamageTarget(caster,target,damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    call DestroyEffect(AddSpecialEffect(VolcD(),x1,y1))
    loop
        exitwhen index>R2I(distance)
        set x3=x1+(NSDistance+100)*Cos(angle*bj_DEGTORAD)
        set y3=y1+(NSDistance+100)*Sin(angle*bj_DEGTORAD)
        set lastcreated=CreateUnit(GetOwningPlayer(caster),'n61G',x3,y3,angle)
        set NSDistance=NSDistance+100
        call UnitApplyTimedLife(lastcreated,'BTLF',0.2)
        set index=index+1
    endloop
 
    set lastcreated=CreateUnit(GetOwningPlayer(caster),'n61E',x2,y2,angle)
    call UnitApplyTimedLife(lastcreated,'BTLF',3)
    call UnitAddAbility(lastcreated,'A629')
    call SetUnitAbilityLevel(lastcreated,'A629',GetUnitAbilityLevel(caster,'A62A'))
    call IssueTargetOrder(lastcreated,"shadowstrike",target)
    set target=null
    set caster = null
    set lastcreated=null
endfunction
 
function InitTrig_Napalm_Shock takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Trig_Napalm_Shock_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Napalm_Shock_Conditions))
    set T = null
endfunction


JASS:
constant function Trig_Phoenix_Swap_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A634'
endfunction
 
constant function DoomD takes nothing returns string
    return "Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl"
endfunction
 
function Trig_Phoenix_Swap_Actions takes nothing returns nothing
 local unit caster=GetTriggerUnit()
 local unit target=GetSpellTargetUnit()
    local real x1=GetUnitX(caster)
    local real x2=GetUnitX(target)
    local real y1=GetUnitY(caster)
    local real y2=GetUnitY(target)
    call SetUnitX(caster,x2)
    call SetUnitX(target,x1)
    call SetUnitY(caster,y2)
    call SetUnitY(target,y1)
    call DestroyEffect(AddSpecialEffect(DoomD(),x1,y1))
    call DestroyEffect(AddSpecialEffect(DoomD(),x2,y2))
    if IsUnitEnemy(target,GetOwningPlayer(caster)) then
        call UnitDamageTarget(caster,target,50.00,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    endif
    set caster=null
    set target=null
endfunction
 
function InitTrig_Phoenix_Swap takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Trig_Phoenix_Swap_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Phoenix_Swap_Conditions))
    set T = null
endfunction


JASS:
constant function Trig_Wind_Slash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A62D'
endfunction
 
constant function BlinkC takes nothing returns string
    return "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
endfunction
 
constant function WS_Filter takes unit u returns boolean
    return IsUnitType(u, UNIT_TYPE_STRUCTURE) != true and GetUnitState(u, UNIT_STATE_LIFE) > 0 and IsUnitEnemy(u, GetOwningPlayer(GetTriggerUnit())) and IsUnitType(u, UNIT_TYPE_FLYING) != true and UnitIsSleeping(u) != true and IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) != true and IsUnitHidden(u) != true
endfunction
 
function Trig_Wind_Slash_Actions takes nothing returns nothing
    local group g
    local unit E
    local unit u = GetTriggerUnit()
    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()
    local unit v = GetSpellTargetUnit()
    local integer i = GetUnitAbilityLevel(u, 'A62D') * 2
    local integer o
 
    call SetUnitInvulnerable( u, true )
    call SetUnitVertexColor( u, 255, 255, 255, 127 )
    call SelectUnit(u, false)
    call PauseUnit( u, true )
    call SetUnitPosition(u, x, y)
    call PauseUnit(u, false)
    call SetUnitAnimation( u, "attack" )
    call UnitDamageTarget( u, v, GetRandomReal(150.00, 250.00), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    call DestroyEffect(AddSpecialEffectTarget( BlinkC(), u, "chest" ))
 
    loop
        call TriggerSleepAction( 0.20 )
        set o = 1
        set g = CreateGroup()
        call GroupEnumUnitsInRange(g, GetUnitX(v), GetUnitY(v), 700., null)
            set v = null
            loop
              set E = FirstOfGroup(g)
                exitwhen E == null
                  call GroupRemoveUnit( g , E )
                  if WS_Filter( E ) then
                    if GetRandomInt( 1 , o ) == 1 then
                      set v = E
                      set o = o + 1
                    endif
                  endif
            endloop
            call DestroyGroup(g)
            exitwhen v == null
                call SelectUnit(u, false)
                call PauseUnit( u, true )
            call SetUnitPosition( u, GetUnitX(v), GetUnitY(v) )
            call PauseUnit( u, false )
            call SetUnitAnimation( u, "attack" )
            call UnitDamageTarget( u, v, GetRandomReal(150.00, 250.00), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            call DestroyEffect(AddSpecialEffectTarget( BlinkC(), u, "chest" ))
        set i = i - 1
        exitwhen i == 0
    endloop
 
    if (GetLocalPlayer() == GetOwningPlayer(u)) then
        call SelectUnit(u, true)
    endif
    call SetUnitVertexColor( u, 255, 255, 255, 255 )
    call SetUnitInvulnerable( u, false )
 
    set g = null
    set u = null
    set v = null
    set E = null
endfunction
 
function InitTrig_Wind_Slash takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Trig_Wind_Slash_Actions)
    call TriggerAddCondition(T,Condition(function Trig_Wind_Slash_Conditions))
    set T = null
endfunction
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
JASS:
 local real manabefore=GetUnitState(caster,UNIT_STATE_MANA)
call TriggerSleepAction(0.05)
set manaafter=GetUnitState(caster,UNIT_STATE_MANA)[/icode]
 
If nothing happens to his mana within that 0.05 wait, then when you calculate
[code=jass]set manaadd=(manabefore-manaafter)/2
You're going to get an extremely low number. Maybe the equation you want is

JASS:
set manadd=(manaafter - (manabefore - manafter) ) / 2

JASS:
constant function Energy_Greed_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),'A62F')>0
endfunction
 
constant function ResourceT takes nothing returns string
    return "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
endfunction
 
function Energy_Greed_Actions takes nothing returns nothing
 local unit u=GetTriggerUnit()
 local integer level=GetUnitAbilityLevel(u,'A62F')
 local real x=GetUnitState(u,UNIT_STATE_MANA)
 local real y
    call TriggerSleepAction(.05)
    set y=GetUnitState(u,UNIT_STATE_MANA)
    call TriggerSleepAction(.02)
    set y=(y-(x-y))/2
    if GetRandomInt(1,10)<=level then
        call SetUnitState(u,UNIT_STATE_MANA,(GetUnitState(u,UNIT_STATE_MANA)+y))
        call DestroyEffect(AddSpecialEffect(ResourceT(),GetUnitX(u),GetUnitY(u)))
    endif
   set u=null 
endfunction
 
function InitTrig_Energy_Greed takes nothing returns nothing
    local trigger T = CreateTrigger()
    call SpellEvent( T )
    call TriggerAddAction(T,function Energy_Greed_Conditions)
    call TriggerAddCondition(T,Condition(function Energy_Greed_Actions))
    set T = null
endfunction
 
Last edited:
Level 22
Joined
Dec 31, 2006
Messages
2,216
That's because the caster is paused. I'll bet you don't get cooldown either. Make sure the event is EVENT_PLAYER_UNIT_SPELL_FINISH. I think maybe ...SPELL_EFFECT works too.


DSG, constant functions can't return non-constant values. If you try to make that in the world editor it will tell you it can't call a non-constant function inside a constant one.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
OK the problem was that I messed up the actions/conditions, I told the code that the actions were the cond's and vice/versa.

Here, this trigger registers the "unit begins casting" instead of "unit starts effect". Unit begins casting will account for the caster's mana before the spell - "Starts effect" (what you had) accounts after the mana has been lost.

JASS:
constant function EGreedCond takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),'A62F') > 0
endfunction
constant function EGreedPath takes nothing returns string
    return "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
endfunction
function EGreedActions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real mana = GetUnitState(u,UNIT_STATE_MANA)
    local real new
    local real Dbg
    call TriggerSleepAction(.7)
    set new = GetUnitState(u,UNIT_STATE_MANA)
    set Dbg = mana - new / 2
    if GetRandomInt(1,10) <= GetUnitAbilityLevel(u,'A62F') and Dbg > 0 then
        call SetUnitState(u,UNIT_STATE_MANA, Dbg + new)
        call DestroyEffect(AddSpecialEffectTarget(EGreedPath(),u,"origin")
    endif
    set u = null
endfunction
 
function InitTrig_Energy_Greed takes nothing returns nothing
    local trigger T = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(T,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddAction(T,function EGreedActions)
    call TriggerAddCondition(T,Condition(function EGreedCond))
    set T = null
endfunction

I added a checker that makes sure the unit's mana doesn't get subtracted (in the event of he uses a potion of mana)
 
Last edited:
Status
Not open for further replies.
Top