Quantcast Reading Chat in LUA - LoTROInterface
VGInterface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
 
Thread Tools Display Modes
  #1  
Unread 11-15-2015, 09:38 PM
Elliss11 Elliss11 is offline
The Indomitable
 
Join Date: Nov 2015
Posts: 11
Reading Chat in LUA

Hi.. im not a developer but I want to convert an existing plugin for own use.
can someone tell me how I have to write it that the counter will only count if a certain text found ?

for example :
if "test" match in Chat(PlayerCounter) then Count+1


ChatMonitor = Turbine.Chat;
ChatMonitor.Received = function(f, args)
local msg = args.Message;
if(args.ChatType == Turbine.ChatType.PlayerCombat) then
count=Count+1
do_update()
end
end


thanks for helping
Elliss11
Reply With Quote
  #2  
Unread 11-16-2015, 05:45 AM
Garan's Avatar
Garan Garan is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 243
Before addressing how to match a specific chat message, I would like to point out that there are two errors in the code snippet above. The first is relatively minor but would still cause the code to fail - Lua is case sensitive, the line "count = Count + 1" will not work as intended since the second "Count" starts with a capital letter. I also assume you initialize the value somewhere otherwise you will get an error about adding 1 to nil.

The second error is the more significant error and will not only affect your plugin but any other plugin in the same environment. The line that starts "ChatMonitor.Recieved = " assigns a specific value to a shared object. All Turbine objects are shared and their event handlers should never be assigned a specific function or you will clobber any other already loaded plugin's event handlers. Additionally, the Lua environment does not always exit nicely if event handlers are not removed prior to plugins unloading. To avoid this, we use a pair of functions, "AddCallback" and "RemoveCallback" to allow multiple plugins to share event handlers and to safely clean up prior to unloading. This is all discussed in greater detail in the post:
https://www.lotro.com/forums/showthr...03#post5784203

As to matching a specific message, that is fairly simple. The code snippet you posted already tests for a specific channel. The only thing left to do is add a comparison for the message:
if args.Message=="some message" then
-- do something
end

It is generally more desirable to match a "pattern" or sub string of the message. That gets a tiny bit more complicated as you use the string.match() function and Lua patterns (similar to but not identical to Regular Expressions):
matches={string.match(args.Message,"some pattern")}
Lua patterns are described in greater detail in section 5.4.1 of the online Lua 5.1 manual:
http://www.lua.org/manual/5.1/manual.html#5.4.1
Reply With Quote
  #3  
Unread 11-16-2015, 07:54 AM
Elliss11 Elliss11 is offline
The Indomitable
 
Join Date: Nov 2015
Posts: 11
OK . I must admit that I'm going to get it not alone.
there are other things that I have not observed.
I would like to not have the complete message as a hit ,only a part.


Also
Is in CombatPlayer Channel the word "test" found , then Count+1

Example:
This is a test

count+1

can someone help me there?

thanks
have a nice day
Reply With Quote
  #4  
Unread 11-16-2015, 09:20 AM
Garan's Avatar
Garan Garan is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 243
Quote:
Originally Posted by Elliss11
OK . I must admit that I'm going to get it not alone.
there are other things that I have not observed.
I would like to not have the complete message as a hit ,only a part.


Also
Is in CombatPlayer Channel the word "test" found , then Count+1

Example:
This is a test

count+1

can someone help me there?

thanks
have a nice day
A simplified version of the string.find function will work for this specific case since you are looking for a static substring, in this case the word "test":

if string.find (args.Message,"test",1,true)~=nil then
end

so, your code snippet becomes:
Code:
 count=0; -- initialize variable
 -- define the AddCallback function
 function AddCallback(object, event, callback)
   if (object[event] == nil) then
     object[event] = callback;
   else
     if (type(object[event]) == "table") then
       table.insert(object[event], callback);
     else
       object[event] = {object[event], callback};
     end
   end
   return callback;
 end

 ChatMonitor = Turbine.Chat;
 ChatReceived = function(f, args)
 local msg = args.Message;
 if(args.ChatType == Turbine.ChatType.PlayerCombat) then
   if string.find (args.Message,"test",1,true)~=nil then
     count=count+1
     do_update()
   end
 end
 end
 AddCallback(Turbine.Chat, "Received", ChatReceived)
Note, you should still read about AddCallback and RemoveCallback and use RemoveCallback in your plugin's unload handler to avoid crashing the client (only in very rare circumstances now that Turbine has fixed a number of their bugs) when unloading the plugin.

Last edited by Garan : 11-16-2015 at 09:22 AM.
Reply With Quote
  #5  
Unread 11-16-2015, 10:06 AM
Elliss11 Elliss11 is offline
The Indomitable
 
Join Date: Nov 2015
Posts: 11
it works .... thank you for your time
Reply With Quote
  #6  
Unread 11-16-2015, 11:13 AM
Elliss11 Elliss11 is offline
The Indomitable
 
Join Date: Nov 2015
Posts: 11
it works fantastic...But one thing I'd like to improve it.

<<<<<<<<<<<<if Out of Combat then
BodyStatus:SetText("6")
else



count=0; -- initialize variable
-- define the AddCallback function
function AddCallback(object, event, callback)
if (object[event] == nil) then
object[event] = callback;
else
if (type(object[event]) == "table") then
table.insert(object[event], callback);
else
object[event] = {object[event], callback};
end
end
return callback;
end

ChatMonitor = Turbine.Chat;
ChatReceived = function(f, args)
local msg = args.Message;

<<<<<<<<<<<<
if(args.ChatType == Turbine.ChatType.PlayerCombat) then
if string.find (args.Message,"Verbesserter Gnadenschuss",1,true)~=nil then
BodyStatus:SetText("6")
else
if killcount==0 then
do_update()
else
if string.find (args.Message,"Verbesserter Schneller Bogen",1,true)~=nil then
killcount=killcount-0.333
do_update()

end
end
end
end
end

AddCallback(Turbine.Chat, "Received", ChatReceived)


can you help me there too?

have a nice day
elliss11
Reply With Quote
Reply


Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
16.5, now in beta on Bullroarer, has one Lua fix magill Interface Requests (L) 0 09-26-2015 06:17 AM
Update 15 has Lua Fixes !!!! magill General Authoring Discussion (L) 4 11-05-2014 01:17 PM
Multiply variable reading of io.open Calax Lua Programming Help (L) 1 10-29-2011 03:36 AM
Combat Chat bar londarhawk LotRO Wish List (L) 1 11-26-2010 06:31 PM
Chat Box AUtz Interface Help (D) 1 05-21-2009 10:56 AM


All times are GMT -5. The time now is 06:58 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | VGInterface | LoTROInterface | MMOInterface | Swtorui