The are many timer systems out there and I dont want to compete with them as it spams a lot nowadays and this is heavily
inspired by Nesthauru's CTL except it uses different intervals instead of only 0.03125 or constant, the cons of
this one is that it creates multiple timers like TimedLoop (by vexorian)...
The difference is that you dont need to manually deallocate the instance and this uses only 3 implementations, 1 is optional...
===Dynamic Timer v1.2
===Created by Mckill2009
- CTL by Nesthaurus
- Dynamic GUI Indexing by Hanky
- Not optional, this needs to be on TOP of implementations
- You may declare your locals here
- This is where your condition is generated/running, this by default is TRUE
- If it encounters FALSE on the first "if", statement, it will automatically deindexed
- Take note that you dont need to put an "endif" to your condition
local unit x = GetUnitX(.hero)
local unit y = GetUnitY(.hero)
if UnitAlive(.hero) then
YOUR ACTIONS HERE!
- Optional, used to null your local variables created via DTloop
- Not optional, this needs to be BELOW of DTloop or implementations
- This calls the "create(real variable)", this is where a timer interval is dynamic
static method create takes real interval returns thistype
- By default, timer runs at INTERVAL (0.03125)
- The "interval" simply delays the 0.03125
- Deaod for suggesting standard methods
globals //These should NOT be modified privateconstantinteger MAX_INDEX =8190 privateconstantreal INTERVAL =0.03125 endglobals
module DTloop //not optional readonlyboolean bol readonlyreal gap readonlyreal in staticboolean chkindex =true staticinteger index1 =0// staticintegerarray indexAr statictimer t
struct DT //extends array //you may also use custom allocators //implement Alloc unit u real dur staticthistype d staticreal interval =1.8
method destroy takesnothingreturnsnothing callBJDebugMsg("HERO NAME ====="+GetUnitName(.u)) set.u=null callBJDebugMsg("HERO NAME ====="+GetUnitName(.u)) call.deallocate() endmethod
implement DTloop localtexttag tag localreal du if.dur>0and UnitAlive(.u)then set.dur=.dur-0.5 set du =.dur set tag =CreateTextTag() callSetTextTagPosUnit(tag,.u,0) callSetTextTagText(tag,R2S(du),0.025) callSetTextTagPermanent(tag,false) callSetTextTagVelocity(tag,0.03,0.03) callSetTextTagLifespan(tag,3) callSetTextTagFadepoint(tag,0.01) //or best to null the local "tag" here XD set tag =null //no need to put "endif" coz if this will encounter FALSE //it will automatically be deindexed
implement DTnulls //optional //null locals here set tag =null
staticmethod cast takesnothingreturnsboolean localthistypethis localunit hero =GetTriggerUnit() localunit first callGroupEnumUnitsInRange(bj_lastCreatedGroup,GetUnitX(hero),GetUnitY(hero),1000.,null) loop set first =FirstOfGroup(bj_lastCreatedGroup) exitwhen first==null if interval >0.3then set interval = interval -0.3 endif setthis= create(interval) set.u= first set.dur=GetRandomReal(5.,10.) callGroupRemoveUnit(bj_lastCreatedGroup,first) endloop returnfalse endmethod
privatestaticmethod onInit takesnothingreturnsnothing localtrigger t =CreateTrigger() callTriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT) callTriggerAddCondition(t,Condition(functionthistype.cast)) endmethod endstruct
- Changed many API name and structures
- Automatically deallocates instance when done
- Added optional nulling of locals and instance
- API name changed so that it can use standard and custom allocators
- DTendnulls removed, codes shortened
privatemethod destroy takesnothingreturnsnothing // // clean your struct here // set loopInstancesCount=loopInstancesCount-1 set loopInstances[loopIndex]=loopInstances[loopInstancesCount] set loopInstances[loopIndex].loopIndex=loopIndex if loopInstancesCount==0then callPauseTimer(LOOP_TIMER) endif call deallocate() endmethod
privatestaticmethod callback takesnothingreturnsnothing localinteger i=loopInstancesCount-1 localthistypethis loop exitwhen i<0 setthis=loopInstances[i] // // do your things here, dont forget to call destroy() somewhen // set i=i-1 endloop endmethod
staticmethod create takesnothingreturnsthistype localthistypethis=allocate() // // initialize the struct here // set loopInstances[loopInstancesCount]=this set loopIndex=loopInstancesCount if loopInstancesCount==0then callTimerStart(LOOP_TIMER, LOOP_TICK,true,functionthistype.callback) endif set loopInstancesCount=loopInstancesCount+1 returnthis endmethod endstruct
the code you gave doesnt work on extended aray unless you implement custom allocators,
mine does, besides its a pain in the yes to cnp all those codes than just implementing ;)...
struct SpellTest extendsarray // declare members implement DTloop //declare locals iftruethen //running conditions //no need to put endif for the first IF statement //if it encounters false, it will be deindexed implement DTend //no need to put anything below this implementation
Mag, one does not simply mention "Nestharus" to prove a point about "code beauty". Yes he may finally be back to coding with real names but still much of his JASS work on this site is full of omgwtfbbq. Yours had been just like it in the past before realizing the optimizer is no longer broken.
How to post your triggers on the Hive Workshop. JPAG - Bettering the cause of readable source code.
from the guy who abuse module and custom struct allocators and struct extends array.
We don't have the same definition of readability :o
- There are bugs with wc3, but most of time, the bug is between the keyboard and the chair.
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.
You spam "...", "lol", and smilies such as "; p", "^)^",">.>"? You think you're the best and all other ones are stupids or at least less clever than you ? You think your errors are funny, while the other ones are incredibly lame ?
Maybe you've too much ego,or worse, you're a douchebag