Jump to content


Photo

I'm new to this and I need help trying to write an addon.


    18 replies to this topic

    #1 Altnob

    Altnob

      Advanced Member

    • Members
    • PipPipPip
    • 37 posts

      Posted 06 April 2015 - 08:23 PM

      So I want to start fiddling around with using packets. I want to start really simple. 

       

      Can someone help me write an addon that simply trades an item to an NPC ? Buys an item from NPC? I don't know how to record incoming packets.



      #2 Iryoku

      Iryoku

        Advanced Member

      • Windower Staff
      • 488 posts

        Posted 06 April 2015 - 08:45 PM

        I strongly recommend against trying to start with buying from or selling to NPCs, screwing it up is a very good way to get yourself banned.



        #3 Altnob

        Altnob

          Advanced Member

        • Members
        • PipPipPip
        • 37 posts

          Posted 06 April 2015 - 08:47 PM

          I strongly recommend against trying to start with buying from or selling to NPCs, screwing it up is a very good way to get yourself banned.

          It's okay I'm practicing on my private server.



          #4 Arcon

          Arcon

            Advanced Member

          • Windower Staff
          • 1189 posts
          • LocationMunich, Germany

          Posted 07 April 2015 - 05:20 AM

          You should hit us up on IRC, people are always happy to help (if you catch them awake). But it's a lot to explain sometimes and requires a bit of dialogue, forums are not a good place to get started with this. Until then you can check out this addon to help you analyze packets. Like Iryoku said, buying/selling is a bit dangerous if you don't do it right, but it's actually rather simple to get right, as long as you know how to do it.



          #5 Altnob

          Altnob

            Advanced Member

          • Members
          • PipPipPip
          • 37 posts

            Posted 08 April 2015 - 04:20 AM

            If this addon does what I think it does that would be perfect. However, I don't know how to work it.

             

            //packetviewer start? record? 



            #6 Arcon

            Arcon

              Advanced Member

            • Windower Staff
            • 1189 posts
            • LocationMunich, Germany

            Posted 08 April 2015 - 07:45 AM

            I've written a tutorial for the addon here:

            https://github.com/z...er/PacketViewer



            #7 Altnob

            Altnob

              Advanced Member

            • Members
            • PipPipPip
            • 37 posts

              Posted 09 April 2015 - 08:23 AM

              How do I format 

              {ctype='unsigned int[9]'

              I understand that 'unsigned int' = I but what do I put for unsigned int[9]



              #8 Arcon

              Arcon

                Advanced Member

              • Windower Staff
              • 1189 posts
              • LocationMunich, Germany

              Posted 09 April 2015 - 11:16 AM

              What do you mean, I? For packing? You shouldn't need to do it manually. You should be able to assign values directly:

              packets = require('packets')
               
              p = packets.new('outgoing', id)
              p['Something 1'] = 300
              p['Something 2'] = 4545
              p['Something 5'] = 12


              #9 Altnob

              Altnob

                Advanced Member

              • Members
              • PipPipPip
              • 37 posts

                Posted 09 April 2015 - 06:13 PM

                require('pack')
                 
                windower.register_event('incoming chunk',function(id, data)
                if id ==0x017then
                local header, mode, gm, zone, sender, message = data:unpack('iCBHS16z')
                if mode ==0then
                local new_mode =1
                local adjusted_data ='iCBHS16z':pack(header, new_mode, gm, zone, sender, message)
                return adjusted_data
                end
                end
                end)

                 I've been fooling around with it that way. How would I write the above using the method you're telling me to use?



                #10 Arcon

                Arcon

                  Advanced Member

                • Windower Staff
                • 1189 posts
                • LocationMunich, Germany

                Posted 09 April 2015 - 10:13 PM

                packets = require('packets')
                 
                windower.register_event('incoming chunk', function(id, data)
                    if id ~= 0x017 then
                        return
                    end
                 
                    packet = packets.parse('incoming', data)
                    packet['Mode'] = 1
                    return packets.build(packet)
                end


                #11 Arcon

                Arcon

                  Advanced Member

                • Windower Staff
                • 1189 posts
                • LocationMunich, Germany

                Posted 09 April 2015 - 10:15 PM

                It even says on the very page you got your example from:

                Note that this is just demonstrative for how string.pack and string.unpack can be used. For general packet reading and manipulation you may want to use the Packets library.



                #12 Altnob

                Altnob

                  Advanced Member

                • Members
                • PipPipPip
                • 37 posts

                  Posted 09 April 2015 - 10:24 PM

                  packets = require('packets')
                   
                  windower.register_event('incoming chunk', function(id, data)
                      if id ~= 0x017 then
                          return
                      end
                   
                      packet = packets.parse('incoming', data)
                      packet['Mode'] = 1
                      return packets.build(packet)
                  end

                  suhweeeeeeeet thanks a ton.

                   

                  edit: just tried to load that addon and it says lua run time error attempt to call string.



                  #13 trv

                  trv

                    Advanced Member

                  • Members
                  • PipPipPip
                  • 34 posts

                    Posted 10 April 2015 - 02:40 AM


                     

                    packets = require('packets')
                     
                    windower.register_event('incoming chunk', function(id, data)
                        if id ~= 0x017 then
                            return
                        end
                     
                        packet = packets.parse('incoming', data)
                        packet['Mode'] = 1
                        return packets.build(packet)
                    end)
                    

                    That one wasn't terrible to spot, but generally speaking it's been my experience that, unless you can easily spot the error that's causing the file to return that error message, you should immediately give up and toss the code into an IDE. That error message means nothing.



                    #14 Altnob

                    Altnob

                      Advanced Member

                    • Members
                    • PipPipPip
                    • 37 posts

                      Posted 10 April 2015 - 02:48 AM

                      packets = require('packets')
                       
                      windower.register_event('incoming chunk', function(id, data)
                          if id ~= 0x017 then
                              return
                          end
                       
                          packet = packets.parse('incoming', data)
                          packet['Mode'] = 1
                          return packets.build(packet)
                      end)
                      

                      That one wasn't terrible to spot, but generally speaking it's been my experience that, unless you can easily spot the error that's causing the file to return that error message, you should immediately give up and toss the code into an IDE. That error message means nothing.

                       

                      what was the error?



                      #15 Altnob

                      Altnob

                        Advanced Member

                      • Members
                      • PipPipPip
                      • 37 posts

                        Posted 10 April 2015 - 05:12 AM

                        nvm see it after staring for like 10minutes lol



                        #16 Altnob

                        Altnob

                          Advanced Member

                        • Members
                        • PipPipPip
                        • 37 posts

                          Posted 14 April 2015 - 05:15 AM

                          If I'm trying to edit a packet that involves an item's name how do I properly do that?

                           

                          packet['Item'] = 'item name here' gives me an error saying it expected a # but got string.



                          #17 Altnob

                          Altnob

                            Advanced Member

                          • Members
                          • PipPipPip
                          • 37 posts

                            Posted 14 April 2015 - 05:59 AM

                            figured it out



                            #18 Arcon

                            Arcon

                              Advanced Member

                            • Windower Staff
                            • 1189 posts
                            • LocationMunich, Germany

                            Posted 14 April 2015 - 06:03 AM

                            I'm not aware of any packet that uses item names. Can you tell me which one it is?



                            #19 Altnob

                            Altnob

                              Advanced Member

                            • Members
                            • PipPipPip
                            • 37 posts

                              Posted 14 April 2015 - 09:25 PM

                              it's item IDs 

                               

                              perhaps you can help me out a bit.

                               

                              I broke my Send delivery box (0x04B) there is an item stuck in delivery slot 0 (first box) that I can't remove and I can't send anything else or do anything anymore. 






                              1 user(s) are reading this topic

                              0 members, 1 guests, 0 anonymous users