Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ MSP and Legends of Kallisti mud

MSP and Legends of Kallisti mud

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by Mariachiac   (10 posts)  Bio
Date Reply #15 on Sat 09 Jan 2021 04:09 PM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #16 on Mon 11 Jan 2021 05:04 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Mariachiac   (10 posts)  Bio
Date Reply #17 on Tue 12 Jan 2021 02:48 PM (UTC)
Message
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
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #18 on Tue 12 Jan 2021 08:21 PM (UTC)
Message
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).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #19 on Tue 12 Jan 2021 09:14 PM (UTC)

Amended on Tue 12 Jan 2021 09:20 PM (UTC) by Nick Gammon

Message
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>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


45,273 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.