- Joined
- Jul 10, 2007

- Messages
- 6,306

JASS:

```
library Particle /* v2.0.2.2
*************************************************************************************
*
* Unit for spell effects
*
* Thanks to Vexorian for dummy.mdx
* Thanks to Magtheridon96 for updates
*
*************************************************************************************
*
* */uses/*
*
* */ UnitIndexer /* hiveworkshop.com/forums/jass-functions-413/unit-indexer-172090/
* */ GetUnitCollision /* hiveworkshop.com/forums/jass-resources-412/snippet-getunitcollision-180495/
*
************************************************************************************
*
* SETTINGS
*/
globals
constant integer PARTICLE_ID = 'h000'
endglobals
/*
************************************************************************************
*
* function GetUnitParticle takes UnitIndex whichUnit returns Particle
*
************************************************************************************
*
* struct Particle extends array
*
* real x
* real y
* real z
*
* real xyAngle
* real zAngle
*
* real scale
*
* player owner
*
* string model
*
* integer red
* integer green
* integer blue
* integer alpha
*
* boolean hidden
*
* readonly real collision
*
* readonly unit unit
*
* static method create takes player owner, real x, real y, real xyAngle, string model, real collision returns Particle
* static method createEx takes player owner, real x, real y, real z, real xyAngle, real zAngle, real scale, integer red, integer green, integer blue, integer alpha, string model, real collision returns Particle
* static method createFromUnit takes unit whichUnit returns Particle
* method destroy takes nothing returns nothing
*
* method setColor takes integer red, integer green, integer blue, integer alpha returns nothing
*
************************************************************************************/
globals
private integer array unitParticle
endglobals
struct Particle extends array
private static integer instanceCount = 0
private static integer array recycler
private unit particle
private unit trueParticle
private real scl
private real tlt
private integer red1
private integer blue1
private integer green1
private integer alpha1
private string mdl
private effect mdle
private real xp
private real yp
private real zp
private real ap
private real collision_p
private static location zloc = Location(0,0)
method operator unit takes nothing returns unit
return particle
endmethod
method operator collision takes nothing returns real
return collision_p
endmethod
method operator x takes nothing returns real
return xp
endmethod
method operator x= takes real v returns nothing
set xp = v
call SetUnitX(particle, v)
endmethod
method operator y takes nothing returns real
return yp
endmethod
method operator y= takes real v returns nothing
set yp = v
call SetUnitY(particle, v)
endmethod
method operator z takes nothing returns real
return zp
endmethod
method operator z= takes real v returns nothing
set zp = v
call MoveLocation(zloc, xp, yp)
call SetUnitFlyHeight(particle, v - GetLocationZ(zloc), 0)
endmethod
method operator xyAngle takes nothing returns real
return ap
endmethod
method operator xyAngle= takes real v returns nothing
set ap = v
call SetUnitFacing(particle,v*57.2957795)
endmethod
method operator zAngle takes nothing returns real
return tlt
endmethod
method operator zAngle= takes real v returns nothing
local integer i = R2I(v*57.2957795+90.5)
set tlt = v
if (179 < i) then
set i = 179
elseif (0 > i) then
set i = 0
endif
call SetUnitAnimationByIndex(particle, i)
endmethod
method operator hidden takes nothing returns boolean
return IsUnitHidden(particle)
endmethod
method operator hidden= takes boolean v returns nothing
call ShowUnit(particle, not v)
endmethod
method operator scale takes nothing returns real
return scl
endmethod
method operator scale= takes real v returns nothing
set scl = v
call SetUnitScale(particle, v, 0, 0)
endmethod
method operator owner takes nothing returns player
return GetOwningPlayer(particle)
endmethod
method operator owner= takes player v returns nothing
call SetUnitOwner(particle, v, true)
endmethod
method operator model takes nothing returns string
return mdl
endmethod
method operator model= takes string s returns nothing
call DestroyEffect(mdle)
if (null != s and "" != s) then
set mdle = AddSpecialEffectTarget(s, particle, "origin")
else
set mdle = null
endif
set mdl = s
endmethod
method setColor takes integer red, integer green, integer blue, integer alpha returns nothing
set this.red1 = red
set this.green1 = green
set this.blue1 = blue
set this.alpha1 = alpha
call SetUnitVertexColor(particle, red, green, blue, alpha)
endmethod
method operator red takes nothing returns integer
return red1
endmethod
method operator blue takes nothing returns integer
return blue1
endmethod
method operator green takes nothing returns integer
return green1
endmethod
method operator alpha takes nothing returns integer
return alpha1
endmethod
method operator red= takes integer v returns nothing
set red1 = v
call SetUnitVertexColor(particle, red1, green1, blue1, alpha1)
endmethod
method operator blue= takes integer v returns nothing
set blue1 = v
call SetUnitVertexColor(particle, red1, green1, blue1, alpha1)
endmethod
method operator green= takes integer v returns nothing
set green1 = v
call SetUnitVertexColor(particle, red1, green1, blue1, alpha1)
endmethod
method operator alpha= takes integer v returns nothing
set alpha1 = v
call SetUnitVertexColor(particle, red1, green1, blue1, alpha1)
endmethod
static method createEx takes player p, real x, real y, real z, real xyAngle, real zAngle, real scale, integer red, integer green, integer blue, integer alpha, string model, real collision returns thistype
local thistype this
local unit u
if (0 == recycler[0]) then
set this = instanceCount + 1
set instanceCount = this
else
set this = recycler[0]
set recycler[0] = recycler[this]
endif
if (null == trueParticle) then
set trueParticle = CreateUnit(p, PARTICLE_ID, x, y, xyAngle * 57.2957795)
set unitParticle[GetUnitUserData(trueParticle)] = this
else
call SetUnitX(trueParticle, x)
call SetUnitY(trueParticle, y)
call SetUnitFacing(trueParticle, xyAngle * 57.2957795)
call SetUnitOwner(trueParticle, p, false)
endif
set xp = x
set yp = y
set zp = z
set ap = xyAngle
set particle = trueParticle
call UnitRemoveAbility(trueParticle, 'Amov')
call UnitAddAbility(trueParticle, 'Amrf')
call UnitRemoveAbility(trueParticle, 'Amrf')
call SetUnitFlyHeight(trueParticle, z, 0)
set mdl = model
set mdle = AddSpecialEffectTarget(model, trueParticle, "origin")
set this.zAngle = zAngle
call setColor(red, green, blue, alpha)
set this.scale = scale
set collision_p = collision
return this
endmethod
static method create takes player p, real x, real y, real xyAngle, string model, real collision returns thistype
return createEx(p, x, y, 0, xyAngle, 0, 1, 255, 255, 255, 255, model, collision)
endmethod
static method createFromUnit takes unit u returns thistype
local thistype this
if (0 == recycler[0]) then
set this = instanceCount + 1
set instanceCount = this
else
set this = recycler[0]
set recycler[0] = recycler[this]
endif
set particle = u
set xp = GetUnitX(u)
set yp = GetUnitY(u)
set zp = GetUnitFlyHeight(u)
set ap = GetUnitFacing(u)*bj_DEGTORAD
set collision_p = GetUnitCollision(u)
set unitParticle[GetUnitUserData(u)] = this
return this
endmethod
method destroy takes nothing returns nothing
if (particle == trueParticle) then
set hidden = false
call DestroyEffect(mdle)
set mdle = null
call SetUnitX(trueParticle, WorldBounds.maxX)
call SetUnitY(trueParticle, WorldBounds.maxY)
else
set particle = null
endif
set recycler[this] = recycler[0]
set recycler[0] = this
endmethod
endstruct
function GetUnitParticle takes UnitIndex whichUnit returns Particle
return unitParticle[whichUnit]
endfunction
endlibrary
```

Last edited: