1
2
3
2
3
function queueSound(id, queue, sound) List.push(queue[id], sound) end
It should work now:
More
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- Queue implementation (https://www.lua.org/pil/11.4.html) List = {} Array = {} function Array.newBooleans(max) local array = {} for i=0,max do array[i] = false end return array end function Array.newLists(max) local lists = {} for i=0,max do lists[i] = List.new() end return lists end function List.new() return {first = 0, last = -1} end function List.push(list, e) list.first = list.first - 1 list[list.first] = e end function List.pop(list) if (List.isEmpty(list)) then return nil end list.last = list.last - 1 return list[list.last + 1] end function List.isEmpty(list) if (list.first > list.last) then return true else return false end end -- Using the queue queue = Array.newLists(32) isSoundRunning = Array.newBooleans(32) sounds = {{"mysound1",3000}, {"mysound2",5000}} function killSound(id) isSoundRunning[id] = false end function queueSound(id, queue, sound) List.push(queue[id], sound) end function playSound(id, queue) if (isSoundRunning[id] == false) then if (not List.isEmpty(queue[id])) then isSoundRunning[id] = true local sound = List.pop(queue[id]) if (id == 0) then parse("sv_sound "..sound[1]) else parse("sv_sound2 "..id.." "..sound[1]) end timer(sound[2], "killSound", tostring(id)) print(sound[1]) end end end addhook("ms100","ms") function ms() playSound(0, queue) for id in ipairs(queue) do playSound(id, queue) end end addhook("kill", "_kill") function _kill(id) -- queueSound(0, queue, sounds[1]) queueSound(id, queue, sounds[1]) end