Hello, well I want to present a little system of mine today. I made it because I was to lazy to make for every periodic spell or other periodic stuff, where I used structs, a timer loop. So I created this. It's very easy to use. But I don't know if it is so effective like TimerUtils. For the updated version visit this thread: Costum Motion Pros:
- Good speed
- Easy to use
- Can save time (because you don't have to write everytime a timer loop)
Cons:
- Well it just work for structs else I see no big cons
System Script
Code
//! textmacro CostumInterface takes Loop,End,path,periodic
library CostumInterface$path$ initializer init
interface $path$Loop
boolean active=false
boolean paused=false
method $Loop$ takes nothing returns nothing
method $End$ takes nothing returns nothing
endinterface
globals
private $path$Loop array $path$_loopObject
private integer $path$_size=0
private trigger $path$_loop
constant real $path$_periodic=$periodic$
endglobals
function AddObjectTo$path$ takes $path$Loop loopObject returns integer
set $path$_loopObject[$path$_size]=loopObject
set $path$_loopObject[$path$_size].active=true
set $path$_size=$path$_size+1
if not IsTriggerEnabled($path$_loop) then
call EnableTrigger($path$_loop)
endif
return $path$_size
endfunction
private function Loop$path$ takes nothing returns nothing
local integer index=0
loop
exitwhen index==$path$_size
if $path$_loopObject[index].active and not $path$_loopObject[index].paused then
call $path$_loopObject[index].$Loop$.execute()
set index=index+1
elseif $path$_loopObject[index].paused then
set index=index+1
else
call $path$_loopObject[index].$End$()
set $path$_size=$path$_size-1
set $path$_loopObject[index]=$path$_loopObject[$path$_size]
endif
endloop
if $path$_size<=0 then
call DisableTrigger($path$_loop)
endif
endfunction
private function init takes nothing returns nothing
set $path$_loop=CreateTrigger()
call TriggerRegisterTimerEvent($path$_loop,$path$_periodic,true)
call TriggerAddAction($path$_loop,function Loop$path$)
call DisableTrigger($path$_loop)
endfunction
endlibrary
//! endtextmacro
How to use?
The first thing you do is to make a runtextmacro where you init the struct loop (like setting the periodic time amount). In this example I want to have the periodic time amount of 0.03. Also I name the loop Motion. The periodic function I name motion and the endfunction I name endmotion. Then it have to look like this:
Code
//! runtextmacro CostumInterface("motion","endmotion","Motion","0.03")
Well it's very easy to import in your struct. Well first you have to create a struct. In this example I call the struct whatever. So I start to write:
Code
struct whatever
endstruct
For that we just add "extends MotionLoop" and the two methods "motion" and "endmotion". Then it look like this:
Code
struct whatever extends MotionLoop
method motion takes nothing returns nothing
endmethod
method endmotion takes nothing returns nothing
endmethod
endstruct
Well now the struct is added to the periodic loop. Now there are several functions that let you start,pause and end the periodic execution:
Code
call AddObjectToMotion(struct) //this is to add a struct to the loop
set whatever.active=true //this is default after you have added a function to the loop
set whatever.active=false //this end the loop and execute endmotion
set whatever.paused=true //this pause the execution of this struct but don't destory it
set whatever.paused=false //this enable again the periodic execution
If you want to have example how well it works just look, for example, at my Vast Plane spell. (Vast Plane) Well I hope you enjoy.