MSP and Legends of Kallisti mud

Posted by Mariachiac on Mon 14 Dec 2020 03:15 PM — 20 posts, 67,881 views.

#0
Hello,

I am a blind user of Mush Client. I have installed the mus reader plugin and have been able to get muds to talk. However, now I'm trying to get msp to work in mush.
I know a few muds that use the mud sound protocol (MSP), but I have not gotten any luck to make sounds play.
I've added the default msp script for sounds that's included with Mushclient 5.06.
When I load the plugin in the world, Legends of Kallisti, I do
set_msp_path C:\Users\user_name\MUSHclient\sounds\msp
I hear no sound. If I need to add a trigger or get a script to play sounds, let me know.
When ever the mud tries to play a sound via msp I get the following line of text
!!SOUND(song_gelsewhere.wav)
That's just an example. So I assume the trigger would have to have a wildcard. I do not yet understand how to do triggers in Mush Client yet as I'm new to using the client.

Thanks
Australia Forum Administrator #1
Odd. That trigger is part of the plugin. Did you install msp.xml plugin, or MSP_Lua.xml? The Lua one is more recent.

From your description it sounds like the plugin is not actually installed. See File menu -> Plugins.
Australia Forum Administrator #2
 !!SOUND(song_gelsewhere.wav)

Is that literally what is shown? If the filename has some special characters in it (eg. an underscore) then the plugin might need to be modified slightly.

#3
Okay... Where do I get the modified version of msp? I just have the default msp plugin installed that ships with the default mushclient download 5.06.
When I log in... I get text saying sound.wav (i.e., "!!SOUND(miscellaneous_fanfare*.wav)"
What modifications will I need to make?

Thanks
#4
The plugin I have installed is msp.xml.
I assume it's installed since I can do msp_set_path to the directory the sounds are located in (e.g., C:\Users\My_username|MushClient\sounds|msp.
Thanks
#5
Hello, ok I went to this link and coppied the code to create the MSP_Lua.xml fole.

https://www.gammon.com.au/forum/?id=12542

When I do ctrl-i and paste this line, sound plays
PlaySound (0, "../sounds/msp/song_gelsewhere.wav")
However, when I type the command to trigger that sound, I get no sound.
Command to trigger the msp sound in Legends of Kallisti: sing gelsewhere
I get recalled back to the waypoint and I hear no sound.
I've also tried the above with the included msp.xml script in Mushclient 5.06.
It's looking for msp sounds in C:\Users\my_username\MUSHclient\sounds\msp

Thanks
Australia Forum Administrator #6

Inside that plugin is a trigger. Look for this line (at or around line 44):

       match="!!SOUND\(([A-Za-z0-9./]+).*\)"

That matches the !!SOUND stuff coming from the MUD. It doesn’t currently recognize an underscore which your sound files seem to have in them. Add an underscore inside the square brackets, eg.

       match="!!SOUND\(([A-Za-z0-9./_]+).*\)"

Also, I am unsure about this filename that you quoted:

"!!SOUND(miscellaneous_fanfare*.wav)"

The asterisk there is rather strange, that is usually a wildcard. The plugin is not designed to handle wildcarded sound files.

#7
That worked.
Thank you sooooo much!!!!
#8
Hello,
The only thing i need to figure out is how to set a variable for the session Legends of Kallisti.
I have a world created.

Thanks
Australia Forum Administrator #9
Can you give more details? There are multiple ways of setting variables. What are you trying to achieve by setting a variable?
#10
Hello,
Sorry fo r the late response.
I'm thinking I need to set a variable sinc everytime I log onto
kallistimud.com port 4000
and the msp plugin loads I have to set the directory manually for it to play sounds.
the directory I have the msp sounds is:
"C:\Users\my_user\MUSHclient\sounds\msp"
So I'm not sure how to make that automatic when ever I log into the mud.

One other question ,is the default msp.xml file suitable for msp uses or is there an upgraded script that allows for the playing of simultaneous sounds?

Thank you
Australia Forum Administrator #11
If you are using msp.xml as your MSP plugin, then modify line 77 which currently reads:


  <variable name="msp_path">c:\mushclient\msp\</variable>


Instead of "c:\mushclient\msp\" replace that with your own path to the sound files.




If you use msp_lua.xml instead (as mentioned earlier) then it remembers the sound file path once you change it the first time. Also, msp_lua.xml uses a better technique for playing sounds and can play up to 10 simultaneously.
#12
Hello,

I've tried using msp_lua.xml from:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=783
and now the sounds do not play.
I've added the "_" in his line
match="!!SOUND\(([A-Za-z0-9./]+).*\)"
It now reads:
match="!!SOUND\(([A-Za-z0-9./_]+).*\)"
However, this does work with the vb script msp.xml.

Please help when you are able.
Australia Forum Administrator #13
The msp_lua.xml plugin is in fact on:

http://www.gammon.com.au/forum/?id=12542&reply=6#reply6
Australia Forum Administrator #14
In reply #5 you said you were using msp_lua.xml, and in reply #7 you said that it worked.

I'm confused as to why you are now saying it doesn't work.

When you say that the sounds do not play, does the !!SOUND line also appear on the screen (indicating that the trigger didn't match)?
#15
Hello Nick,

I'm sory for not clarifying. In reply number 7 I was using msp.xml. I forgot to state that.
Moving forward, when I load msp_lua.xml I hear no sound. What appears in the output window when a sound is suppose to play is:
1.0
If I load msp.xml and I set the msp path to obtain sounds, sound works. I've not edited msp.xml to autoload the the path to obtain the msp sounds as I had wanted to try msp_lua.xml.

Sorry for the confusion.
I appreciate your responses.
Australia Forum Administrator #16
Ah, I see. There was a second reference to !!SOUND in that plugin.

Look at line 91, which reads:


    local text = string.gsub (v.text, "!!SOUND%(([%a%d./]+).-%)", fSound)


Add the underscore there also, before the right-hand bracket, so it reads:


    local text = string.gsub (v.text, "!!SOUND%(([%a%d./_]+).-%)", fSound)


Then it should work. I tested it on your MUD.
#17
Everything works as expected.
The only file that doesn't play is when I log into the mud.
After pressing 1 to enter the mud, my screen reader says the following when the fan fare is suppose to play:
1.0
When I go to the msp path where the sound files are located
The files are named
miscellaneous_fanfare0.
There is 6 files like that ranging from miscellaneous_fanfare0 to miscellaneous_fanfare5.


Awesome work.
One other question. What shall I read to learn how to do triggers using lua for mush?
There is a built-in help system which I access with the plugin
MUSHclient_Help.xml.
The files are also accessed via the online documentation of this website.
However, if there is an intro that is worth checking out, please let me know.

Warmest regards
Australia Forum Administrator #18
You may find this helpful:

http://www.gammon.com.au/forum/?id=8411

There are quite a few screenshots, but also the same information in text form (in particular the code parts).
Australia Forum Administrator #19
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.

Template:saveplugin=MSP_Lua
To save and install the MSP_Lua plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. 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.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file MSP_Lua.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. 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>