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 = 039;usfx039;
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,039;BTLF039;,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,039;Amrf039;) then
call UnitRemoveAbility(this.dummy,039;Amrf039;)
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