Reading Chat in LUA
Hi.. i´m 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 |
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 |
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 |
Quote:
if string.find (args.Message,"test",1,true)~=nil then end so, your code snippet becomes: Code:
count=0; -- initialize variable |
it works .... thank you for your time
|
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 |
The test for combat state is localPlayer:IsInCombat() where localPlayer is an instance of the Turbine.Gameplay.LocalPlayer object.
I'm not sure of your intent, but it looks like you should put the condition you are testing in the chat handler (definitely not outside the function definition). That does leave some situations where you could leave combat without generating any messages in that channel which might not always be the result you are after. I believe you are after something like: Code:
localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance(); Code:
localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance(); |
The second text is working with a small change . but you had me already pointed
THANKS !!!! localPlayer=Turbine.Gameplay.LocalPlayer:GetInstan ce(); 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 CombatChanged = function(sender, args) if not localPlayer:IsInCombat() then --BodyStatus:SetText("6") killcount=6; do_update() end end AddCallback(localPlayer, "InCombatChanged", CombatChanged) 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 killcount=6; do_update() 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) |
CombatChanged = function(sender, args)
if not localPlayer:IsInCombat() then --BodyStatus:SetText("6") <<<<<<< killcount=6; do_update() end end AddCallback(localPlayer, "InCombatChanged", CombatChanged) Is it still possible here with a sleep function to install ?? because the buff after end of the fight still goes 9sec |
#push
|
Quote:
The general idea is something like: Code:
localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance(); Note, I didn't have a chance to test this in game so the args.Effect element may not exist in which case you would have to check what the actual elements in the args table are. To list the elements, use: Code:
EffectRemoved=function(sender,args) Code:
localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance(); |
hi
if i have not the buff then Killcount=6; do_update() the buff calls "Schnelle Erlösung" in german Client "Schnelle Erl\195\182sung" i try something but it doesn´t work. i try it with other buffs too. Quote:
thanks for your time |
Yep, as I noted in my earlier post, I wasn't sure what the args table contained for EffectRemoved. It turns out it contains the index of the effect being removed. Unfortunately, it is also very buggy. Many times when more than one effect are being removed simultaneously the effect has already been removed from the list before the event fires so the index is useless and there is no way to determine the effect that was removed. I will play with it some more when I find time.
|
Thanks
|
Quote:
|
Quote:
The code would then look like: Code:
localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance(); |
thx ... i will test it
|
All times are GMT -5. The time now is 01:57 AM. |
vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI