Help me : Group doesn't work

tuantai120

Cool Member
Reaction score
1
I've just made this spell , i have a problem in my code that picked unit doesn't move or be damaged
this is my code :
JASS:
scope tornado initializer Init

globals
    private constant integer SID = 'A001'
    private constant integer DID = 'h000'
    private constant string SFX = "Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl"
    private constant real Period = 0.04
endglobals

private function Damage_dealt takes integer lvl returns real
        return 100.00 * lvl
endfunction

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

private struct tor
    unit cast
    unit c
    real angle
    integer tick
    real distance
    string sfx
    group g
endstruct

private function TornadoT takes nothing returns nothing
    local timer ti = GetExpiredTimer()
    local tor data = GetTimerData( ti )
    local unit p
    local real x = GetUnitX(data.c)
    local real y = GetUnitY(data.c)
    local real xx = GetPPX( x, data.distance, data.angle )
    local real yy = GetPPY( y, data.distance, data.angle )
    local real px
    local real py
    local real pxx
    local real pyy
    call DestroyEffect(AddSpecialEffect(SFX,xx,yy))
    call SetUnitPosition(data.c,xx,yy)
    call GroupEnumUnitsInRange(data.g,x,y,200,null)
    loop
        set p = FirstOfGroup(data.g)
        exitwhen p == null
        call GroupRemoveUnit(data.g,p)
        if IsUnitEnemy(p,GetOwningPlayer(data.cast)) == true then
            set px = GetUnitX(p)
            set py = GetUnitY(p)
            set pxx = GetPPY( px , data.distance , data.angle)
            set pyy = GetPPY( py , data.distance , data.angle )
            call SetUnitPosition(p,pxx,pyy)
            call UnitDamageTarget(data.c,p,Damage_dealt,false,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNIVERSAL,WEAPON_TYPE_WHOKNOWS)
        endif
    endloop
    set data.tick = data.tick - 1
    if data.tick <= 0 then
        call RemoveUnit(data.c)
        call ReleaseTimer(ti)
        call data.destroy()
    endif
    set p = null
    set ti = null
endfunction

private function Actions takes nothing returns nothing
    local tor data = tor.create()
    local timer ti = NewTimer()
    local unit u = GetTriggerUnit()
    local unit du
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real xx = GetSpellTargetX()
    local real yy = GetSpellTargetY()
    local real angle = AngleXY(x,y,xx,yy)
    local real distance = 40
    set du = CreateUnit(GetOwningPlayer(u),DID,x,y,angle)
    call SetTimerData(ti,data)
    set data.cast = u
    set data.c = du
    set data.angle = angle
    set data.tick = 25
    set data.distance = distance
    call TimerStart(ti,Period,true,function TornadoT)
    set u = null
    set du = null
endfunction

private function Init takes nothing returns nothing
    local trigger use = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( use , EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( use , Condition( function Conditions ) )
    call TriggerAddAction( use , function Actions )
    set use = null
endfunction
endscope
 

Attachments

  • BasicOfStruct.w3x
    23.4 KB · Views: 132

BlackRose

Forum User
Reaction score
239
Post JASS scripts in [noparse]
JASS:
[/noparse] tags....

Ok, your problem is probably that [ljass]data.g[/ljass] is not existent, you have not created a group, do so by [ljass]set data.g = CreateGroup()[/ljass].
 

Executor

I see you
Reaction score
57
Seems like you didn't initialize the group.
JASS:
set .g = CreateGroup()


By the way, this method here is faster:

JASS:
globals 
   group GROUP = CreateGroup()
endglobals

struct someStruct
   thistype enumInstance
   // vars
   private static boolexpr enumUnitsCond
   static method enumUnits takes nothing returns boolean
      call KillUnit(GetFilterUnit())
   endmethod
   private static method onInit takes nothing returns nothing
      set .enumUnitsCond = Condition(function thistype.enumUnits)
   endmethod
   static method onTimer takes nothing returns nothing
      local thistype this = GetTimerData(GetExpiredTimer())
      set .enumInstance = this
      call GroupEnumUnitsInRange(GROUP,.x,.y,500.,.enumUnitsCond)
   endmethod
endstruct
 

Executor

I see you
Reaction score
57
JASS:
local tor    data      = GetTimerData( ti )
local real   x         = 0.
local $TYPE$ $VARNAME$ = $VALUEOFTYPE$


He could only use [lJASS]tor.[/lJASS] if he wanted to access something static.
 
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