Jump to content


Photo

Index in the treasure pool question


23 replies to this topic

#1 Kenshi

Kenshi

    Advanced Member

  • Members
  • PipPipPip
  • 334 posts

    Posted 17 February 2015 - 02:42 AM

    I seems to have no problem with bags, but with treasure I can't get the items id in the treasure pool.
    I try to print with eval "//eval print(windower.ffxi.get_items().treasure[1].id)" but I get an error, I'm doing something wrong? If so, could someone explain me how that works?

    Thank you!

    #2 Arcon

    Arcon

      Advanced Member

    • Windower Staff
    • 1189 posts
    • LocationMunich, Germany

    Posted 17 February 2015 - 06:20 AM

    The index goes from 0 to 9. By "error" do you mean it just returns nil or it throws an actual error? Because the code you posted should work fine except that 0 is the first index. This was done intentionally against the Lua norm, because the indices in this are used in various packets and would otherwise require adjusting it by 1 in multiple places.

     

    When items drop into the pool they start using up the slots increasing from 0. When an item drops from the pool, other items will not shift up, they will remain at their index. That means that previous slots open up, and those slots will be filled by new items that drop into the pool.



    #3 Kenshi

    Kenshi

      Advanced Member

    • Members
    • PipPipPip
    • 334 posts

      Posted 17 February 2015 - 11:50 AM

      I was getting an actual error, instead of nil. I'll try again and post with the result.

      #4 Kenshi

      Kenshi

        Advanced Member

      • Members
      • PipPipPip
      • 334 posts

        Posted 17 February 2015 - 12:32 PM

        Ok tested now using "//eval print(windower.ffxi.get_items().treasure[0].id)" if there are no items in the pool I get the error: Eval: Lua runtime error: [string "print(windower.ffxi.get_items().treasure[0]..."]:1: attempt to index field '?' (a nil value) if there is an item in the treasure poool I get nil.

        #5 sdahlka

        sdahlka

          Advanced Member

        • Members
        • PipPipPip
        • 324 posts

          Posted 17 February 2015 - 12:46 PM

          it could be that there is not id in the windower.ffxi.get_items().treasure[0] table

          try this

           

          "//eval for i,v inpairs(windower.ffxi.get_items().treasure[0]) doprint(i," = ",v) end"

           

          it should print the list of every thing in the windower.ffxi.get_items().treasure[0] table

          like this

          id = 123

          name = abc

          etc.



          #6 Kenshi

          Kenshi

            Advanced Member

          • Members
          • PipPipPip
          • 334 posts

            Posted 17 February 2015 - 01:18 PM

            Had to change print(i," = ",v) to print(i,' = ',v) or I'll get a unexpected symbol error. after changing if no items in treasure I get a (table expected, got nil) error, if a item is in the treasure I get 3 values item_id, timestamp and dropper_id.

            #7 sdahlka

            sdahlka

              Advanced Member

            • Members
            • PipPipPip
            • 324 posts

              Posted 17 February 2015 - 01:42 PM

              so

              windower.ffxi.get_items().treasure[0].item_id == the id of the item

              windower.ffxi.get_items().treasure[0].dropper_id == (i guess) the mob that dropped the item

              windower.ffxi.get_items().treasure[0].timestamp == the time of the drop

               

              this should print out whats in your party/allience Drop box

               

              res = require('resources')
              if windower.ffxi.get_items().treasure.count >= 1 then
                  for i,v in ipairs(windower.ffxi.get_items().treasure) do
                      if type(v) == "table" then
                          print(res.items(windower.ffxi.get_items().treasure[i].item_id))
                      end
                  end
              end
               


              #8 Kenshi

              Kenshi

                Advanced Member

              • Members
              • PipPipPip
              • 334 posts

                Posted 17 February 2015 - 02:52 PM

                Using this in a script get the error attemp to compare number with nil, on line 2

                #9 sdahlka

                sdahlka

                  Advanced Member

                • Members
                • PipPipPip
                • 324 posts

                  Posted 17 February 2015 - 03:38 PM

                  Using this in a script get the error attemp to compare number with nil, on line 2

                  i assumed that treasure had a count as well so try this one

                   

                  res = require('resources')
                  if windower.ffxi.get_items().treasure[0] then
                      for i,v in ipairs(windower.ffxi.get_items().treasure) do
                          if type(v) == "table" then
                              print(res.items(windower.ffxi.get_items().treasure[i].item_id))
                          end
                      end
                  end
                   

                  if this does not work im not sure how to tell when there is nothing in treasure



                  #10 Kenshi

                  Kenshi

                    Advanced Member

                  • Members
                  • PipPipPip
                  • 334 posts

                    Posted 17 February 2015 - 03:49 PM

                    I don't get the error but is not printing anything

                    #11 sdahlka

                    sdahlka

                      Advanced Member

                    • Members
                    • PipPipPip
                    • 324 posts

                      Posted 17 February 2015 - 03:55 PM

                      try changing

                      if type(v) == "table" then

                      to

                      if type(windower.ffxi.get_items().treasure[i]) == "table" then

                       

                      also change

                      for i,v in ipairs(windower.ffxi.get_items().treasure)do

                      to

                      for i,v in pairs(windower.ffxi.get_items().treasure)do



                      #12 Kenshi

                      Kenshi

                        Advanced Member

                      • Members
                      • PipPipPip
                      • 334 posts

                        Posted 17 February 2015 - 04:00 PM

                        still not printing

                        #13 sdahlka

                        sdahlka

                          Advanced Member

                        • Members
                        • PipPipPip
                        • 324 posts

                          Posted 17 February 2015 - 04:03 PM

                          im going to have to load ffxi to figure it out give me a few

                           

                          also just so you know you have to reload this ever time you want to print whats in treasure



                          #14 Kenshi

                          Kenshi

                            Advanced Member

                          • Members
                          • PipPipPip
                          • 334 posts

                            Posted 17 February 2015 - 04:04 PM

                            Its weird cause if I change it for inventory it does print the ids in my inv

                            #15 sdahlka

                            sdahlka

                              Advanced Member

                            • Members
                            • PipPipPip
                            • 324 posts

                              Posted 17 February 2015 - 04:26 PM

                              ok here we go

                               

                              res = require('resources')
                              if windower.ffxi.get_items().treasure[0] then
                                  for i,v in pairs(windower.ffxi.get_items().treasure) do
                                      if type(v) == "table" then
                                          print(res.items[windower.ffxi.get_items().treasure[i].item_id].name)
                                      end
                                  end
                              end
                               

                              or if you just want the id

                               

                              res = require('resources')
                              if windower.ffxi.get_items().treasure[0] then
                                  for i,v in pairs(windower.ffxi.get_items().treasure) do
                                      if type(v) == "table" then
                                          print(windower.ffxi.get_items().treasure[i].item_id)
                                      end
                                  end
                              end
                               


                              #16 Kenshi

                              Kenshi

                                Advanced Member

                              • Members
                              • PipPipPip
                              • 334 posts

                                Posted 17 February 2015 - 04:36 PM

                                Yea it does work now, thx so much for the help!. Could I have a little explanation of what pairs do? so I can learn a few

                                #17 sdahlka

                                sdahlka

                                  Advanced Member

                                • Members
                                • PipPipPip
                                • 324 posts

                                  Posted 17 February 2015 - 05:05 PM

                                  Yea it does work now, thx so much for the help!. Could I have a little explanation of what pairs do? so I can learn a few

                                  ipairs - goes through a table to find all the iterators(but only numbers of 1+) and varables

                                  pairs - goes through a table to find all the iterators and varables

                                   

                                  example_table = {[0]="test",[1]="a",[2]="car",[4]="hello", a="yo",b="hi",d="buy"}

                                  ipairs wiil return

                                  1 "a"

                                  2 "car"

                                   

                                  pairs wiil return

                                  0 "test"

                                  1 "a"

                                  2 "car"

                                  4 "hello"

                                  "a" "yo"

                                  "b" "hi"

                                  "d" "buy"

                                   

                                  this is with the below codes

                                  ipairs

                                   

                                  for i,v in ipairs(example_table) do
                                    print(i,v)
                                  end
                                   

                                  for pairs

                                   

                                  for i,v in pairs(example_table) do
                                     print(i,v)
                                  end
                                   


                                  #18 Arcon

                                  Arcon

                                    Advanced Member

                                  • Windower Staff
                                  • 1189 posts
                                  • LocationMunich, Germany

                                  Posted 17 February 2015 - 07:35 PM

                                  While everything sdahlka said was correct, a few additions:

                                   

                                  1. " don't work in the above code because the command handler uses those to group tokens together. It will work when you use it in an addon file, but if you enter it via the chat box or Windower console, you need to resort to using ' or escaping the " with a backslash: //eval print(\"word\")

                                   

                                  2. The outer if in the example code is not required.

                                   

                                  3. You don't need to check if the type of v is a table, only if v exists. If no item is in a certain treasure pool slot, the value will be nil.

                                   

                                  4. Re-using windower.ffxi.get_items() is a bad idea, as it's a very expensive function. In the above code snippet you call it up to 11 times every time the code runs, instead of just one, which is all you need.

                                   

                                  5. pairs, unlike ipairs, also doesn't guarantee the order. ipairs always enumerates elements from 1 to n, where n is the size of the table as defined by the # operator. pairs enumerates the elements in an arbitrary order (although it will often, but not always, coincide with ipairs on numerically indexed tables).

                                   

                                  All said, the code can be prettified a bit more if you're using common libraries. If you want, for example, a set of IDs, you can do this:

                                  S(windower.ffxi.get_items().treasure):map(table.get-{'item_id'})


                                  #19 Kenshi

                                  Kenshi

                                    Advanced Member

                                  • Members
                                  • PipPipPip
                                  • 334 posts

                                    Posted 17 February 2015 - 07:57 PM

                                    It was mainly a question for learn, cause I was able to do it with all the bags except treasure, thx for all the replies. Just one more question is the slot the same than the index?

                                    #20 Arcon

                                    Arcon

                                      Advanced Member

                                    • Windower Staff
                                    • 1189 posts
                                    • LocationMunich, Germany

                                    Posted 17 February 2015 - 08:04 PM

                                    Yes.






                                    1 user(s) are reading this topic

                                    0 members, 1 guests, 0 anonymous users