-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPlay_Random_Sound.xml
More file actions
85 lines (61 loc) · 2.23 KB
/
Play_Random_Sound.xml
File metadata and controls
85 lines (61 loc) · 2.23 KB
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
84
85
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, June 24, 2008, 3:20 PM -->
<!-- MuClient version 4.29 -->
<!-- Plugin "Play_Random_Sound" generated by Plugin Wizard -->
<muclient>
<plugin
name="Play_Random_Sound"
author="Nick Gammon"
id="461479af5d149307e69e305f"
language="Lua"
purpose="Plays a sound from a group of sounds"
date_written="2008-06-24 15:08:41"
requires="4.29"
version="1.0"
>
<description trim="y">
<![CDATA[
Implements an interface for other plugins, or triggers etc. to play a sound chosen at random.
Examples of use:
-- loop a battle sound in buffer 9 at -6 db
check (CallPlugin ("461479af5d149307e69e305f", "PlayRandomSound", "9,battle,y,-6"))
-- play a single dagger sound in first free buffer at full volume
check (CallPlugin ("461479af5d149307e69e305f", "PlayRandomSound", "0,dagger,n,0"))
]]>
</description>
</plugin>
<!-- Script -->
<script>
<![CDATA[
sounds = {}
-- args are: buffer,folder,loop,level
function PlayRandomSound (args)
local buffer, folder, loop, level = string.match (args,
"^(%d+),%s*(%w+),%s*([y|n]),%s*(%-?%d+)$")
if not buffer then
error ("Arguments to PlayRandomSound are: buffer,folder,loop(y/n),level, you supplied: " .. args)
end -- if
-- if folder not read in yet, go grab it
if not sounds [folder] then
sounds [folder] = {} -- table of sound file names
local t = assert (utils.readdir (GetInfo (74) .. folder .. "/*wav"))
-- copy from keys of the table of names, into a new table, dropping files starting with "."
for k in pairs (t) do
if k:sub (1, 1) ~= "." then
table.insert (sounds [folder], k)
end -- not temporary files
end -- for adding each one
-- check we got something
assert (#sounds [folder] > 0, "No sounds in folder " .. folder)
ColourNote ("white", "green", "Found " .. #sounds [folder] .. " sounds in " .. folder .. " folder.")
end -- if not dagger sounds table yet
-- choose one
sound = folder .. "/" .. sounds [folder] [math.random (#sounds [folder])]
-- play it
check (PlaySound (buffer, sound, loop == "y", level ))
end -- function PlayRandomSound
math.randomseed (os.time ())
]]>
</script>
</muclient>