local variable arrays and unit groups

Cohadar

master of fugue
Reaction score
209
Learn to use groups, they are better than local arrays in every way possible.
 

Cohadar

master of fugue
Reaction score
209
JASS:
scope FrostBolt

globals
    private constant integer AID_AREA_FROST_BOLT = 'A002'
    private constant integer AID_DUMMY_FROST_BOLT = 'A000'
endglobals

private function EnemyCondition takes nothing returns boolean
    return IsUnitAliveBJ(GetFilterUnit()) and IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit()))
endfunction

// must match AOE fields of AID_AREA_FROST_BOLT in object editor
private function AOE takes integer level returns real
    return 200.0 + 50.0 * level
endfunction

//===========================================================================
private function Actions takes nothing returns nothing
    local group g = NewGroup() // Recycler
    local location temp = GetSpellTargetLoc()
    local unit hero = GetTriggerUnit()
    
    local Caster_Data cdata = Caster_Data.create(hero)
    set cdata.height = GetUnitFlyHeight(hero)
    set cdata.abilityId = AID_DUMMY_FROST_BOLT
    set cdata.orderId = OID_thunderbolt
    set cdata.level = GetUnitAbilityLevel(hero, AID_AREA_FROST_BOLT)
    
    call GroupEnumUnitsInRange(g, GetLocationX(temp), GetLocationY(temp), AOE(cdata.level), Condition(function EnemyCondition))
    
    call cdata.castOnGroup(g, false)
    
    call cdata.destroy()
    call RemoveLocation(temp)
    call ReleaseGroup(g) // Recycler
    
    set g = null
    set hero = null
    set temp = null
endfunction

//===========================================================================
private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == AID_AREA_FROST_BOLT
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


Frost Bolt Area spell from Pyramidal Defence.
It has all you need.
 

Cohadar

master of fugue
Reaction score
209
Many things are possible in jass,
but I recommend you make it a private function.
PS: if you need to pass variables to the filter: for example the owner of triggering unit
You can:
A: call them directly in filter
JASS:
    private function GroupFilter takes nothing returns boolean
        return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())
    endfunction


B: pass them in a variable
JASS:
    globals
        private player filter_owner
    endglobals
    private function GroupFilter takes nothing returns boolean
        return IsUnitEnemy(GetFilterUnit(), filter_owner)
    endfunction


Of course you need to set filter_owner before you call GroupEnumUnit... functions
 

Cohadar

master of fugue
Reaction score
209
Put the units in a group.
Put the group in a struct
Use the timer...
 

Flare

Stops copies me!
Reaction score
662
i understand the first bit, not rly sure on how to do the second bit (back to andrewgosu's tut i guess) and third sounds simple enough. only thing is that i want to assign varying distance for each unit depending on how close it is to the dummy unit i.e. 100 dist away from dummy will push a short distance, but 50 dist from dummy would push it about double the distance
 

Tom Jones

N/A
Reaction score
437
JASS:
struct SomeData
    group g
endstruct

function ...
    local SomeData d = SomeData.create()
    local group g
 
    //Set up your group
    set d.g = g 
endfunction
 

Cohadar

master of fugue
Reaction score
209
Then you have to use arrays

JASS:
private struct Data
    unit array Target[100]
    real array Distance[100]
    real array Angle[100]
    integer N // Number of units in arrays
endstruct


Of course you could always do it this way:
JASS:
private struct Data
    unit target
    real distance
    real angle
endstruct

//...... make struct for every unit (in a ForGroup)
Data array dataz[100]

//...... and send every struct to TT
set i = N-1
loop
    exitwhen i<0   
    call TT_Start(function Handler, dataz<i>)
    set i = i - 1
endloop
</i>


Witch will also use only one timer.
 

Flare

Stops copies me!
Reaction score
662
so, that will allow for 100 units to be moved for every instance of the spell? or 100 units between all current instances

JASS:
//...... make struct for every unit (in a ForGroup)

so, make a unit group loop, then create a struct within the loop?


JASS:
set i = N-1

ahm, does that go in the ForGroup thingy after the struct data. and i dont see anything else with N in it so wont it always the same value?
 

Cohadar

master of fugue
Reaction score
209
Look you are trying to make something like a Nova spell right?
Just make the damn basic code and post it so I have something to work on.
It is easier for me to correct you that to imagine what you want to do.
 
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