• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Problem with "Nova" (JASS)

Status
Not open for further replies.
Level 1
Joined
Apr 9, 2004
Messages
1
The spell is casted on an unit, after that circles are created around the unit (each circle is bigger than the previous one)

the problem is, that the action
JASS:
call GroupAddUnitSimple( GetLastCreatedUnit(), dmgUnits)
is not exectued, so the loop stops after the first sfx

JASS:
function Trig_HS_Stike_of_Light_JASS_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00J' ) ) then
        return false
    endif
    return true
endfunction

function Trig_HS_Stike_of_Light_JASS_Func005002 takes nothing returns nothing
    call IssuePointOrderLocBJ( GetEnumUnit(), "selfdestruct", GetUnitLoc(GetEnumUnit()) )
endfunction

function Trig_HS_Stike_of_Light_JASS_Actions takes nothing returns nothing

    local integer spellLevel
    local integer loopOuterIndex
    local integer loopInnerIndex
    local group dmgUnits
    local location targetPoint
    local unit caster
    local effect array dmgEffects

    set spellLevel = GetUnitAbilityLevelSwapped('A00J', GetSpellAbilityUnit())
    set targetPoint = GetSpellTargetLoc()
    set caster = GetSpellAbilityUnit()
    set loopOuterIndex = 0

    loop
        exitwhen loopOuterIndex > 5

        set loopInnerIndex = 0

        loop
            exitwhen loopInnerIndex > 8

            call AddSpecialEffectLocBJ( PolarProjectionBJ(targetPoint, ( 50.00 * loopOuterIndex ), ( 40.00 * loopInnerIndex )), "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl" )    
            set dmgEffects[( ( 9 * loopOuterIndex ) + loopInnerIndex )] = GetLastCreatedEffectBJ()            
            call CreateNUnitsAtLoc( 1, udg_E_HS_SoL_DmgEinheiten[spellLevel], GetOwningPlayer(caster), PolarProjectionBJ(targetPoint, ( 25.00 + ( I2R(loopOuterIndex) * 50.00 ) ), ( I2R(loopInnerIndex) * 40.00 )), bj_UNIT_FACING )           
            call GroupAddUnitSimple(GetLastCreatedUnit(),dmgUnits)        
            set loopInnerIndex = loopInnerIndex + 1
            

        endloop

        //call PolledWait( 0.00 )
        set loopOuterIndex = loopOuterIndex + 1

    endloop

    call PolledWait( 0.20 )
    call ForGroupBJ( dmgUnits, function Trig_HS_Stike_of_Light_JASS_Func005002 )
    call GroupClear( dmgUnits )
    call PolledWait( 1.00 )

    set loopOuterIndex = 0

    loop
        exitwhen loopOuterIndex > 64
        call DestroyEffectBJ( dmgEffects[loopOuterIndex] )
        set loopOuterIndex = loopOuterIndex + 1
    endloop

endfunction

//===========================================================================
function InitTrig_HS_Stike_of_Light_JASS takes nothing returns nothing
    set gg_trg_HS_Stike_of_Light_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_HS_Stike_of_Light_JASS, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_HS_Stike_of_Light_JASS, Condition( function Trig_HS_Stike_of_Light_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_HS_Stike_of_Light_JASS, function Trig_HS_Stike_of_Light_JASS_Actions )
endfunction
 
Level 2
Joined
Apr 13, 2004
Messages
29
You never initialised that group variable. And accessing an uninitialised variable ends the thread.
Use CreateGroup() to put an actual group object in that variable.
 
Level 17
Joined
Sep 29, 2003
Messages
580
The first condition does not look very nice. Its 1:1 what WE makes when converting a trigger to jass.
Better and shorter is:
JASS:
function Trig_HS_Stike_of_Light_JASS_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A00J' )
endfunction
For the UnitGroup action you're leaking a location. Another tip: Don't use the BJ functions. They are useless because they just rearrange the variables and call the native function. You can for example write the function like this ( i used the native IssuePointOrderLoc function instead of IssuePointOrderLocBJ):
JASS:
function Trig_HS_Stike_of_Light_JASS_Func005002 takes nothing returns nothing
    local location l = GetUnitLoc(GetEnumUnit())
    call IssuePointOrderLoc( GetEnumUnit(), "selfdestruct", l )
    call RemoveLocation(l)
endfunction
If you want to directly implement a unitgroup loop into your trigger there's a neat trick where you dont need to call a new function.
Instead of calling the function
JASS:
call ForGroupBJ( dmgUnits, function Trig_HS_Stike_of_Light_JASS_Func005002 )
you can use the following code:
JASS:
// new local variables
local unit dmgUnit
local location l
// this as replacement for 
// call ForGroupBJ( dmgUnits, function Trig_HS_Stike_of_Light_JASS_Func005002 )
// call GroupClear( dmgUnits )
set dmgUnit = FirstOfGroup(dmgUnits)
loop
    exitwhen dmgUnit == null
    set l = GetUnitLoc(dmgUnit)
    call IssuePointOrderLoc( dmgUnit, "selfdestruct", l )
    call RemoveLocation(l)
    call GroupRemoveUnitSimple(dmgUnit,dmgUnits)
    set dmgUnit = FirstOfGroup(dmgUnits)
endloop
As you see you can now use all the local variables from your Trig_HS_Stike_of_Light_JASS_Actions function and got rid of 1 function.

Now we come to the main function. The "Trig_HS_Stike_of_Light_JASS_Actions".
First of all why not directly format the local variables? makes the code shorter as well. Then you forgot to create the Group object. Groups need to get initialized with CreateGroup() before used.
Then you use a lot of BJ functions which are useless. The native ones are better and allow directly to return the desired variable type. For example look how i changed "AddSpecialEffectLocBJ" (beside.. leaking a lot locations there as well). CreateNUnitsAtLoc is also a Blizzard.j funtion. Better use the native one.
Sidenote: you dont need I2R because integers get autoconverted to reals if it needs a real value. But the other way round you need R2I.
JASS:
function Trig_HS_Stike_of_Light_JASS_Actions takes nothing returns nothing
    local unit         caster         = GetSpellAbilityUnit()
    local integer      spellLevel     = GetUnitAbilityLevelSwapped('A00J', caster)
    local location     targetPoint    = GetSpellTargetLoc()
    local group        dmgUnits       = CreateGroup()
    local integer      loopOuterIndex = 0
    local integer      loopInnerIndex
    local effect array dmgEffects

    loop
        exitwhen loopOuterIndex > 5
        set loopInnerIndex = 0
        loop
            exitwhen loopInnerIndex > 8
            set l = PolarProjectionBJ(targetPoint, 50.00 * loopOuterIndex , 40.00 * loopInnerIndex )
            set dmgEffects[( ( 9 * loopOuterIndex ) + loopInnerIndex )] = AddSpecialEffectLoc("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", l)
            call RemoveLocation(l)
            set l = PolarProjectionBJ(targetPoint, 25.00 + (loopOuterIndex * 50.00 ), loopInnerIndex * 40.00)
            call GroupAddUnitSimple( CreateUnitAtLoc(GetOwningPlayer(caster), udg_E_HS_SoL_DmgEinheiten[spellLevel], l, bj_UNIT_FACING), dmgUnits)
            call RemoveLocation(l)         
            set loopInnerIndex = loopInnerIndex + 1
        endloop
        call PolledWait( 0.00 )
        set loopOuterIndex = loopOuterIndex + 1
    endloop
    call PolledWait( 0.20 )
    call ForGroupBJ( dmgUnits, function Trig_HS_Stike_of_Light_JASS_Func005002 )
    call GroupClear( dmgUnits )
    call PolledWait( 1.00 )
    set loopOuterIndex = 0
    loop
        exitwhen loopOuterIndex > 64
        call DestroyEffect( dmgEffects[loopOuterIndex] )
        set loopOuterIndex = loopOuterIndex + 1
    endloop
endfunction

Hope those tips help

Darky27
 
Status
Not open for further replies.
Top