Tasks
Code
Changes
Create a timer that fires a function "foo" after 2 seconds expired after map initialization.
In function "foo" the expired time must be printed on screen and the expired timer destroyed.
Following global variables must be declared and used (<type> , <name>):
- hashtable Hash
Create a timer on map initialiaztion.
The unit must be saved into hashtable, using the timer as ParentKey, which means that the used index must be directly related to the timer object itself.
The timer should periodicly (each second) call a function "DamageUnit", which goal is to retrieve the saved unit from hashatble, and to decrease it's life by "10".
In case the unit is dead, the timer must be destroyed.
JASS:
native UnitAlive takes unit whichUnit returns boolean
scope Part1n2 initializer init
globals
hashtable Hash = InitHashtable()
endglobals
private function foo takes nothing returns nothing
local timer t = GetExpiredTimer()
call BJDebugMsg(R2S(TimerGetElapsed(t)) + " second(s) elapsed")
call DestroyTimer(t)
set t = null
endfunction
private function DamageUnit takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = LoadUnitHandle(Hash, GetHandleId(t), 0)
if UnitAlive(u) then
call SetWidgetLife(u, GetWidgetLife(u) - 10)
else
call FlushChildHashtable(Hash, GetHandleId(t))
call DestroyTimer(t)
endif
set t = null
set u = null
endfunction
private function init takes nothing returns nothing
local timer clock = CreateTimer()
local timer dpsTimer = CreateTimer()
call SaveUnitHandle(Hash, GetHandleId(dpsTimer), 0, CreateUnit(Player(0), 'hfoo', 0, 0, 0))
call TimerStart(clock, 2, false, function foo)
call TimerStart(dpsTimer, 1, true, function DamageUnit)
endfunction
endscope
-submission
-now uses
UnitAlive
-replaced any
GetUnitState and SetUnitState
with GetWidgetLife and SetWidgetLife
Attachments
Last edited: