System Effect

luorax

Invasion in Duskwood
Reaction score
67
Effect v1.2

Requirements
- Timer32
- ARGB
- AutoFly (optional)

System Code

JASS:
/*

            Effect v1.2
                by Luorax

            DESCRIPTION
                >> Effect is an basic and simple system that gives you a nice
                   interface to work with effects and allows you to create effects with
                   specific size; angle; colors; x; y; z, and also allows you to modify them after
                   they've been created.

            FEATURES
                 > Clear interface
                 > Can handle timed effects with custom death time
                 > Allows effect locking to units
                 > A lot of attributes to work with
                 > Each method returns the actual instance allowing you to create chain calls
                 > Simple struct syntax should be easy to use
            
            REQUIREMENTS
                 > T32 by Jesus4Lyf
                 > ARGB by Vexorian
                 > AutoFly by Azlier (optional)
            
            METHOD LIST
                >> struct Effect
                    .create takes string model,string att,real x,real y,real z,real angle returns thistype
                    .setPosition takes real x,real y,real z returns thistype
                    .method setXYAngle takes real angle returns thistype
                    .method setZAngle takes real angle returns thistype
                    .lockToUnit takes unit u,real x,real y,real z returns thistype
                    .removeLock takes nothing returns thistype
                    .setColor takes integer r,integer g,integer b,integer a returns thistype
                    .setDuration takes real d,real dt returns thistype
                    .setOwner takes player p,boolean color returns thistype
                    .setXYAngle takes real angle returns thistype
                    .setZAngle takes real angle returns thistype
                    .setTeamColor playercolor pc returns thistype
                    .setsize takes real size returns thistype
                    .setData takes integer dara returns thistype
                    .ARGBrecolor takes ARGB color returns thistype
                    
                > I think all of those methods are self-explanatory.  
                
            OPERATOR LIST
                >> struct Effect
                    .size takes nothing returns real
                    .red takes nothing returns integer
                    .green takes nothing returns integer
                    .blue takes nothing returns integer
                    .alpha takes nothing returns integer
                    .target takes nothing returns unit
                    .duration takes nothing returns real
                    .x takes nothing returns real
                    .y takes nothing returns real
                    .z takes nothing returns real
                    .xyangle takes nothing returns real
                    .zangle takes nothing returns real
                    .owner takes nothing returns player
                    .data takes nothing returns integer
                    .teamcolor takes nothing returns playercolor
                    
                > I think all of those operators are self-explanatory.
                
            WRAPPER LIST
                >> CreateEffect takes string id,string att,real x,real y,real size,real duration returns Effect
                >> CreateEffectEx takes string id,string att,real x,real y,real z,real angle,real size,real duration,real deathTime returns Effect
                >> CreateEffectOnUnit takes string id,string att,unit u,real x,real y,real z,real size,real duration returns Effect
                >> SetEffectColor takes Effect sfx,integer r,integer g,integer b,integer a returns nothing
                >> SetEffectSize takes Effect sfx,real s returns nothing
                >> SetEffectPosition takes Effect sfx,real x,real y returns nothing
                >> SetEffectPositionEx takes Effect sfx,real x,real y,real z returns nothing
                >> RemoveEffect takes Effect sfx,real duration,real deathTime returns nothing

                > I think all of those functions are self-explanatory.    

            IMPLEMENTING

                  > Create a new trigger object called DummyCaster, go to 'Edit -> Convert to
                    Custom Text', and replace everything that's there with this script.
                  > Copy the "Effext Dummy" unit from the test map and export/import the dummy model.
                  > Go to the "Configuration" part and set the options.
                  > Have fun using the system!

            CREDITS

                 > Jesus4Lyf for T32
                 > Vexorian for the dummy unit model and setZAngle method
                 
            
            MISC

                 > Check the wrapper functions at the bottom of the library for examples!!


*/
library Effect uses T32,ARGB optional AutoFly

    //: ==============================================
    //:                CONFIGURATION
    //: ==============================================
    
    globals
        private      constant       integer         UNIT_TYPE       =   'usfx'
        private      constant       player          DEFAULT_OWNER   =   Player(12)
    endglobals

    //: ==============================================
    //:                    CODE
    //: ==============================================

    struct Effect
        readonly unit dummy
        readonly effect sfx
        
        readonly real deathTime=1.
        
        readonly unit targetUnit=null
        readonly real oX            //Offset X
        readonly real oY            //Offset Y
        readonly real oZ            //Offset Z
        
        readonly real s=1.          //Size
        readonly real d             //Duration
        readonly real za            //Z Angle
        readonly integer r=255      //Red
        readonly integer g=255      //Green
        readonly integer b=255      //Blue
        readonly integer a=255      //Alpha
        readonly integer dat        //Data
        readonly playercolor pc     //Player color
        
        private static location l
        
        private method getZ takes nothing returns real
            call MoveLocation(thistype.l,GetUnitX(this.targetUnit),GetUnitY(this.targetUnit))
            return GetLocationZ(thistype.l) + GetUnitFlyHeight(this.targetUnit)
        endmethod
        private method recolor takes integer r,integer g,integer b,integer a returns nothing
           set this.r=r
           set this.g=g
           set this.b=b
           set this.a=a
           call SetUnitVertexColor(this.dummy,this.r,this.g,this.b,this.a)
        endmethod
        method destroy takes nothing returns nothing
            call DestroyEffect(this.sfx)
            if this.deathTime>0. then
                call UnitApplyTimedLife(this.dummy,'BTLF',this.deathTime)
            else
                call RemoveUnit(this.dummy)
            endif
            call this.deallocate()
        endmethod
        method periodic takes nothing returns nothing
            if this.d>0. then
                set this.d=this.d-T32_PERIOD
                if this.d<=0 then
                    call this.stopPeriodic()
                    call this.destroy()
                    return
                endif
            endif
            if this.targetUnit!=null then
                call SetUnitPosition(this.dummy,GetUnitX(this.targetUnit)+this.oX,GetUnitY(this.targetUnit)+this.oY)
                call SetUnitFacing(this.dummy,GetUnitFacing(this.targetUnit))
                call SetUnitFlyHeight(this.dummy,this.getZ()+this.oZ,0.)
            endif
        endmethod
        implement T32x
        method operator size takes nothing returns real
            return this.s
        endmethod
        method operator red takes nothing returns integer
            return this.r
        endmethod
        method operator green takes nothing returns integer
            return this.g
        endmethod
        method operator blue takes nothing returns integer
            return this.b
        endmethod
        method operator alpha takes nothing returns integer
            return this.a
        endmethod
        method operator target takes nothing returns unit
            return this.targetUnit
        endmethod
        method operator duration takes nothing returns real
            return this.d
        endmethod
        method operator x takes nothing returns real
            return GetUnitX(this.dummy)
        endmethod
        method operator y takes nothing returns real
            return GetUnitY(this.dummy)
        endmethod
        method operator z takes nothing returns real
            return GetUnitFlyHeight(this.dummy)
        endmethod
        method operator xyangle takes nothing returns real
            return GetUnitFacing(this.dummy)
        endmethod
        method operator zangle takes nothing returns real
            return this.za
        endmethod
        method operator owner takes nothing returns player
            return GetOwningPlayer(this.dummy)
        endmethod
        method operator teamcolor takes nothing returns playercolor
            return this.pc
        endmethod
        method operator data takes nothing returns integer
            return this.dat
        endmethod
        method setDuration takes real d,real dt returns thistype
            if this.targetUnit==null and this.d==0 and d>0then
                call this.startPeriodic()
            elseif this.targetUnit==null and this.d>0 and d==0then
                call this.stopPeriodic()
            endif
            set this.d=d
            set this.deathTime=dt
            return this
        endmethod
        method setColor takes integer r,integer g,integer b,integer a returns thistype
            call this.recolor(r,g,b,a)
            return this
        endmethod
        method lockToUnit takes unit u,real x,real y,real z returns thistype
            set this.targetUnit=u
            set this.oX=x
            set this.oY=y
            set this.oZ=z
            if this.d==0. then
                call this.startPeriodic()
            endif
            return this
        endmethod
        method removeLock takes nothing returns thistype
            if this.targetUnit!=null then
                set this.targetUnit=null
                if this.d==0. then
                    call this.stopPeriodic()
                endif
            endif
            return this
        endmethod
        method setPosition takes real x,real y,real z returns thistype
            call this.removeLock()
            call SetUnitPosition(this.dummy,x,y)
            call SetUnitFlyHeight(this.dummy,z,0.)
            return this
        endmethod
        method setXYAngle takes real angle returns thistype
            call SetUnitFacing(this.dummy,angle)
            return this
        endmethod
        method setSize takes real size returns thistype
            set this.s=size
            call SetUnitScale(this.dummy,this.s,this.s,this.s)
            return this
        endmethod
        method setZAngle takes real angle returns thistype
            local integer i=R2I(angle+90.5)
            if(i>=180) then
                set i=179
            elseif(i<0) then
                set i=0
            endif
            set this.za=angle
            call SetUnitAnimationByIndex(this.dummy,i)
            return this
        endmethod
        method setOwner takes player p,boolean color returns thistype
            call SetUnitOwner(this.dummy,p,color)
            return this
        endmethod
        method setTeamColor takes playercolor pc returns thistype
            set this.pc=pc
            call SetUnitColor(this.dummy,pc)
            return this
        endmethod
        method setData takes integer data returns thistype
            set this.dat=data
            return this
        endmethod
        method ARGBrecolor takes ARGB color returns thistype
            call this.recolor(color.red,color.green,color.blue,color.alpha)
            return this
        endmethod
        static method create takes string model,string att,real x,real y,real z,real angle returns thistype
            local thistype this=thistype.allocate()
            set this.dummy=CreateUnit(DEFAULT_OWNER,UNIT_TYPE,x,y,angle)
            set this.sfx=AddSpecialEffectTarget(model,this.dummy,att)
            static if not LIBRABRY_AutoFly then
                if UnitAddAbility(this.dummy,'Amrf') then
                    call UnitRemoveAbility(this.dummy,'Amrf')
                endif
            endif
            call SetUnitFlyHeight(this.dummy,z,0.)
            return this
        endmethod
    endstruct
    //: ==============================================
    //:                  WRAPPERS
    //: ==============================================
    function CreateEffect takes string id,string att,real x,real y,real size,real duration returns Effect
        return Effect.create(id,att,x,y,0.,0.).setDuration(duration,1.).setSize(size)
    endfunction
    function CreateEffectEx takes string id,string att,real x,real y,real z,real angle,real size,real duration,real deathTime returns Effect
        return Effect.create(id,att,x,y,z,angle).setDuration(duration,deathTime).setSize(size)
    endfunction
    function CreateEffectOnUnit takes string id,string att,unit u,real x,real y,real z,real size,real duration returns Effect
        return Effect.create(id,att,0.,0.,0.,0.).setDuration(duration,1.).lockToUnit(u,x,y,z).setSize(size)
    endfunction
    function SetEffectColor takes Effect sfx,integer r,integer g,integer b,integer a returns nothing
        call sfx.setColor(r,g,b,a)
    endfunction
    function SetEffectSize takes Effect sfx,real size returns nothing
        call sfx.setSize(size)
    endfunction
    function SetEffectPosition takes Effect sfx,real x,real y returns nothing
        call sfx.setPosition(x,y,0.)
    endfunction
    function SetEffectPositionEx takes Effect sfx,real x,real y,real z returns nothing
        call sfx.setPosition(x,y,z)
    endfunction
    function RemoveEffect takes Effect sfx,real duration,real deathTime returns nothing
        call sfx.setDuration(duration,deathTime)
    endfunction
endlibrary
 

Attachments

  • Effect.w3x
    65.2 KB · Views: 347

Solmyr

Ultra Cool Member
Reaction score
30
This is pretty much a xefx rip-off.

Also, ARGBrecolor is bugged, Vexorian screwed it up with the latest update (I think), and never bothered to revert it back.

You should also credit Vexorian for the pitch angle dummy. That's his work, after all (or perhaps you're using the one by Anitarf and Infrane).
 

luorax

Invasion in Duskwood
Reaction score
67
Actually I never knew about xefx. I knew about the basic xe library, but it was kinda outdated and I never had to use it.

I'm working on an AoS map with my friend, and because I quite often used a unit to attach effects to it I decided to write one. I was reading the topics some days ago and then I read something about xe and xefx. But it's still a module of a pretty outdated and never used system while this one is an independent system that also serves different purposes

You should also credit Vexorian for the pitch angle dummy. That's his work, after all
CREDITS

> Jesus4Lyf for T32
> Vexorian for the dummy unit model



Version 1.1
- ARGB is not optional anymore.
- Fixed the "this.ARGBrecolor" method.
 

Solmyr

Ultra Cool Member
Reaction score
30
What's its bug? For me it seems okay (or at least I never had any problems with it)
It doesn't even work. Read the last page of the ARGB thread at Wc3C.net.

Also, xe is not outdated. And sorry, but "Actually I never knew about xefx." does not sound very honest to me. This most definitely looks like a rip-off, at least in my eyes. Look at xefx's code, and look at yours. The only difference is that xefx uses a circular queue for the dummies' removal (while yours uses Timer32 and timed life) and does not have that "lock to target" thingy.

And sorry about the credits, didn't see them.
 

luorax

Invasion in Duskwood
Reaction score
67
http://www.thehelper.net/forums/sho...d-the-Caster-System-for-1.24e-patch-or-higher

Check Tom_Kazanky's post. I've seen xe when I was a very newbie JASSer and I had no idea how to use it. After it I started to use J4L's libraries.. I simply love them. When I wanted to post it in the discussion section the beta it still used another dummy model (it only had one animation) and "setXYAngle" was "setFacing". But as I told you, I found this dummy and method which is... kinda useless for me actually, but who knows, maybe someone else will find it useful (just like "this.setData()")

Well, if a moderator thinks that this library is useless and serves no purpose at all, I'm ready for graveyarding.

EDIT:
And yes, I think xe is outdated. I've never seen anyone using it. We have way better projectile systems so we don't need xecollider. We have J4L's DummyCaster, so we don't need xecast. GroupUtils+J4L's Damage is flawless victory, also xedamage is kinda useless because you always use custom filters, the options given by xedamage are not enough. So yes, for me xe is kinda useless.
The only thing that looks interesting in xe is xefx. If I found it before I start to write this I wouldn't write it, I'm sure. But now it doesn't matter, I've written my own so I won't use it.
 

Solmyr

Ultra Cool Member
Reaction score
30
I never said that this is useless or that it should be sent to the graveyard.

Anyway, here are some things that you should fix:
  1. You are missing a comma at the requirements (it won't even compile).
  2. Implement the Timer32 module at a more adequate place. Currently, all your [ljass].stopPeriodic()[/ljass] and [ljass].startPeriodic()[/ljass] are done via trigger evaluations, which is bad.
  3. There is no need to set the default values of your struct's members to [ljass]0[/ljass], [ljass]0.0[/ljass] or [ljass]null[/ljass] (depending on the type), as those are the default values for arrays (which non-static struct members are), so it just results in additional overhead for the struct's allocator.
 

luorax

Invasion in Duskwood
Reaction score
67
1, Where? Maybe I'm blind, or something like that but I can't find it - also, my compiler says no error and it works.
2, I propably forgot about that, sorry. I'll fix it soon.
3, Well, it's kinda unfortunate but I found nothing useful about non-initialized variables. I know that it terminates a thread if you don't initialize for example an integer, but I was not sure if the same goes for globals too. Initializing variables became one of my bad habbits, but I promise you, I'll try to get a rid of it.

Version 1.2
- Efficiency improvements.
 

Solmyr

Ultra Cool Member
Reaction score
30
Okay, surprisingly, [ljass]library Effect uses T32,ARGB optional AutoFly[/ljass] compiles even without a comma between "ARGB" and "optional".

EDIT:
And yes, I think xe is outdated. I've never seen anyone using it. We have way better projectile systems so we don't need xecollider. We have J4L's DummyCaster, so we don't need xecast. GroupUtils+J4L's Damage is flawless victory, also xedamage is kinda useless because you always use custom filters, the options given by xedamage are not enough. So yes, for me xe is kinda useless.
The only thing that looks interesting in xe is xefx. If I found it before I start to write this I wouldn't write it, I'm sure. But now it doesn't matter, I've written my own so I won't use it.
So, you didn't know about xefx, and now you know about all of xe's modules. Fucking awesome man.

Anyway, let me tell you something. All of Jesus4Lyf's systems are crap. Now, I don't want to be offensive or anything, but you're the one who started it. The only good thing is Timer32, and you know why? Because the whole looping through a linked list is better than looping through an array stuff was not his invention, but grim001's.

Also, xecollider is not a system for projectiles, but for collision missiles.

You think that something like xecast can be replaced with that DummyCaster shit (that isn't even done properly)? Mad props to you mate.

And Damage? Seriously? Let me enlighten you. Damage uses dynamic triggers, which are horrible. There are tons of better damage detection engines out there, and I don't even want to talk about damage modifiers. Also, xedamage is nothing like Damage.

And look at Jesus4Lyf's code in general. Using globals instead of locals? It's been common knowledge that locals are about 20% faster than globals, else what retarded man would use locals anyway?

Oh, and before you bring AIDS in the conversion, try looking at the code you get after running (and using) the textmacro in your struct.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
Using globals instead of locals? It's been common knowledge that locals are about 20% faster than globals, else what retarded man would use locals anyway?

source plz
 

Solmyr

Ultra Cool Member
Reaction score
30
The speed at which a variable is accessed depends on how many variables there are in the scope. JassHelper can generate tons of global variables, which in turn makes them slower. Moreover, the VM checks the local scope first (this is a O(n) operation, with n being the number of the variables in the scope, which leads to the first statement in my post; that the speed depends on how many variables there in the scope), which makes them even more faster.

Don't ask me for a source, test it yourself. Or try looking at PipeDream's posts on Wc3C.net.
 

tooltiperror

Super Moderator
Reaction score
231
>Don't ask me for a source, test it yourself
Much of the academic community of the world pretty much agrees saying things without citation is similar to speaking out of your ass.

Graveyarded, this is bad xefx.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top