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
 
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
 
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
 
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 :)
 
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
 
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.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top