Thread Tools Display Modes
04-18-06, 01:57 PM   #1
evil_oatmeal
A Murloc Raider
Join Date: Mar 2006
Posts: 7
I need some help with events

Hey there, this is my first time hanging with lua and generally thje guts of a wow mod, so here's my question:

I'm trying to create something very simple, a mod that reacts to things being typed in the chat frame. Is this possible? could I use some sort of CHAT_MSG event for this? Scenario:

Let's say i had succesfully made this mod, then, I log in to the game and type the word 'cake' the mod would respond by putting a message in the chat frame saying 'You typed cake! Good job!".

Is this doable? And if so how? Thanks in advance for th help
  Reply With Quote
04-19-06, 01:51 AM   #2
evil_oatmeal
A Murloc Raider
Join Date: Mar 2006
Posts: 7
Nobody likes me.... oh well... I'll just go sit in the corner....
  Reply With Quote
04-19-06, 02:18 AM   #3
Maia
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 15
yes, it is possible. register the event CHAT_MSG_CHANNEL and once it fires grab the arguments arg1 (the message), arg2 (the sender), arg9 (the channel). Now do your checks (only in specific channel,...) and use string.find() to check if the word you're looking for is in the parsed message...
  Reply With Quote
04-20-06, 03:55 AM   #4
evil_oatmeal
A Murloc Raider
Join Date: Mar 2006
Posts: 7
aha.. cool... I think I understood that... I'm new to this kind of thing, I'll give it a try
so... i would do something like?:

RegisterEvent("CHAT_MSG_CHANNEL")

function OnEvent()

if (event == "CHAT_MSG_CHANNEL") then

and that's as far as i get. Sorry for being a noob

Last edited by evil_oatmeal : 04-20-06 at 04:14 AM.
  Reply With Quote
04-20-06, 09:56 PM   #5
Maia
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 15
exactly. Now add something like
Code:
local message = arg1
local sender = arg2
local channel = arg9
if channel == whatever and string.gsub(message,...) then
   -- do whatever
end
I just never memorize how string.gsub works, but you can find the info at lua.org.
  Reply With Quote
04-21-06, 01:08 AM   #6
evil_oatmeal
A Murloc Raider
Join Date: Mar 2006
Posts: 7
OH! thank you! that's great I'll try it out when I get home today

Hmm... it just doesn't look right, and I keep thinking string.find would be better somehow. I really apreciate you helping me out though

Code:
RegisterEvent("CHAT_MSG_CHANNEL")

function OnEvent()

if (event == "CHAT_MSG_CHANNEL") then

local message = arg1

local sender = arg2

local channel = arg9

if channel == whatever and string.gsub(message,...) then

   -- do whatever

end

Last edited by evil_oatmeal : 04-21-06 at 01:18 AM.
  Reply With Quote
04-21-06, 01:25 AM   #7
evil_oatmeal
A Murloc Raider
Join Date: Mar 2006
Posts: 7
In my code (for what I'm thinking in my head) local sender/channel is irrelevant, and it might seem that channel would be a problem, but I'm pretty sure it won't. So I was thinking:

Code:
RegisterEvent("CHAT_MSG_CHANNEL")

function OnEvent()

if (event == "CHAT_MSG_CHANNEL") then

local message = arg1

local sender = arg2

local channel = arg9

if string.find(s, whatever) == whatever then

   -- do whatever

end
string.find should return "whatever" if there is "whatever" written in the chat right?
and if this is the case then then the script would do something whenever someone write "whatever" in the chat? (I think I'm starting to get the hang of this, oh, it's so fun.)
  Reply With Quote
04-21-06, 01:56 PM   #8
Maia
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 15
Originally Posted by evil_oatmeal
string.find should return "whatever" if there is "whatever" written in the chat right?
and if this is the case then then the script would do something whenever someone write "whatever" in the chat? (I think I'm starting to get the hang of this, oh, it's so fun.)
of course you don't need sender and channel - I just assumed you might want to parse that info as well. As for string.find, check out the lua manual:
http://www.lua.org/manual/5.1/manual...df-string.find

but basically you need something like
Code:
message = "Hey evil" -- well, in your case it's rather the argument passed by the event
checkFor = "evil" -- the word you want to check
if string.find(message, checkFor) then
  -- do whatever you want to do here 
end
Finally, I'd like to suggest studying some basic macros, and once you know how lua and the wow api works, move on to tiny addons and try to understand what they do by looking at their code.
  Reply With Quote
04-22-06, 11:16 AM   #9
evil_oatmeal
A Murloc Raider
Join Date: Mar 2006
Posts: 7
Well, thanks I'll look around and try to get some more knowledge on how sutff works
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » I need some help with events


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off