by RiskYourLife
[Note!] Requires vJass/JNGP to use this system
What is this?
This is a system can create looping effect with gap between it.
For example, if you set the gap to 2 second, after the first effect created the system will wait for 2 second and after that the second effect will be created.
Can shorten your code
How to import?
Create a trigger and name it fxGap
Convert the trigger into custom text and clear it
Copy the code below and paste it into the fxGap trigger
Code : fxGap
Spoiler
Show
[jass]library fxGap requires TimerUtils, TimedEffects
/**********************************************************************
*
* fxGap v1.0.0
* by RiskYourLife
*
*
* This is a system that can create looping sFx (FxGap)
* with gap between the effect creation. For example,
* if you set the gap to 0.50 second, after the first sFx
* created, the system will wait for 0.50 second and the
* second sFx will be created.
*
* Currently, I have ton of work in coding. Most of them is
* spell making. I found that I use a lot of code like this.
* So, I create this system to make coders code shorter.
*
*
* Optional requirement :-
* -Table by Bribe [optional]
* |
* -TimerUtils by Vexorian, Bribe & Magtheridon96 [requires Table]
* |
* -TimedEffects by moyack [requires TimerUtils]
*-----------------------------------------------------------------------------------------------------------------------------------------
*
* API:
* ----
* | - function CreateFxGap takes string modelPath, real gap, real x, real y returns FxGap
* | - return FxGap (the looping sFx). Create FxGap at (x, y)
* |
* | - function CreateFxGapLifeSpan takes string modelPath, real gap, real lifespan, real x, real y returns FxGap
* | - return FxGap. Create FxGap at (x, y) with lifespan applied effect
* |
* | - function CreateTimedFxGap takes string modelPath, real gap, real duration , real x, real y returns FxGap
* | returns FxGap. Create timed FxGap at (x, y)
* |
* | - function CreateTimedFxGapLifeSpan takes string modelPath, real gap, real duration, real lifespan, real x, real y returns FxGap
* | returns FxGap. Create timed FxGap at (x, y) with lifespan applied effect
* |
* |----------------------------------------------------------------------------------------------------------------------------------
* | - function CreateFxGapTarget takes string modelPath, unit whichUnit, string attach, real gap returns FxGap
* | - return FxGap. Create FxGap at selected attachment point of the unit.
* |
* | - function CreateFxGapLifeSpanTarget takes string modelPath, unit whichUnit, string attach, real gap, real lifespan returns FxGap
* | - return FxGap. Create FxGap at selected attachment point of the unit with lifespan applied effect
* |
* | - function CreateTimedFxGapTarget takes string modelPath, unit whichUnit, string attach, real gap, real duration returns FxGap
* | returns FxGap. Create timed FxGap at selected attachment point of the unit
* |
* | - function CreateTimedFxGapLifeSpanTarget takes string modelPath, unit whichUnit, string attach, real gap, real duration, real lifespan returns FxGap
* | returns FxGap. Create timed FxGap at selected attachment point of the unit with lifespan applied effect
*
**********************************************************************/
struct FxGap
private static real PERIODIC = 0.10
string m
effect fx
real gap
real gapEx
real dur
real ls
unit ta
timer t
string atch
real x
real y
boolean typ
boolean tm
method destroy takes nothing returns nothing
call ReleaseTimer(this.t)
call .deallocate()
endmethod
private static method iterator takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
if this.tm then
if this.dur > 0.00 then
if this.gapEx > 0.00 then
set this.gapEx = this.gapEx - PERIODIC
else
if this.typ then
set this.fx = AddSpecialEffectTarget(this.m, this.ta, this.atch)
else
set this.fx = AddSpecialEffect(this.m, this.x, this.y)
endif
if this.ls > 0.00 then
call StartTimedEffect(this.fx, this.ls)
else
call DestroyEffect(this.fx)
endif
set this.gapEx = this.gap
endif
set this.dur = this.dur - PERIODIC
else
call this.destroy()
endif
else
if this.gapEx > 0.00 then
set this.gapEx = this.gapEx - PERIODIC
else
if this.typ then
set this.fx = AddSpecialEffectTarget(this.m, this.ta, this.atch)
else
set this.fx = AddSpecialEffect(this.m, this.x, this.y)
endif
if this.ls > 0.00 then
call StartTimedEffect(this.fx, this.ls)
else
call DestroyEffect(this.fx)
endif
set this.gapEx = this.gap
endif
endif
endmethod
static method create takes string mdl, unit target, real Gap, real duration, real lifespan, string attach, real x, real y returns thistype
local thistype this = thistype.allocate()
set this.m = mdl
set this.ta = target
set this.gap = Gap
set this.gapEx = 0.00
set this.t = NewTimerEx(this)
set this.atch = attach
set this.x = x
set this.y = y
set this.ls = lifespan
set this.dur = duration
if this.atch != null then
set this.typ = true
else
set this.typ = false
endif
if duration <= 0.00 then
set this.tm = false
else
set this.tm = true
endif
call TimerStart(this.t, PERIODIC, true, function thistype.iterator)
return this
endmethod
endstruct
function DestroyFxGap takes FxGap this returns nothing
call this.destroy()
endfunction
function CreateFxGap takes string modelPath, real gap, real x, real y returns FxGap
return FxGap.create(modelPath, null, gap, 0.00, 0.00, null, x, y)
endfunction
function CreateFxGapLifeSpan takes string modelPath, real gap, real lifespan, real x, real y returns FxGap
return FxGap.create(modelPath, null, gap, 0.00, lifespan, null, x, y)
endfunction
function CreateTimedFxGap takes string modelPath, real gap, real duration , real x, real y returns FxGap
return FxGap.create(modelPath, null, gap, duration, 0.00, null, x, y)
endfunction
function CreateTimedFxGapLifeSpan takes string modelPath, real gap, real duration, real lifespan, real x, real y returns FxGap
return FxGap.create(modelPath, null, gap, duration, lifespan, null, x, y)
endfunction
//*****************************************************************************************************************
function CreateFxGapTarget takes string modelPath, unit whichUnit, string attach, real gap returns FxGap
return FxGap.create(modelPath, whichUnit, gap, 0.00, 0.00, attach, 0, 0)
endfunction
function CreateFxGapLifeSpanTarget takes string modelPath, unit whichUnit, string attach, real gap, real lifespan returns FxGap
return FxGap.create(modelPath, whichUnit, gap, 0.00, lifespan, attach, 0, 0)
endfunction
function CreateTimedFxGapTarget takes string modelPath, unit whichUnit, string attach, real gap, real duration returns FxGap
return FxGap.create(modelPath, whichUnit, gap, duration, 0.00, attach, 0, 0)
endfunction
function CreateTimedFxGapLifeSpanTarget takes string modelPath, unit whichUnit, string attach, real gap, real duration, real lifespan returns FxGap
return FxGap.create(modelPath, whichUnit, gap, duration, lifespan, attach, 0, 0)
endfunction
endlibrary[/jass]
/**********************************************************************
*
* fxGap v1.0.0
* by RiskYourLife
*
*
* This is a system that can create looping sFx (FxGap)
* with gap between the effect creation. For example,
* if you set the gap to 0.50 second, after the first sFx
* created, the system will wait for 0.50 second and the
* second sFx will be created.
*
* Currently, I have ton of work in coding. Most of them is
* spell making. I found that I use a lot of code like this.
* So, I create this system to make coders code shorter.
*
*
* Optional requirement :-
* -Table by Bribe [optional]
* |
* -TimerUtils by Vexorian, Bribe & Magtheridon96 [requires Table]
* |
* -TimedEffects by moyack [requires TimerUtils]
*-----------------------------------------------------------------------------------------------------------------------------------------
*
* API:
* ----
* | - function CreateFxGap takes string modelPath, real gap, real x, real y returns FxGap
* | - return FxGap (the looping sFx). Create FxGap at (x, y)
* |
* | - function CreateFxGapLifeSpan takes string modelPath, real gap, real lifespan, real x, real y returns FxGap
* | - return FxGap. Create FxGap at (x, y) with lifespan applied effect
* |
* | - function CreateTimedFxGap takes string modelPath, real gap, real duration , real x, real y returns FxGap
* | returns FxGap. Create timed FxGap at (x, y)
* |
* | - function CreateTimedFxGapLifeSpan takes string modelPath, real gap, real duration, real lifespan, real x, real y returns FxGap
* | returns FxGap. Create timed FxGap at (x, y) with lifespan applied effect
* |
* |----------------------------------------------------------------------------------------------------------------------------------
* | - function CreateFxGapTarget takes string modelPath, unit whichUnit, string attach, real gap returns FxGap
* | - return FxGap. Create FxGap at selected attachment point of the unit.
* |
* | - function CreateFxGapLifeSpanTarget takes string modelPath, unit whichUnit, string attach, real gap, real lifespan returns FxGap
* | - return FxGap. Create FxGap at selected attachment point of the unit with lifespan applied effect
* |
* | - function CreateTimedFxGapTarget takes string modelPath, unit whichUnit, string attach, real gap, real duration returns FxGap
* | returns FxGap. Create timed FxGap at selected attachment point of the unit
* |
* | - function CreateTimedFxGapLifeSpanTarget takes string modelPath, unit whichUnit, string attach, real gap, real duration, real lifespan returns FxGap
* | returns FxGap. Create timed FxGap at selected attachment point of the unit with lifespan applied effect
*
**********************************************************************/
struct FxGap
private static real PERIODIC = 0.10
string m
effect fx
real gap
real gapEx
real dur
real ls
unit ta
timer t
string atch
real x
real y
boolean typ
boolean tm
method destroy takes nothing returns nothing
call ReleaseTimer(this.t)
call .deallocate()
endmethod
private static method iterator takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
if this.tm then
if this.dur > 0.00 then
if this.gapEx > 0.00 then
set this.gapEx = this.gapEx - PERIODIC
else
if this.typ then
set this.fx = AddSpecialEffectTarget(this.m, this.ta, this.atch)
else
set this.fx = AddSpecialEffect(this.m, this.x, this.y)
endif
if this.ls > 0.00 then
call StartTimedEffect(this.fx, this.ls)
else
call DestroyEffect(this.fx)
endif
set this.gapEx = this.gap
endif
set this.dur = this.dur - PERIODIC
else
call this.destroy()
endif
else
if this.gapEx > 0.00 then
set this.gapEx = this.gapEx - PERIODIC
else
if this.typ then
set this.fx = AddSpecialEffectTarget(this.m, this.ta, this.atch)
else
set this.fx = AddSpecialEffect(this.m, this.x, this.y)
endif
if this.ls > 0.00 then
call StartTimedEffect(this.fx, this.ls)
else
call DestroyEffect(this.fx)
endif
set this.gapEx = this.gap
endif
endif
endmethod
static method create takes string mdl, unit target, real Gap, real duration, real lifespan, string attach, real x, real y returns thistype
local thistype this = thistype.allocate()
set this.m = mdl
set this.ta = target
set this.gap = Gap
set this.gapEx = 0.00
set this.t = NewTimerEx(this)
set this.atch = attach
set this.x = x
set this.y = y
set this.ls = lifespan
set this.dur = duration
if this.atch != null then
set this.typ = true
else
set this.typ = false
endif
if duration <= 0.00 then
set this.tm = false
else
set this.tm = true
endif
call TimerStart(this.t, PERIODIC, true, function thistype.iterator)
return this
endmethod
endstruct
function DestroyFxGap takes FxGap this returns nothing
call this.destroy()
endfunction
function CreateFxGap takes string modelPath, real gap, real x, real y returns FxGap
return FxGap.create(modelPath, null, gap, 0.00, 0.00, null, x, y)
endfunction
function CreateFxGapLifeSpan takes string modelPath, real gap, real lifespan, real x, real y returns FxGap
return FxGap.create(modelPath, null, gap, 0.00, lifespan, null, x, y)
endfunction
function CreateTimedFxGap takes string modelPath, real gap, real duration , real x, real y returns FxGap
return FxGap.create(modelPath, null, gap, duration, 0.00, null, x, y)
endfunction
function CreateTimedFxGapLifeSpan takes string modelPath, real gap, real duration, real lifespan, real x, real y returns FxGap
return FxGap.create(modelPath, null, gap, duration, lifespan, null, x, y)
endfunction
//*****************************************************************************************************************
function CreateFxGapTarget takes string modelPath, unit whichUnit, string attach, real gap returns FxGap
return FxGap.create(modelPath, whichUnit, gap, 0.00, 0.00, attach, 0, 0)
endfunction
function CreateFxGapLifeSpanTarget takes string modelPath, unit whichUnit, string attach, real gap, real lifespan returns FxGap
return FxGap.create(modelPath, whichUnit, gap, 0.00, lifespan, attach, 0, 0)
endfunction
function CreateTimedFxGapTarget takes string modelPath, unit whichUnit, string attach, real gap, real duration returns FxGap
return FxGap.create(modelPath, whichUnit, gap, duration, 0.00, attach, 0, 0)
endfunction
function CreateTimedFxGapLifeSpanTarget takes string modelPath, unit whichUnit, string attach, real gap, real duration, real lifespan returns FxGap
return FxGap.create(modelPath, whichUnit, gap, duration, lifespan, attach, 0, 0)
endfunction
endlibrary[/jass]
Table by Bribe
TimerUtils by Vexorian, Bribe & Magtheridon96
TimedEffects by moyack
Credits:
Vexorian, Bribe & Magtheridon96 for TimerUtils
Bribe for Table
moyack for TimedEffects