LoTROInterface

LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Lua Programming Help (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=50)
-   -   Reading Chat in LUA (https://www.lotrointerface.com/forums/showthread.php?t=3591)

Garan 11-21-2015 05:15 PM

Quote:

Originally Posted by Elliss11 (Post 11731)
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

This is a tiny bit more complicated - instead of testing the combat state whenever you exit combat, it sounds as though you want to determine when the buff ends. That raises a new question, do you want the status changed whenever the buff ends, or only when it ends out of combat? In either case, you want an event handler that tracks the player EffectList, not the combat state change. Unfortunately, I haven't played with effect lists much and without knowing exactly which effect you are trying to track, I can't provide the exact code, but the basic idea is that you want to handle the EffectRemoved event for the local player EffectList and test for the specific effect you are using as a condition.

The general idea is something like:
Code:

  localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance();
  effectList=localPlayer:GetEffects()
  EffectRemovedHandler=function(sender,args)
    if args.Effect:GetName()=="some effect" then
      killcount=6;
      do_update()
    end
  end
  AddCallback(effectList,"EffectRemoved",EffectRemovedHandler)

where "some effect" is the actual name of the Effect you are looking for.
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)
    for k,v in pairs(args) do
      Turbine.Shell.WriteLine(tostring(k)..":"..tostring(v))
    end
  end

If you only want to set the status when out of combat then just add a test for localPlayer:IsInCombat() to the handler:
Code:

  localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance();
  effectList=localPlayer:GetEffects()
  EffectRemovedHandler=function(sender,args)
    if args.Effect:GetName()=="some effect" and not localPlayer:IsInCopmbat() then
      killcount=6;
      do_update()
    end
  end
  AddCallback(effectList,"EffectRemoved",EffectRemovedHandler)


Elliss11 11-21-2015 07:50 PM

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:

localPlayer=Turbine.Gameplay.LocalPlayer:GetInstan ce();
effectList=localPlayer:GetEffects()
EffectRemovedHandler=function(sender,args)
if args.Effect:GetName()=="Schnelle Erl\195\182sung" then
killcount=6;
do_update()
end
end
AddCallback(effectList,"EffectRemoved",EffectRemov edHandler)

EffectRemoved=function(sender,args)
for k,v in pairs(args) do
Turbine.Shell.WriteLine(tostring(k)..":"..tostring (v))
end
end
... of the Rings Online\Plugins\BodyCount\BodyCount.lua:147: attempt to index field 'Effect' (a nil value)



thanks for your time

Garan 11-21-2015 10:19 PM

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.

Elliss11 11-22-2015 05:23 AM

Thanks

Thurallor 11-22-2015 03:08 PM

Quote:

Originally Posted by Garan (Post 11735)
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.

I played with this a while back. Based on my observations, the EffectRemoved event also supplies an Effect argument, but only if you've previously read the effects list (with a effectsObject:Get() loop). You can use that argument to get the name of the effect, although that is by no means a unique identifier. (Lots of different effects have the same names.) It may be good enough for the OP's purposes, though.

Garan 11-22-2015 06:39 PM

Quote:

Originally Posted by Thurallor (Post 11737)
I played with this a while back. Based on my observations, the EffectRemoved event also supplies an Effect argument, but only if you've previously read the effects list (with a effectsObject:Get() loop). You can use that argument to get the name of the effect, although that is by no means a unique identifier. (Lots of different effects have the same names.) It may be good enough for the OP's purposes, though.

Ah, thanks Thurallor, that explains some of the weirdness I was seeing. It seems if multiple effects are removed simultaneously the second (or subsequent) EffectRemoved contains the args.Effect since the args.Index is no longer valid. That makes the whole thing workable.

The code would then look like:
Code:

localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance();
 effectList=localPlayer:GetEffects()

 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

 EffectRemovedHandler=function(sender,args)

  local effectName=""
  Turbine.Shell.WriteLine("args.Effect:"..tostring(args.Effect))
  if args.Effect==ni then
    effectName=effectList:Get(args.Index):GetName()
  else
    effectName=args.Effect:GetName()
  end
  if effectName=="Schnelle Erl\195\182sung" then
    killcount=6;
    do_update()
  end
-- uncomment the following line to see the name of every effect as it is removed in case the name is not "Schnelle Erl\195\182sung"
--  Turbine.Shell.WriteLine("effect:"..effectName)
 end

 AddCallback(effectList,"EffectRemoved",EffectRemovedHandler)

 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)

Note, the commented line " Turbine.Shell.WriteLine("effect:"..effectName)" can be uncommented to verify what the effect name is in case it is not "Schnelle Erl\195\182sung"

Elliss11 11-23-2015 04:52 PM

thx ... i will test it


All times are GMT -5. The time now is 07:12 AM.

vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI