View Single Post
  #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: 340
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