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: 355

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 The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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