• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Group Add Group

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
Help!! Argh Going Nuts!!!

this code is driving me nuts nothing is going as i want!

ok this is what i got so far but there is a problem after u have casted this sometimes the dummy unit will only how for like 0.1 sec, and after somemore cast it wont even show...(code is a mess atm)

oh one more thing is there something better then call GroupAddGroup(dat.g,g)?

JASS:
scope ZhaosBomb initializer Init

globals
    private constant integer Abil_id = 'A005'
    private constant integer Slow_id = 'A006'
    private constant integer Dum_caster = 'h000'
    private constant integer Dum = 'h006'
endglobals

private struct Data
unit c
unit t
unit dum

real x
real y
real angle
real cos
real sin
real distbetween
real dist

integer count

group g

timer time

    method onDestroy takes nothing returns nothing
        call PauseTimer(.time)
        call ClearTimerStructA(.time)
        call DestroyTimer(.time)
    endmethod
    
endstruct

private function Stop takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Data dat = GetTimerStructA(t)
    
    call PauseTimer(t)
    call ClearTimerStructA(t)
    call DestroyTimer(t)
    
    call dat.destroy()
endfunction

private function Check takes nothing returns nothing
    local Data dat = GetTimerStructA(GetExpiredTimer())
    local unit d
    local group g = CreateGroup()
    local real dist
    local real ux
    local real uy
    
    call GroupAddGroup(dat.g,g)
    
    loop
        set d = FirstOfGroup(g)
        exitwhen d == null
        call GroupRemoveUnit(g,d)
        set ux = GetUnitX(d)
        set uy = GetUnitY(d)
        if SquareRoot((dat.x-ux)*(dat.x-ux)+(dat.y-uy)*(dat.y-uy)) >= 400 then
            call UnitDamageTarget(dat.c,d,50,false,false,null,null,null)
            call GroupRemoveUnit(dat.g,d)
            call UnitRemoveAbility(d,'Bslo')
        endif
    endloop
    call DestroyGroup(g)
    set g = null
endfunction

private function Wait takes nothing returns nothing
    local Data dat = GetTimerStructA(GetExpiredTimer())
    local unit d
    local group g = CreateGroup()
    local unit dum
    local player p = GetOwningPlayer(dat.c)
    local timer t = CreateTimer()
    
    set dat.g = CreateGroup()
    call PauseTimer(dat.time)
    call GroupEnumUnitsInRange(g,dat.x,dat.y,200,null)
    
    loop
        set d = FirstOfGroup(g)
        exitwhen d == null
        call GroupRemoveUnit(g,d)
        call GroupAddUnit(dat.g,d)
        set dum = CreateUnit(p,Dum_caster,dat.x,dat.y,0.)
        call UnitAddAbility(dum,Slow_id)
        call IssueTargetOrder(dum,"slow",d)
        call UnitApplyTimedLife(dum,'BTLF',2.)
        set dum = null
    endloop
    call SetTimerStructA(t,dat)
    call TimerStart(t,4.,false,function Stop)
    call TimerStart(dat.time,.5,true,function Check)
    
    call DestroyGroup(g)
    set g = null
    set t = null
    set p = null
endfunction
        
private function Move takes nothing returns nothing
    local Data dat = GetTimerStructA(GetExpiredTimer())
    local real x = GetUnitX(dat.dum)+20*dat.cos
    local real y = GetUnitY(dat.dum)+20*dat.sin
    local group g
    local unit d
    
    set dat.dist = dat.dist + 20
    
    if dat.dist < dat.distbetween then
        call SetUnitFlyHeight(dat.dum,JumpParabola(dat.dist,dat.distbetween,6.),0.)
        call SetUnitX(dat.dum,x)
        call SetUnitY(dat.dum,y)
    else
        set g = CreateGroup()
        call RemoveUnit(dat.dum)
        call PauseTimer(dat.time)
        call GroupEnumUnitsInRange(g,dat.x,dat.y,200.,null)
        loop
            set d = FirstOfGroup(g)
            exitwhen d == null
            call GroupRemoveUnit(g,d)
            call UnitDamageTarget(dat.c,d,100,false,false,null,null,null)
        endloop
        call TimerStart(dat.time,1.,false,function Wait)
        call DestroyGroup(g)
    endif
    set g = null
endfunction
    
private function Actions takes nothing returns nothing
    local Data dat = Data.create()
    local location loc = GetSpellTargetLoc()
    local real x
    local real y
    
    set dat.c = GetTriggerUnit()
    set x = GetUnitX(dat.c)
    set y = GetUnitY(dat.c)
    set dat.x = GetLocationX(loc)
    set dat.y = GetLocationY(loc)
    set dat.distbetween = SquareRoot((dat.x-x)*(dat.x-x)+(dat.y-y)*(dat.y-y))
    set dat.angle = Atan2(dat.y-y,dat.x-x)*57.27589
    set dat.cos = Cos(dat.angle*3.14159/180)
    set dat.sin = Sin(dat.angle*3.14159/180)
    set dat.time = CreateTimer()
    set dat.dum = CreateUnit(GetOwningPlayer(dat.c),Dum,x+50*dat.cos,y+50*dat.sin,0.)
    call SetTimerStructA(dat.time,dat)
    call TimerStart(dat.time,.035,true,function Move)
    call RemoveLocation(loc)
    set loc = null
endfunction

private function Conds takes nothing returns boolean
    return GetSpellAbilityId()==Abil_id
endfunction
    
public function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t,function Actions)
    call TriggerAddCondition(t,Filter(function Conds))
endfunction

endscope
 
oh one more thing is there something better then call GroupAddGroup(dat.g,g)?

WHat do you need that for ?
Also please, don't do like the other guys ... variables have a name for a reason, DON'T GIVE STUPID USELESS NAMES to them like U, V, Z, W or whatever ... that makes the code very hard to read.
=P

JASS:
method onDestroy takes nothing returns nothing
        call PauseTimer(.time)
        call ClearTimerStructA(.time)
        call DestroyTimer(.time)
    endmethod
It makes more sense to do
call PauseTimer(.time)
call DestroyTimer(.time)
call ClearTimerStructA(.time)

I dunno if this can affect something, but i think you can't destroy something pointing to null. Not sure though

I see you use multiple timers... maybe you should consider using the attach B and C.
I g2g now, but i'll see what I can do later.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
I think that using timers inside structs ang getting the structs by them is a bit buggy.

JASS:
method onDestroy takes nothing returns nothing
        call PauseTimer(.time)
        call ClearTimerStructA(.time)
        call DestroyTimer(.time)
    endmethod
It makes more sense to do
call PauseTimer(.time)
call DestroyTimer(.time)
call ClearTimerStructA(.time)

That made no sense 0.o
If you destroy the timer, how can you destroy the things attached to it ? It's exactly like a pointer. If you destroy a location var you cannot remove the location.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Ciebron, in this case, as opposed to GroupAddGroup you can use:

JASS:
local unit u
loop
    //we have 2 groups, g and g2. While using g we want to copy to g2
    set u = FirstOfGroup(g)
    exitwhen u == null
    //do stuff
    call GroupRemoveUnit(g,u)
    call GroupAddUnit(g2,u)
endloop
call DestroyGroup(g)
//set g = g2 if you want
 
Status
Not open for further replies.
Top