Quote:
There is 6 files like that ranging from miscellaneous_fanfare0 to miscellaneous_fanfare5.
It looks like they are wildcarded file names. For example: miscellaneous_fanfare*.wav.
I've modified the plugin to handle wildcards, assuming the wildcard represents a single character, and that file is in the "root" MSP sound file directory.
The changes were so extensive that I reproduce the modified plugin below.
 |
To save and install the MSP_Lua plugin do this:
- Copy the code below (in the code box) to the Clipboard
- Open a text editor (such as Notepad) and paste the plugin code into it
- Save to disk on your PC, preferably in your plugins directory, as MSP_Lua.xml
- The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file MSP_Lua.xml (which you just saved in step 3) as a plugin
- Click "Close"
- Save your world file, so that the plugin loads next time you open it.
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="MSP_Lua"
author="Nick Gammon"
id="7da63d78d9f91bebb5285127"
language="Lua"
purpose="Emulates MSP (MUD Sound Protocol)"
save_state="y"
date_written="2014-08-10 15:43"
date_modified="2020-01-13 08:00"
requires="4.54"
version="2.0"
>
<description trim="y">
<![CDATA[
Type: "msp:help" to see this help.
See: http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=783 for a more complete description.
You will need to get the sound files manually (ie. from the MUD) and install them before using this.
The plugin is configured to look for them in the "sounds" directory of the MUSHclient installation,
but you can change that by typing:
set_msp_path new_path
eg.
set_msp_path d:\muds\mushclient\msp
This version supports wildcards in the filename, where an asterisk in the filename is considered
a single-character wildcard. Such files must appear in the "root" directory of the MSP path.
To make an asterisk match multiple characters, change the line in the plugin:
fixedName = string.gsub (fixedName, '%*', '.')
To read:
fixedName = string.gsub (fixedName, '%*', '.-')
]]>
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="!!SOUND\(([A-Za-z0-9./_*]+).*\)"
name="sound"
omit_from_output="y"
regexp="y"
script="OnSound"
sequence="100"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
script="On_set_MSP_path"
match="set_msp_path *"
enabled="y"
>
</alias>
<alias
script="OnHelp"
match="msp:help"
enabled="y"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
function fSound (filename)
-- handle wildcards
if string.find (filename, '%*') and SoundFiles then
local matchingFiles = { }
-- get rid of magic characters in patterns (except asterisk)
local fixedName = string.gsub (filename, "[%%%]%^%-$().[+?]", "%%%1")
-- make asterisk into ".-" to make it a wildcard
fixedName = string.gsub (fixedName, '%*', '.')
for filename in pairs (SoundFiles) do
if string.match (filename, fixedName) then
table.insert (matchingFiles, filename)
end -- if wildcard matched
end -- for
if #matchingFiles == 0 then
ColourNote ("red", "", "Warning: could not find wildcarded sound file: " .. filename)
else
-- pick a file at random
filename = matchingFiles [math.random (#matchingFiles)]
end -- if
end -- if
local result = PlaySound (0, GetVariable ("msp_path") .. filename)
if result ~= error_code.eOK then
ColourNote ("red", "", "ERROR: " .. error_desc [result] .. " playing " .. GetVariable ("msp_path") .. filename)
end -- if
return "" -- omit MSP stuff from output
end -- function fSound
-- handle a line with !!SOUND in it
function OnSound (name, line, wildcards, styles)
-- echo existing line with colours, sending !!SOUND part to a function
for _, v in ipairs (styles) do
local text = string.gsub (v.text, "!!SOUND%(([%a%d./_*]+).-%)", fSound)
ColourTell (RGBColourToName (v.textcolour),
RGBColourToName (v.backcolour),
text)
end -- for each style run
Note ("") -- finish the line
end -- function OnSound
function ScanSoundFiles ()
SoundFiles, err = utils.readdir (GetVariable ("msp_path") .. "*.wav")
if not SoundFiles then
ColourNote ("red", "", "Could not scan sound files directory: " .. err)
return
end -- if
local count = 0
for k, v in pairs (SoundFiles) do
count = count + 1
end -- for
ColourNote ("green", "", "Found " .. count .. " sound files")
end -- ScanSoundFiles
-- change desired sound file path
function On_set_MSP_path (name, line, wildcards)
local path = wildcards [1]
-- ensure trailing backslash
if string.sub (path, -1) ~= "\\" then
path = path .. "\\"
end -- if
SetVariable ("msp_path", path)
ColourNote ("green", "", "MSP sound files will be obtained from " .. path)
ScanSoundFiles ()
end -- function On_set_MSP_path
-- do telnet negotiation
function OnPluginTelnetRequest (type, data)
if type == 90 and data == "WILL" then
return true -- IAC DO MSP
else
return false
end -- if
end -- function OnPluginTelnetRequest
-- show help
function OnHelp ()
print (GetPluginInfo (GetPluginID (), 3))
end -- function OnHelp
-- find all the sound files in the requested directory, in case they use wildcards
function OnPluginInstall ()
ScanSoundFiles ()
end -- OnPluginInstall
-- use supplied path or default
msp_path = GetVariable ("msp_path") or GetInfo (74)
]]>
</script>
</muclient>
|