• 🏆 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!

[vJASS] multiple structs in one trigger usage

Status
Not open for further replies.
Level 5
Joined
Sep 16, 2008
Messages
47
I got a simple question.

I don't know is there is other way for that because i am using CTL.
Some spells require more than one loop like spells where in one loop units are spawned and in second that units are moving.

Is it correct way for that?

JASS:
scope example

    globals
        private constant integer    SPELL_CODE              =   'A000'
        private constant integer    DUMMY_CODE              =   'h000'
        private constant integer    AMMOUT                  =   10
        private constant real       DISTANCE                =   700
        private constant real       SPEED                   =   20
    endglobals
    
    private struct A
    
        private static unit array caster
        private static player array owner
        
        private static real array targetx
        private static real array targety
        
        private static integer array ammout
    
        implement CTL
        
            local real cx
            local real cy
            local real angle
            local unit dummy
        
        implement CTLExpire
        
            set cx = GetUnitX(caster[this])
            set cy = GetUnitY(caster[this])
            
            set angle = Atan2(targety[this] - cy, targetx[this] - cx)
            
            set dummy = CreateUnit(owner[this], DUMMY_CODE, cx, cy, angle * bj_RADTODEG)
            
            call B.onFire(dummy, angle)
            
            set ammout[this] = ammout[this] - 1
            
            if ammout[this] == 0 then
            
                set caster[this] = null
                set owner[this] = null
                call destroy()
            
            endif
        
        implement CTLNull
        implement CTLEnd
    
        private static method onCast takes nothing returns nothing
        
            local thistype this = create()
            
            set caster[this] = GetTriggerUnit()
            set owner[this] = GetTriggerPlayer()
            
            set targetx[this] = GetSpellTargetX()
            set targety[this] = GetSpellTargetY()
            
            set ammout[this] = AMMOUT
        
        endmethod
    
        private static method onInit takes nothing returns nothing
            call RegisterSpellEffectEvent(SPELL_CODE,function thistype.onCast)
        endmethod
    endstruct
    
    struct B
    
    private static unit array dummy
    
    private static real array distance
    private static real array angle
    
        implement CTL
        
            local real dx
            local real dy
            local real mx
            local real my
        
        implement CTLExpire
        
            set dx = GetUnitX(dummy[this])
            set dy = GetUnitY(dummy[this])
            
            set mx = dx + SPEED * Cos(angle[this])
            set my = dy + SPEED * Sin(angle[this])
            
            call SetUnitX(dummy[this], mx)
            call SetUnitY(dummy[this], my)
            
            set distance[this] = distance[this] - SPEED
            
            if distance[this] <= 0 then
            
                call KillUnit(dummy[this])
            
                set dummy[this] = null
                call destroy()
                
            endif
        
        implement CTLNull
        implement CTLEnd
    
        static method onFire takes unit d, real a returns nothing
        
            local thistype this = create()
        
            set dummy[this] = d
            set angle[this] = a
            set distance[this] = DISTANCE
        
        endmethod
    
    endstruct
endscope
 
Status
Not open for further replies.
Top