[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Making a sound work with an if statement

Making a sound work with an if statement

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


Posted by Paul Balfe   (4 posts)  [Biography] bio
Date Mon 15 May 2023 12:38 AM (UTC)

Amended on Mon 15 May 2023 09:24 AM (UTC) by Nick Gammon

Message
Hi I'm learning how to script in lua, a soundpack for a mud I play. I have this trigger that's not working. Here's the trigger.


<triggers>
  <trigger
   enabled="y"
   group="misc"
   match="* leading into *"
   send_to="12"
   sequence="100"
  >
  <send>if "%1"=="unlock" then
playsound ("misc/doorunlock/"..math.random(1,3)..".ogg")
end</send>
  </trigger>
</triggers>


Here's the text I'm trying to make different sounds work when encountering: open close unlock lock opens unlocks locks closes.


You unlock a hunter green oak door leading into a rustic white log cabin on the north side of the street bearing the house number "1142".


Thank you.
[Go to top] top

Posted by Fiendish   USA  (2,523 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Mon 15 May 2023 06:02 AM (UTC)

Amended on Mon 15 May 2023 06:07 AM (UTC) by Fiendish

Message
With that match pattern and that text, "%1" will not be "unlock". It will be "You unlock a hunter green oak door".

Try turning on the regexp option on your trigger and then changing the match pattern to "^You (open|close|unlock|lock) .*"

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Paul Balfe   (4 posts)  [Biography] bio
Date Reply #2 on Mon 15 May 2023 09:35 AM (UTC)
Message
I tried what you said and it's still not working.
I want to make the unlock sound play when mush sees the unlock word in the match trigger. As well as lock open close unlocks locks opens closes.
What about the text after the .*"? Do I put leading into * after it?
I'm new in mush client.
Thanks.
[Go to top] top

Posted by Fiendish   USA  (2,523 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Mon 15 May 2023 06:53 PM (UTC)

Amended on Tue 16 May 2023 01:08 AM (UTC) by Fiendish

Message
Upon closer inspection I realize I missed several details, so here's a more complete answer.

Ok, you're new so first let me give you a copy/paste version to start from just to make sure...


<triggers>
  <trigger
   enabled="y"
   group="misc"
   match="^You (open|close|unlock|lock) .*"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
mapping = {
  ["open"] = "misc/dooropen/"..math.random(1,3)..".wav",
  ["close"] = "misc/doorclose/"..math.random(1,3)..".wav",
  ["unlock"] = "misc/doorunlock/"..math.random(1,3)..".wav",
  ["lock"] = "misc/doorlock/"..math.random(1,3)..".wav"
}

print("TRIGGER MATCHED. SOUND FILE: " .. mapping["%1"])</send>
  </trigger>
</triggers>


This will match on "You open/close/etc ..." messages (when YOU interact with a door) and print a message showing that the trigger matched and what sound file would play.

Once you see that working, you'll want to:

1. convert your .ogg files to 16-bit, 22.05 KHz, PCM (ie. uncompressed), Mono or Stereo WAV files, because MUSHclient does not support OGG format.

2. change the print to instead use either https://www.gammon.com.au/scripts/doc.php?function=Sound or https://www.gammon.com.au/scripts/doc.php?function=PlaySound

3. make a second trigger for a different pattern for when someone else interacts with the door, because the message would be different.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (23,006 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 16 May 2023 05:53 AM (UTC)
Message
Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Paul Balfe   (4 posts)  [Biography] bio
Date Reply #5 on Tue 16 May 2023 12:00 PM (UTC)
Message
The sound is still not playing when I put in your code for the trigger we're working with the door.
I want the client to play the sound when it sees open close lock unlock in this text:
You unlock a hunter green oak door leading into a rustic white log cabin on the north side of the street bearing the house number "1142".
And btw I just made a mp3 file of a sound and put it in mush and it played just fine as well as ogg.
Thanks.
[Go to top] top

Posted by Nick Gammon   Australia  (23,006 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Tue 16 May 2023 08:21 PM (UTC)
Message
Please show exactly how you have amended Fiendish's trigger example.

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Paul Balfe   (4 posts)  [Biography] bio
Date Reply #7 on Tue 16 May 2023 08:55 PM (UTC)
Message
Hi
Here's the trigger.
<triggers>
<trigger
enabled="y"
group="misc"
match="&quot;^You (open|close|unlock|lock) .*&quot;"
regexp="y"
send_to="12"
sequence="101"
>
<send>
mapping = {
["open"] = playsound "misc/dooropen/"..math.random(1,6)..".ogg",
["close"] = playsound "misc/doorclose/"..math.random(1,10)..".ogg",
["unlock"] = playsound "misc/doorunlock/"..math.random(1,3)..".ogg",
["lock"] = playsound "misc/doorlock/"..math.random(1,6)..".ogg"
}

print("TRIGGER MATCHED. SOUND FILE: " .. mapping["%1"])</send>
</trigger>
</triggers>
Thanks.
[Go to top] top

Posted by Fiendish   USA  (2,523 posts)  [Biography] bio   Global Moderator
Date Reply #8 on Tue 16 May 2023 09:42 PM (UTC)

Amended on Tue 16 May 2023 09:53 PM (UTC) by Fiendish

Message
MUSHclient does not support OGG or MP3 files. You have to convert them to WAV like I described.

PlaySound is also case-sensitive. You cannot freely alter the capitalization of functions in Lua.

PlaySound also requires more than just one input argument. If you want to use only one input argument, you need to use the Sound function instead.

Also I said to change the print, not the mapping. The proper modification (only after you see the print statements appear from the version I originally posted) would be:


<triggers>
  <trigger
   enabled="y"
   group="misc"
   match="^You (open|close|unlock|lock) .*"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
mapping = {
  ["open"] = "misc/dooropen/"..math.random(1,3)..".wav",
  ["close"] = "misc/doorclose/"..math.random(1,3)..".wav",
  ["unlock"] = "misc/doorunlock/"..math.random(1,3)..".wav",
  ["lock"] = "misc/doorlock/"..math.random(1,3)..".wav"
}

Sound(mapping["%1"])
</send>
  </trigger>
</triggers>

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by AdInfinitum   (74 posts)  [Biography] bio
Date Reply #9 on Wed 17 May 2023 02:20 PM (UTC)
Message
Fiendish said:


mapping = {
  ["open"] = "misc/dooropen/"..math.random(1,3)..".wav",
  ["close"] = "misc/doorclose/"..math.random(1,3)..".wav",
  ["unlock"] = "misc/doorunlock/"..math.random(1,3)..".wav",
  ["lock"] = "misc/doorlock/"..math.random(1,3)..".wav"
}



I am curious if the files are indeed named "1.ogg", "2.ogg", and "3.ogg", too. Obviously they still need conversion to .wav, as stated. Another thing to note is if the pathing is actually accurate. Is the 'misc' folder indeed in the 'sounds' directory?

Of course, if more sounds are added, the math.random would need to be updated, but in this situation, I'd imagine a function that selects a random filename from 'utils.readdir' would be more beneficial. Just some food for thought.
[Go to top] 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.


6,746 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]