- Joined
- Jun 26, 2020
- Messages
- 1,928
I looked for tutorials, but they don't solve all my doubts, so I'm here to ask you.
Ok, you don't know that timers can be used in a different way in Jass.Here is a tutorial on timers
Then when you have made the trigger in GUI you can select it, go to Edit -> Convert to Custom Text.
It will convert the trigger to Jass so you can see how it works.
I'm in the 1.26You should look for the library "TimerUtils" for Jass. AFAIK it's the standard library used for better timer recycling and associating data with timers.
That said, Timers are something Lua is much better at than Jass, since you can bind functions as callbacks from TimerStarts. It's much easier to persist data into these functions, since they can access variables from when the timer was started.
(Or, as I prefer, use Typescript that is compiled to Lua! It's great!)
function Trig_Meditation_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A032' ) ) then
return false
endif
return true
endfunction
function ZenCheck takes unit monk returns boolean
if GetUnitState(monk, UNIT_STATE_LIFE) < GetUnitState(monk, UNIT_STATE_MAX_LIFE) then
return false
endif
if (GetUnitState(monk, UNIT_STATE_MANA) < GetUnitState(monk, UNIT_STATE_MAX_MANA)) then
return false
endif
return true
endfunction
function ZenTick takes nothing returns nothing
local timer cl = GetExpiredTimer()
local unit w = LoadUnitHandle (udg_HT_self, GetHandleId(cl), 57)
if ( GetUnitCurrentOrder(w) == String2OrderIdBJ("corporealform") ) then
call SetUnitState (w, UNIT_STATE_LIFE, (GetUnitState(w, UNIT_STATE_LIFE) + (GetUnitState(w, UNIT_STATE_MAX_LIFE) / 20 ) ) )
call SetUnitState (w, UNIT_STATE_MANA, (GetUnitState(w, UNIT_STATE_MANA) + (GetUnitState(w, UNIT_STATE_MAX_MANA) / 20 ) ) )
if ZenCheck(w) == true then
call IssueImmediateOrder (w, "holdposition")
endif
else
call PauseTimer (cl)
call DestroyTimer (cl)
call FlushChildHashtableBJ( GetHandleId(cl), udg_HT_self )
call BJDebugMsg ("timer cleared")
endif
set cl = null
set w = null
endfunction
function Trig_Meditation_Actions takes nothing returns nothing
local timer ck
if (ZenCheck(GetTriggerUnit()))== true then
call IssueImmediateOrder (GetTriggerUnit(), "holdposition")
else
set ck = CreateTimer()
call SaveUnitHandle (udg_HT_self, GetHandleId(ck), 57, GetTriggerUnit())
call TimerStart ( ck, 1.00, true, function ZenTick )
endif
set ck = null
endfunction
//===========================================================================
function InitTrig_Meditation takes nothing returns nothing
set gg_trg_Meditation = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Meditation, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Meditation, Condition( function Trig_Meditation_Conditions ) )
call TriggerAddAction( gg_trg_Meditation, function Trig_Meditation_Actions )
endfunction