Jump to content


Photo

windower.packets.parse_action


    7 replies to this topic

    #1 Iberian

    Iberian

      Member

    • Members
    • PipPip
    • 10 posts

      Posted 22 August 2014 - 02:42 PM

      I'm having some trouble figuring out packets. Could anyone give me some assistance converting this so it can be used with battlemod? Thanks in advance.

       

      windower.register_event('action message',function (actor_id, target_id, actor_index, target_index, message_id, param_1, param_2, param_3)
          if (message_id == 6) then
              for k, v in ipairs(t) do
                  if v == target_id then
                      table.remove(t, k)
                  end
              end
          end
      end)
      

       



      #2 Arcon

      Arcon

        Advanced Member

      • Windower Staff
      • 1189 posts
      • LocationMunich, Germany

      Posted 22 August 2014 - 05:12 PM

      What are you trying to do here? That code sample is incomplete. What is t?

      I'd also recommend against using the action event and instead use the packets library to parse it.



      #3 Iberian

      Iberian

        Member

      • Members
      • PipPip
      • 10 posts

        Posted 23 August 2014 - 12:52 AM

        I just want to parse killshot messages and remove the mob id from my table, if it is found. This function works exactly how i want it, do you require the rest of my code? t is my table to track staggered mobs. Sorry I could have defined the table for you at the very least. Yes I wish to take your advice and convert this to parse packets, as this requires me to unload our beloved battlemod (feels kinda slow too). I'm a little lost with packets, unable to find an example I can easily convert to my needs. I'm looking at libs\packets\fields.lua, I have some uncertainty, if provided a simple example or pointed to one this may hopefully help me understand.



        #4 Iberian

        Iberian

          Member

        • Members
        • PipPip
        • 10 posts

          Posted 23 August 2014 - 04:47 AM

          Base for what i am working on, Simply tracks mobs staggered between characters with this loaded, and displays it when switching target (intended for use while engaged with many mobs, early stages). Need help converting action message for kill shot to parse packets. I need to check for the equivalent of message_id 6 (killshot) then compare target_id from this message to table Staggered for removal from table Staggered. I'm rather lost or may just be doing something silly, spent a little too much time on this and have trashed my tests, in any case, help would be appreciative! Thanks!

          require('tables')
          require('luau')
          ---------------------------------------------------------------------------------------------------------
          --- "Staggered table defined when addon is loaded, Changing zones clears stagger tracker."
          ---------------------------------------------------------------------------------------------------------
          windower.register_event('load',function ()
          Staggered = {}
          end)
          ---------------------------------------------------------------------------------------------------------
          --- "Display message if current sub target is staggered, if sub target not active display for main target."
          --- "Known issue with this and <stnpc> macro, I am awaiting possible adjustments before I consider a re-write as <st> does function."
          ---------------------------------------------------------------------------------------------------------
          function target_change(new)
          	local player = windower.ffxi.get_player()
          	local mob = windower.ffxi.get_mob_by_target('t')
          	local smob = windower.ffxi.get_mob_by_target('st')
          	if (smob ~= nil) then
          		starget = smob.id
          	elseif (mob ~= nil) and (smob == nil) then
          		starget = mob.id
          	end
          	if starget ~= nil then
          		for t, u in ipairs(Staggered) do
          			if u == starget then
          				log('Mob Staggered')
          				starget = nil
          			end
          		end
          	end
          end
          windower.register_event('target change', target_change)
          ---------------------------------------------------------------------------------------------------------
          --- "Remove dead mob id from staggered table. Convert to parse packets."
          ---------------------------------------------------------------------------------------------------------
          windower.register_event('action message',function (actor_id, target_id, actor_index, target_index, message_id, param_1, param_2, param_3)
          	if (message_id == 6) then
          		for k, v in ipairs(Staggered) do
          			if v == target_id then
          				table.remove(Staggered, k)
          			end
          		end
          	end
          end)
          ---------------------------------------------------------------------------------------------------------
          --- "Track staggers between instances."
          ---------------------------------------------------------------------------------------------------------
          windower.register_event('ipc message',function (msg)
          	if msg then
          	msg = tonumber(msg)
          		table.insert(Staggered, msg)
          		target_change()
          	end
          end)
          ---------------------------------------------------------------------------------------------------------
          --- "Track your stagger messages and add current target id to staggered table,"
          --- "if current target is staggered or nil add lastst to staggered table."
          ---------------------------------------------------------------------------------------------------------
          windower.register_event('incoming text', function(old,new,color,newcolor)   
              local player = windower.ffxi.get_player()
              name = player.name
              if string.find(old,(player.name).. '\'s attack staggers the fiend%p') then
              	local mob = windower.ffxi.get_mob_by_target()
              	local lmob = windower.ffxi.get_mob_by_target('lastst')
              	if mob.id ~= nil then
              	Stagger = mob.id
              	end
          		for k, v in ipairs(Staggered) do
          			if v == Stagger and lmob ~= nil then
              		Stagger = lmob.id
          			end
          		end
          		table.insert(Staggered, Stagger)
          		windower.send_ipc_message('' ..(Stagger).. '')
              return
          	end
          end)
          


          #5 Arcon

          Arcon

            Advanced Member

          • Windower Staff
          • 1189 posts
          • LocationMunich, Germany

          Posted 23 August 2014 - 05:33 AM

          Ah, so your question is just how to make that function work without the action message event itself?

          If so, the answer is here:

          require('packets')
           
          windower.register_event('incoming chunk', function(id, data)
              if id == 0x029 then
                  local action_message = packets.parse('incoming', data)
                  print(action_message['Actor'])
                  print(action_message['Message'])
                  print(action_message['Target'])
                  print(action_message['Param 1'])
                  print(action_message['Param 2'])
                  print(action_message['Actor Index'])
                  print(action_message['Target Index'])
              end
          end)

           

          So basically just call packets.parse(direction, data) and it will return a table with all the fields as defined in Windower/addons/libs/packets/fields.lua.



          #6 Iberian

          Iberian

            Member

          • Members
          • PipPip
          • 10 posts

            Posted 23 August 2014 - 07:44 AM

            Thanks, I understand that now, silly mistakes. Much easier than I anticipated. Here's the code in case anyone cared.

            windower.register_event('incoming chunk', function(id, data)
                if id == 0x029 then
                    action_message = packets.parse('incoming', data)
                    if (action_message['Message'] == 6) then
                        for k, v in ipairs(Staggered) do
                            if v == action_message['Target'] then
                                table.remove(Staggered, k)
                            end
                        end
                    end   
                end
            end)
            


            #7 amadeus1171

            amadeus1171

              Newbie

            • Members
            • Pip
            • 4 posts

              Posted 16 September 2014 - 08:59 AM

              Is it me, or are some of the action messages not received, even parsing packets from incoming chunks.  For example, I'm trying to write a program to say who's inflicted with what when PC's in the party/alliance gains or looses a debuff.  I look for the appropriate action_message.Message, but it never comes up.  Arcon, using a modified version of your code I'll show an example below.

              For:

              64 <target> is no longer <status>. 203 <target> is <status>.

               

              require('packets')
               
              windower
              .register_event('incoming chunk',function(id, data)
                  if id ==0x029 then
                      local action_message = packets.parse('incoming', data)

                       if T{64,203}:contains(action_message.Message) then
                          print(action_message['Actor'])
                          print(action_message['Message'])
                          print(action_message['Target'])
                          print(action_message['Param 1'])
                          print(action_message['Param 2'])
                          print(action_message['Actor Index'])
                          print(action_message['Target Index'])

                     end
                  end
              end)

               

               

              Message_id's 64 and 203 will never be printed because it never shows up.



              #8 Arcon

              Arcon

                Advanced Member

              • Windower Staff
              • 1189 posts
              • LocationMunich, Germany

              Posted 16 September 2014 - 09:37 AM

              Three options, it's either in 0x028 as a byproduct of a proper action, or it's in 0x02A, which is also used for some messages, or it's in a new packet altogether, although that's the least likely event. Honestly, I'm not sure, but you may wanna turn on a packet logger and see which packets come in when that happens, just to get an idea.






              1 user(s) are reading this topic

              0 members, 1 guests, 0 anonymous users