ForGroup and Local Problems

Chocobo

White-Flower
Reaction score
409
When I try to use ForGroup and Local Variables, it never worked. This Spell is supposed to Splash all units dealing BoltofFire[level] damage, it does 0 damage.

Code:
function Bolt_of_Fire_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A02Z' ) ) then
        return false
    endif
    return true
endfunction

function BoltOfFireCond1 takes nothing returns boolean
    if ( not ( distance < 270.00 ) ) then
        return false
    endif
    return true
endfunction

function BoltOfFireCond2 takes nothing returns boolean
    if ( not ( distance > 400.00 ) ) then
        return false
    endif
    return true
endfunction

function BoltOfFireCond3 takes nothing returns boolean
    return ( IsUnitVisible(unit, GetFilterPlayer()) == true )
endfunction

function Bolt_of_Fire_Actions takes nothing returns nothing
    local real distance
    local real totaldistance
    local unit unit
    local unit dummy
    local integer level
    local effect sfx
    set level = GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetTriggerUnit())
    set unit = GetSpellTargetUnit()
    set position1 = GetUnitLoc(GetTriggerUnit())
    set position2 = GetUnitLoc(unit)
    set distance = DistanceBetweenPoints(position1, position2)
    if ( BoltOfFireCond1() ) then
        call DisplayTimedTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), 10.00, "TRIGSTR_1724" )
        return
    else
        set totaldistance = distance
    endif
    call TriggerSleepAction( ( distance / 1000.00 ) )
    set position1 = GetUnitLoc(unit)
    set distance = DistanceBetweenPoints(position1, position2)
    if ( BoltOfFireCond2() ) then
        call DisplayTimedTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), 10.00, "TRIGSTR_1725" )
    else
    endif
    call CreateNUnitsAtLoc( 1, 'e002', GetTriggerPlayer(), position1, 0.00 )
    set dummy = GetLastCreatedUnit()
    call SetUnitAbilityLevelSwapped( 'A030', dummy, level )
    call IssueImmediateOrderBJ( dummy, "stomp" )
    call AddSpecialEffectLocBJ( position1, "war3mapImported\\nuke.mdx" )
    set sfx = GetLastCreatedEffectBJ()
    call CreateTextTagLocBJ( ( "Explosion! (" + ( I2S(BoltOfFireDmg[level]) + " dmg!)" ) ), point, 0, 6.00, 0.00, 100, 0.00, 0 )
    call ForGroupBJ(GetAllUnits(150.00, (GetTriggeringUnit()), function SourceDamage) //GetAllUnits(150.00, GetTriggeringUnit()) means all units in 150 range of triggering unit, SourceDamage means to damage the target by level.
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetPlayersMatching(Condition(function BoltOfFireCond3)) )
    call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 64, 90 )
    call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
    call SetTextTagFadepointBJ( GetLastCreatedTextTag(), 1.00 )
    call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 3.00 )
    set level = 0
    set unit = null
    set distance = 0.00
    set totaldistance = 0.00
    call TriggerSleepAction( 1.00 )
    call RemoveUnit( dummy )
    set dummy = null
    call TriggerSleepAction( 5.00 )
    call DestroyEffectBJ( sfx )
endfunction

//===========================================================================
function InitBolt_of_Fire takes nothing returns nothing
    set Bolt_of_Fire = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Bolt_of_Fire, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( Bolt_of_Fire, Condition( function Bolt_of_Fire_Conditions ) )
    call TriggerAddAction( Bolt_of_Fire, function Bolt_of_Fire_Actions )
endfunction
 

wonderpriest

New Member
Reaction score
18
Dude(ette?) this doesn't work at all. Take it back and fix! Don't use conditions for things you could do in in the if statement. Don't use undeclared variables...argh.
I can't even look at it >_>

:p I can fix for you if you'd like
 

SFilip

Gone but not forgotten
Reaction score
634
lets start...from the beginning ;)
Code:
function Bolt_of_Fire_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A02Z' ) ) then
        return false
    endif
    return true
endfunction
should be
Code:
function Bolt_of_Fire_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A02Z'
endfunction

Code:
function BoltOfFireCond1 takes nothing returns boolean
    if ( not ( distance < 270.00 ) ) then
        return false
    endif
    return true
endfunction

function BoltOfFireCond2 takes nothing returns boolean
    if ( not ( distance > 400.00 ) ) then
        return false
    endif
    return true
endfunction
not needed.

Code:
function BoltOfFireCond3 takes nothing returns boolean
    return ( IsUnitVisible(unit, GetFilterPlayer()) == true )
endfunction
this is where the problem is i guess. locals only work in the function you declared them in. no exceptions. however
Code:
function BoltOfFireCond3 takes nothing returns boolean
    return ( IsUnitVisible(GetSpellTargetUnit(), GetFilterPlayer()) == true )
endfunction
should work well.

moving on.
Code:
    local real distance
    local real totaldistance
    local unit unit
    local unit dummy
    local integer level
    local effect sfx
    set level = GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetTriggerUnit())
    set unit = GetSpellTargetUnit()
    set position1 = GetUnitLoc(GetTriggerUnit())
    set position2 = GetUnitLoc(unit)
    set distance = DistanceBetweenPoints(position1, position2)
Code:
    local real distance = DistanceBetweenPoints(position1, position2)
    local real totaldistance
    local unit unit = GetSpellTargetUnit()
    local unit dummy
    local integer level = GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetTriggerUnit())
    local effect sfx
    local location position1 = GetUnitLoc(GetTriggerUnit())
    local location position2 = GetUnitLoc(unit)
not sure if position1 and position2 were global since you said no udg_ so now they are local.

Code:
    if ( BoltOfFireCond1() ) then
now we use the condition directly
Code:
    if ( distance < 270.00 ) then

Code:
    if ( BoltOfFireCond2() ) then
Code:
    if ( distance > 400.00 ) then

and finally on the very end remove and null local locations.
Code:
    call RemoveLocation(position1)
    call RemoveLocation(position2)
    set position1 = null
    set position2 = null
 

wonderpriest

New Member
Reaction score
18
And after you make it work, you optimize. Preloading effects maybe, using real coordinates instead of locs (no bjs or cleanup). STOP using BJs, reuse locals and take advantage of never used bj_ variables and make the math more effiecient.

In other words, pull out Jasscraft and make this script look nice :)
 

Chocobo

White-Flower
Reaction score
409
Looks better now, no?

Code:
function Bolt_of_Fire_Conditions takes nothing returns boolean
return(GetSpellAbilityId()=='A02Z')
endfunction
function BoltOfFireCond1 takes nothing returns boolean
return(distance<270.)
endfunction
function BoltOfFireCond2 takes nothing returns boolean
return(distance>400.)
endfunction
function BoltOfFireCond3 takes nothing returns boolean
return(IsUnitVisible(unit,GetFilterPlayer()))
endfunction
function Bolt_of_Fire_Actions takes nothing returns nothing
local real distance
local real totaldistance
local unit unit
local unit dummy
local integer level
local effect sfx
set level=GetUnitAbilityLevelSwapped(GetSpellAbilityId(),GetTriggerUnit())
set unit=GetSpellTargetUnit()
set position1=GetUnitLoc(GetTriggerUnit())
set position2=GetUnitLoc(unit)
set distance=DistanceBetweenPoints(position1,position2)
if(BoltOfFireCond1())then
call DisplayTimedTextToForce(GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())),10.,"TRIGSTR_1724")
return
else
set totaldistance=distance
endif
call TriggerSleepAction((distance/1000.))
set position1=GetUnitLoc(unit)
set distance=DistanceBetweenPoints(position1,position2)
if(BoltOfFireCond2())then
call DisplayTimedTextToForce(GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())),10.,"TRIGSTR_1725")
endif
call CreateNUnitsAtLoc(1,'e002',GetTriggerPlayer(),position1,.0)
set dummy=bj_lastCreatedUnit
call SetUnitAbilityLevelSwapped('A030',dummy,level)
call IssueImmediateOrderById(dummy,852127)
call AddSpecialEffectLocBJ(position1,"war3mapImported\\nuke.mdx")
set sfx=bj_lastCreatedEffect
call CreateTextTagLocBJ(("Explosion! ("+(I2S(BoltOfFireDmg[level])+" dmg!)")),point,0,6.,.0,'d',.0,0)
call ForGroupBJ(GetAllUnits(150.,(GetTriggeringUnit()),function SourceDamage)
call ShowTextTagForceBJ(true,bj_lastCreatedTextTag,GetPlayersMatching(Condition(function BoltOfFireCond3)))
call SetTextTagVelocityBJ(bj_lastCreatedTextTag,64,90)
call SetTextTagPermanentBJ(bj_lastCreatedTextTag,false)
call SetTextTagFadepointBJ(bj_lastCreatedTextTag,1.)
call SetTextTagLifespanBJ(bj_lastCreatedTextTag,3.)
set level=0
set unit=null
set distance=.0
set totaldistance=.0
call TriggerSleepAction(1.)
call RemoveUnit(dummy)
set dummy=null
call TriggerSleepAction(5.)
call DestroyEffect(sfx)
endfunction
function InitBolt_of_Fire takes nothing returns nothing
set Bolt_of_Fire=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(Bolt_of_Fire,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(Bolt_of_Fire,Condition(function Bolt_of_Fire_Conditions))
call TriggerAddAction(Bolt_of_Fire,function Bolt_of_Fire_Actions)
endfunction
 

SFilip

Gone but not forgotten
Reaction score
634
why are you still using locals in functions they aren't declared in? :nuts:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top