
Index in the treasure pool question
#1

Posted 17 February 2015 - 02:42 AM
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

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

Posted 17 February 2015 - 11:50 AM
#4

Posted 17 February 2015 - 12:32 PM
#5

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

Posted 17 February 2015 - 01:18 PM
#7

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

Posted 17 February 2015 - 02:52 PM
#9

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

Posted 17 February 2015 - 03:49 PM
#11

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

Posted 17 February 2015 - 04:00 PM
#13

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

Posted 17 February 2015 - 04:04 PM
#15

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

Posted 17 February 2015 - 04:36 PM
#17

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

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

Posted 17 February 2015 - 07:57 PM
#20

Posted 17 February 2015 - 08:04 PM
Yes.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users