View Single Post
  #7  
Unread 11-16-2015, 11:59 AM
Garan's Avatar
Garan Garan is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 341
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();
 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 localPlayer:IsInCombat() then
     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
   else
     BodyStatus:SetText("6")
   end
 end

 AddCallback(Turbine.Chat, "Received", ChatReceived)
If as I assumed earlier, you are trying to default the text to "6" whenever you exit combat then the correct approach is to use the InCombatChanged handler to set the default text:
Code:
 localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance();
 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")
   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
       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)

Last edited by Garan : 11-16-2015 at 12:06 PM.
Reply With Quote