This is what I came up with:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
addhook("say", "say_hook") function say_hook(id, message) if message == "suicide" then Thread(function() msg2(id, "You will die in 3 seconds!") msg2(id, "3..") sleep(1000) msg2(id, "2..") sleep(1000) msg2(id, "1..") sleep(1000) parse("killplayer "..id) end) return 1 end end
What happened here? I created a Thread that is actually instantly running lua coroutine. Every time you call sleep(time) inside a coroutine it will yield the current coroutine and resume it after the specified time using cs2d timer.
Because it is so simple you don't have (yet) any control over the threads. You can't stop/resume/suspend them outside the thread itself. Ofcourse this can be easily added but I'm feeling kind of lazy today. If anyone is willing to take this any further, please do share your modifications!