System TE - SFX-system

Trollvottel

never aging title
Reaction score
262
Description:
Creates a ring of dummys which is turnable and movable in x,y and z direction.

CODE:
JASS:

library TE initializer Init uses TT

globals
    // Maximum of Units each Figure
    private constant integer MAXUNITS = 40

endglobals


// put in desired custom struct members or methods (only advanced)
//! textmacro TEStructMembers
    
//! endtextmacro

// this will be done everytime the timer runs (only advanced)
//! textmacro TEPeriodic

//! endtextmacro


// dont edit below!

globals
    private constant real RTD = 57.29577951
    private constant real DTR = 0.017353292
    private  real MaxX
    private  real MaxY
    private  real MinX
    private  real MinY
    private location loc
    private boolexpr AliveFilter

endglobals

    private function DistanceBetweenCoords takes real x0, real y0, real z0, real x1, real y1, real z1 returns real
        local real x = x1 - x0
        local real y = y1 - y0
        local real z = z1 - z0
        return SquareRoot ( ( x * x ) + ( y * y ) + ( z * z ) )
    endfunction

    private function AngleBetweenCoordsB takes real x0, real y0, real z0, real x1, real y1, real z1 returns real
        local real x = x1 - x0
        local real y = y1 - y0
        local real z = z1 - z0
        return Atan2 ( z, SquareRoot ( ( x * x ) + ( y * y ) ) )
    endfunction
    
    private function SquareDistance takes real x0, real y0, real x1, real y1 returns real
        local real x = x1 - x0
        local real y = y1 - y0
        return ( x * x ) + ( y * y )
    endfunction  
    
    private function GetUnitZ takes unit whichUnit returns real
        call MoveLocation(loc,GetUnitX(whichUnit),GetUnitY(whichUnit)) 
        return GetLocationZ( loc ) + GetUnitFlyHeight( whichUnit ) 
    endfunction
    
     private function SetUnitZ takes unit whichUnit, real z returns nothing
        local boolean whichUnitHasNotAmrf = ( GetUnitAbilityLevel( whichUnit, 'Amrf' ) <= 0 )
        if ( whichUnitHasNotAmrf ) then
            call UnitAddAbility( whichUnit, 'Amrf' )
            call UnitRemoveAbility( whichUnit, 'Amrf' )
        endif
        call MoveLocation(loc, GetUnitX(whichUnit), GetUnitY(whichUnit))
        call SetUnitFlyHeight( whichUnit, z - GetLocationZ(loc), 0.00 )
    endfunction   
    
    private function SetSafeX takes unit which, real x returns nothing
        if x < MaxX then
            if x > MinX then
                call SetUnitX(which, x)
            else
                call SetUnitX(which,MinX)
            endif
        else
            call SetUnitX(which, MaxX)
        endif
    endfunction
    
    private function SetSafeY takes unit which, real y returns nothing
        if y < MaxY then
            if y > MinY then
                call SetUnitY(which,y)
            else
                call SetUnitY(which,MinY)
            endif
        else
            call SetUnitY(which, MaxY)
        endif
    endfunction

    private function AngleBetweenCoords takes real x0, real y0, real x1, real y1 returns real
        local real x = x1 - x0
        local real y = y1 - y0
        return Atan2 ( y, x )
    endfunction
   
// System begins:   

public struct Figure
    private real    TE_cx     
    private real    TE_cy
    private real    TE_cz
    private real    TE_radius
    private real    TE_nface
    private real    TE_zface
    private real    TE_offset
    private integer TE_number
    private unit    array TE_member[MAXUNITS]
    private real    array TE_sin[MAXUNITS]
    private real    array TE_cos[MAXUNITS]
    
    
    private boolean TE_zturning = false
    private real    TE_zturnage
    
    private boolean TE_nturning = false
    private real    TE_nturnage

    private boolean TE_attached = false
    private unit    TE_towhich
    
    private boolean TE_moving   = false
    private real    TE_wherex
    private real    TE_wherey
    private real    TE_wherez
    private real    TE_moverate
    
    private boolean TE_zset     = false
    private boolean TE_nset     = false
    
    private boolean TE_destroy  = false
    
    private boolean TE_expire   = false
    private real    TE_time     = 0.
    
    private real    TE_rchange  = 0
    private real    TE_wantedr  = 0
    private boolean TE_rchanging= false
    
    private boolean TE_hide     = true
    
    //! runtextmacro TEStructMembers()
    
        method GetX takes nothing returns real
            return .TE_cx
        endmethod
    
        method GetY takes nothing returns real
            return .TE_cy
        endmethod
    
        method GetZ takes nothing returns real
            return .TE_cz
        endmethod
        
        method GetZAngle takes nothing returns real
            return .TE_zface
        endmethod
        
        method GetNAngle takes nothing returns real
            return .TE_nface
        endmethod
        
        method GetRadius takes nothing returns real
            return .TE_radius
        endmethod
        
        method SetZAngle takes real Z returns nothing
            set .TE_zface = Z
            set .TE_zset = true
        endmethod
        
        method SetNAngle takes real N returns nothing
            set .TE_nface = N
            set .TE_nset = true
        endmethod
        
        method SetRadius takes real r returns nothing
            set .TE_radius = RAbsBJ(r)
            set .TE_nset = true
        endmethod
        
        method SetRadiusOverTime takes real r, real time returns nothing
            set .TE_wantedr = RAbsBJ(r)
            set .TE_rchange = (.TE_wantedr-.TE_radius) * TT_PERIOD / RMaxBJ(time, 0.001)
            set .TE_rchanging = true
            
        endmethod
        
         method StartZTurn takes real rate returns nothing
            set .TE_zturning = true
            set .TE_zturnage = rate * TT_PERIOD
        endmethod
        
        method StartNTurn takes real rate returns nothing
            set .TE_nturning = true
            set .TE_nturnage = rate * TT_PERIOD
        endmethod
 
        method Attach takes unit whichto returns nothing
            set .TE_attached = true
            set .TE_moving = false
            set .TE_towhich = whichto
            set .TE_cz = .TE_radius
        endmethod
        
        method UnAttach takes nothing returns nothing
            set .TE_attached = false
            set .TE_hide = true
        endmethod
        
        method MoveTo takes real x, real y, real z, real rate returns nothing
            set .TE_moverate = RAbsBJ(rate) * TT_PERIOD
            set .TE_wherex = x
            set .TE_wherey = y
            set .TE_wherez = z
            set .TE_attached = false
            set .TE_moving = true
        endmethod
        
        method SetPosition takes real x, real y, real z returns nothing
            set .TE_cx = x
            set .TE_cy = y
            set .TE_cz = z
            set .TE_nset = true
        endmethod
        
        method Destroy takes nothing returns nothing
            set .TE_destroy = true
        endmethod
        
        method SetExpirationTime takes real time returns nothing
            set .TE_expire = true
            set .TE_time = time
        endmethod
        
        method GetUnitsInRange takes nothing returns group
            local group g = CreateGroup()
            local group swap = CreateGroup()
            local unit u
            local real dx
            local real dy
            local real dz
            call GroupEnumUnitsInRange(g, .TE_cx, .TE_cy, .TE_radius, AliveFilter)
            
            loop
                set u = FirstOfGroup(g)
                exitwhen u == null
                call GroupRemoveUnit(g, u)
                
                set dx = GetUnitX(u) - .TE_cx
                set dy = GetUnitY(u) - .TE_cy
                set dz = GetUnitZ(u) - .TE_cz
                
                if dx*dx + dy*dy + dz*dz <= .TE_radius * .TE_radius then
                    call GroupAddUnit(swap, u)
                endif
            
            endloop
            call DestroyGroup(g)
            set g = null
            
            return swap
        endmethod
        
        static method create takes integer rawcode, player owner, real x, real y, real z, real radius, real nface, real zface, integer edges returns Figure
            local Figure init   = Figure.allocate()
            local real offset   
            local integer i     = 0
            local real      x0
            local real      y0
            local real      z0
            local real      zangle
            local real      height
            local real      angle
            local real      anglez
            local real      distance
            local real      x1
            local real      y1
            
            //save:
            if rawcode == 0 or rawcode == null then
                call BJDebugMsg("TE System Error: Null rawcode!")
            endif
            
            if owner == null then
                set owner = Player(15)
            endif
            
            set radius = RAbsBJ(radius)
            set edges = IAbsBJ(edges)
            
            //system:
            call MoveLocation(loc, x, y)
            set height = GetLocationZ(loc)
            
            set init.TE_cx         = x
            set init.TE_cy         = y
            set init.TE_cz         = z
            
            set init.TE_radius     = radius
            set init.TE_nface      = nface
            set init.TE_zface      = zface
            
            if edges <= MAXUNITS then
                set init.TE_number     = edges
            else
                set init.TE_number = MAXUNITS
            endif
            set offset = 360. / init.TE_number 
            set init.TE_offset = offset
            loop
                exitwhen i >= init.TE_number
                set zangle = offset  * i 
                set init.TE_cos<i> = Cos(zangle * DTR)
                set init.TE_sin<i> = Sin(zangle * DTR)
                set x0 = x           + radius * init.TE_cos<i> * Cos(zface * DTR)
                set y0 = y           + radius * init.TE_sin<i> 
                set z0 = init.TE_cz  + radius * init.TE_cos<i> * Sin(zface * DTR)
                
                set x1 = x0
                set y1 = y0
                
                set distance = SquareRoot(SquareDistance(x0, y0, init.TE_cx, init.TE_cy))
                set angle = AngleBetweenCoords(init.TE_cx, init.TE_cy, x0, y0) * bj_RADTODEG
                set x1 = init.TE_cx + distance * Cos( (angle+nface) * DTR ) 
                set y1 = init.TE_cy + distance * Sin( (angle+nface) * DTR ) 
                
                
                
                set init.TE_member<i> = CreateUnit(owner, rawcode, x1,y1,0)
                call SetUnitZ(init.TE_member<i>, height + z0)
                call SetSafeX(init.TE_member<i>, x1)
                call SetSafeY(init.TE_member<i>, y1)
                set i = i + 1
            endloop
            
            call TT_Start(function Figure.ThingsToDo, init)
            
            return init
        endmethod   
        
        static method ThingsToDo takes nothing returns boolean
            local Figure this = TT_GetData()
            local real x0
            local real y0
            local real z0
            local integer i = 0
            local real height
            local real      angle
            local real      zangle
            local real      distance
            local real      x1
            local real      y1
            
            if .TE_expire then
                set .TE_time = .TE_time - TT_PERIOD
                if .TE_time &lt;= 0 then
                    call .Destroy()
                endif
            endif
            
            if .TE_destroy then
                call .destroy()
                return true
            endif
            
            //! runtextmacro TEPeriodic()
            
            if .TE_rchanging then
                set .TE_radius = .TE_radius + .TE_rchange
                if RAbsBJ(.TE_radius-.TE_wantedr) &lt; .TE_rchange then
                    set .TE_rchanging = false
                    set .TE_nset = true
                endif
            endif
            
            if .TE_moving then
                set distance = DistanceBetweenCoords(.TE_cx, .TE_cy, .TE_cz, .TE_wherex, .TE_wherey, .TE_wherez)
                
                if distance &gt; .TE_moverate * 2 then
                    set angle = AngleBetweenCoords(.TE_cx, .TE_cy, .TE_wherex, .TE_wherey)
                    set zangle = AngleBetweenCoordsB(.TE_cx, .TE_cy, .TE_cz, .TE_wherex, .TE_wherey, .TE_wherez)
                    set .TE_cx = .TE_cx + .TE_moverate * Cos(angle) * Cos(zangle)
                    set .TE_cy = .TE_cy + .TE_moverate * Sin(angle) * Cos(zangle)
                    set .TE_cz = .TE_cz + .TE_moverate              * Sin(zangle)
                endif
            endif
            
            if .TE_attached then
                set .TE_cx = GetUnitX(.TE_towhich)
                set .TE_cy = GetUnitY(.TE_towhich)
                if IsUnitType(.TE_towhich, UNIT_TYPE_DEAD) == true then
                    set .TE_hide = false
                    if IsUnitType(.TE_towhich, UNIT_TYPE_HERO) == false then
                        call .Destroy()
                    endif
                else
                    set .TE_hide = true
                endif
            endif
            
            if .TE_zturning then
                set .TE_zface = .TE_zface + .TE_zturnage
            endif
            if .TE_nturning then
                set .TE_nface = .TE_nface + .TE_nturnage
            endif
            
            if .TE_rchanging or .TE_zturning or .TE_nturning or .TE_attached or .TE_moving or .TE_zset or .TE_nset then
                set .TE_zset = false
                set .TE_nset = false
                call MoveLocation(loc, .TE_cx, .TE_cy)
                set height = GetLocationZ(loc)
                loop
                    exitwhen i &gt;= .TE_number
                    
                    set x0 = .TE_cx + .TE_radius * .TE_cos<i> * Cos(.TE_zface * DTR)
                    set y0 = .TE_cy + .TE_radius * .TE_sin<i> 
                    set z0 = .TE_cz + .TE_radius * .TE_cos<i> * Sin(.TE_zface * DTR)
                    
                    set x1 = x0
                    set y1 = y0
                    
                    set distance = SquareRoot(SquareDistance(x0, y0, .TE_cx, .TE_cy))
                    set angle = AngleBetweenCoords(.TE_cx, .TE_cy, x0, y0) * bj_RADTODEG
                        
                    set x1 = .TE_cx + distance * Cos( (angle+.TE_nface) * DTR ) 
                    set y1 = .TE_cy + distance * Sin( (angle+.TE_nface) * DTR ) 
                    
                    if .TE_hide == false then
                        set height = 6000
                        set z0 = 0
                    endif
                    
                    call SetSafeX(.TE_member<i>, x1)
                    call SetSafeY(.TE_member<i>, y1)
                    call SetUnitZ(.TE_member<i>, height + z0)
                    
                    set i = i + 1
                endloop
            endif
            
            
            
            return false
        endmethod
        
        method onDestroy takes nothing returns nothing
            local integer i = 0
            if not .TE_destroy then
                call BJDebugMsg(&quot;TE System Error: Destroyed struct wrong&quot;)
            endif
            
            loop
                exitwhen i &gt;= .TE_number
                    call KillUnit(.TE_member<i>)
            endloop
        endmethod
        
 
endstruct


private function Alive takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) &gt; 0.5
endfunction

private function Init takes nothing returns nothing
    set loc = Location(0,0)
    set MaxX = GetRectMaxX(bj_mapInitialPlayableArea)
    set MaxY = GetRectMaxY(bj_mapInitialPlayableArea)
    set MinX = GetRectMinX(bj_mapInitialPlayableArea)
    set MinY = GetRectMinY(bj_mapInitialPlayableArea)
    set AliveFilter = Condition(function Alive)
endfunction
endlibrary

</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


Documentation(yes, it is short):
JASS:

TE - Trollvottel Effects

How to import: 

Copy the Effects Trigger into your map. You need a vJass Compiler.
If you dont have it already in your map, copy TT , too.

How to use:

Create it with this method:

        static method create takes integer rawcode, player owner, real x, real y, real z, real radius, real nface, real zface, integer edges returns Figure

    Creates the Figure with the given values.
    If you want to Z-turn your figure, remember that the z value should not be
    smaller than radius.
    
    
    
method-summary:

        method GetX takes nothing returns real
    
    Returns the Current X of the Figure.
    
        method GetY takes nothing returns real
        
    Returns the Current Y of the Figure.
    
        method GetZ takes nothing returns real
    
    Returns the Current Z of the Figure.
    
    
        method GetZAngle takes nothing returns real

    Returns the Current Z-angle (degrees).
        
        method GetNAngle takes nothing returns real

    Returns the Current N-angle (degrees).
    
        method GetRadius takes nothing returns real
        
    Returns the Radius of the figure.
    
        method SetZAngle takes real Z returns nothing
    
    Sets Z-angle to the value Z.
        
        method SetNAngle takes real N returns nothing
    
    Sets facing of the figure to the value N.
    
         method SetRadius takes real r returns nothing
         
    Set radius of figure to r.
    
        method SetRadiusOverTime takes real r, real time returns nothing
        
    Changes radius to r over time seconds.
    
        method StartZTurn takes real rate returns nothing
        
    Starts turning the figure (z-angle). rate is degrees per second.
    
        method StartNTurn takes real rate returns nothing
 
    Starts turning the figure (facing). rate is degrees per second.
    
        method Attach takes unit whichto returns nothing

    Locks the figure to the unit.    
    
        method UnAttach takes nothing returns nothing

    Unlocks the figure.
        
        method MoveTo takes real x, real y, real z, real rate returns nothing

    Moves the figure to the desired coordinates with the desired
    speed per second.
    
        method SetPosition takes real x, real y, real z returns nothing
        
    Instantly moves the figure to the coordiantes x,y,z.
    
        method Destroy takes nothing returns nothing
  
    Destroys the Figure. Dont use .destroy()
        
        method SetExpirationTime takes real time returns nothing
    
    Destroys the figure after time seconds.
 
        method GetUnitsInRange takes nothing returns group
        
    Returns all units in range of the figure 
    (distance to center &lt; radius).
    
You can also add methods/attributes by adding them into the textmacro TEStructMembers.
Code written in the TEPeriodic textmacro will be called periodically.

Screenshot(Look at it ingame...):

scrsn1.jpg

Maybe you have ideas to improve this? Please tell me.

Map:
 

Attachments

  • TE-System.w3x
    32.3 KB · Views: 189

Romek

Super Moderator
Reaction score
963
What does it do?

I doubt it can be that hard to explain...
 

WindexIsBack

New Member
Reaction score
100
right-click>view image

Imageshack is too stupid to realize no one wants to use their pre-made codes that don't work except on one or two sites.
 

Trollvottel

never aging title
Reaction score
262
Thank you <3


Huge Update!

New methods:

JASS:
        method GetZAngle takes nothing returns real
        method GetNAngle takes nothing returns real
        method GetRadius takes nothing returns real

        method SetRadius takes real r returns nothing
        method SetPosition takes real x, real y, real z returns nothing
        method SetExpirationTime takes real time returns nothing
        method SetRadiusOverTime takes real r, real time returns nothing


If the figure is attached and your unit dies, the figure will hide if its a hero and destroy if its not.
 

Romek

Super Moderator
Reaction score
963
Just tested the map.
I think it should not require "Useless Funcs Compilation". It seems pretty useless.

The effect seems so small as well. It's funny how it requites an entire system.
Well, either way. Good Job.

Also, I don't think this is needed:
JASS:
// put in desired custom struct members or methods (only advanced)
//! textmacro TEStructMembers
    
//! endtextmacro


Because you could just make your own struct which extends this struct. It would also be much, much cleaner.
JASS:
struct Test extends TE_Figure
   private unit u
endstruct
 

Trollvottel

never aging title
Reaction score
262
i began this system a quite long time ago. i maybe will remove the UsedFuncs functions.

and it requites a whole system because its much code to make it look like it currently looks.

@ textmacros:

you can do it with structs extending structs, but that would be more work.
 

Romek

Super Moderator
Reaction score
963
Actually, extending structs is easier. Also, if you want to use this system in many different situations, you'd have to make all the members in that struct. So, eventually you could have a whole list of variables, with odd prefixes and names to avoid confusion (For example, 'caster' would be a common name).

Extending would look cleaner, be easier to work with and avoid all the naming hassle.
 

Dr.Jack

That's Cap'n to you!
Reaction score
108
Awesome system, though you should really explain it better. You should answer these in your first post:

1) What is radius?
2) Whats Z-turn? Z-angle?
3) What are those figures exactly?

Etc. for the sake of those that can't understand from the code alone.
 

Trollvottel

never aging title
Reaction score
262
Maybe i will add an explaining picture later. thx for the comment.

Small update:
-Put the usedfuncs library into the TE library. Some of you didnt like to have to import an extra library.
 

Cohadar

master of fugue
Reaction score
209
You really need to put an explanation of what system does.
If you cannot explain it how you expect people to use it?

And avoid short names for non general purpouse systems.
 

Sim

Forum Administrator
Staff member
Reaction score
534
> Creates a ring of dummys which is turnable and movable in x,y and z direction.

And to achieve what?

Didn't know TE was short for "Trollvottel Effects".

SFX systems are also quite different from what you posted here!
 

Trollvottel

never aging title
Reaction score
262
> Creates a ring of dummys which is turnable and movable in x,y and z direction.

And to achieve what?

-> Eyecandy for spells, maybe?

Didn't know TE was short for "Trollvottel Effects".

-> now it is

SFX systems are also quite different from what you posted here!

-> may be right
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top