WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Trigger PlaySound upon keyword event (https://www.wowinterface.com/forums/showthread.php?t=58485)

rbpaiett 12-26-20 05:28 PM

Trigger PlaySound upon keyword event
 
I'm looking to create a macro/script/addon where if I receive a system message that any of my auction items expired or sold, I would hear a sound cue.


So basically it would search anything from CHAT_MSG_SYSTEM by keywords and triggers a PlaySound, example:

The word 'sold' appears, it activates PlaySound(5274) and ...
The word 'expired' appears, it activates PlaySound(5275).

I used to have this but lost it when I forgot to make a backup. Any advice or instruction would be very helpful.

Thanks.

Note: I'm a complete newbie with this so I don't know how to even set this up.

Seerah 12-26-20 07:23 PM

Lua Code:
  1. local f = CreateFrame("Frame")     --create a frame to listen for the event
  2. f:RegisterEvent("CHAT_MSG_SYSTEM")     --register for the event you want to listen for
  3. f:SetScript("OnEvent", function(self, event, msg)     --tell WoW what to do when the event fires
  4.           if strfind(msg, "sold") then     --we only registered for one event, so we don't even have to check to see which one it was
  5.                PlaySound(5274)
  6.           elseif strfind(msg, "expired") then
  7.                PlaySound(5275)
  8.           end
  9.      end)

rbpaiett 12-26-20 07:34 PM

<Bows before Seerah>

UPDATE:

Out of curiosity, what is the purpose of adding 'self' to it? You have an event that contains a message, it's not like one is listening for other players.

Seerah 12-26-20 10:07 PM

What you call variables is irrelevant. The first return from an event firing is the frame that was listening to it. The second return is the specific event that was fired in case your frame was listening for more than one. Beyond that, anything else depends on which event it was and what comes with it.

rbpaiett 12-27-20 01:38 AM

Ok, very good.


All times are GMT -6. The time now is 11:59 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI