Jump to content




[lua] CCsensor - getting informations about items in chest.


  • You cannot reply to this topic
1 reply to this topic

#1 Marval

  • Members
  • 47 posts

Posted 19 September 2012 - 09:36 AM

I use CCsensors addon and I have a question.

How to get amount of items in chest in defined slot? When I type:

targets = sensors.getAvailableTargetsforProbe("left","Chest","InventoryInfo")
data = sensors.getSensorReadingAsDict("left","Chest",targets[1],"InventoryContent")

the data contain something like this: 1xUranium [email protected] in one string.
Is the way to get only amount of item or only the name?
Now when I want amount i use string.sub, but there is no simpler way? Getting name will be difficult. Only way I think right now to do this is to get one character with string sub and doing this after it go to @.

In sensorsAPI is function:
-- returns a dict for each item in the given names table with .dmg and .qty
function getItemsInfo(names,content)
local r={total=0,};
for i,v in pairs(content) do
q,item,dmg= string.match(v,"(%d+)\*(.*)@(%d+)")
itb = string.sub(item,6)
item = itemsDict[itb] or item;
r.total = r.total+1;
for idx,name in ipairs(names) do
if item==name then
local vl=0;
local vq=0;
if r[item] then vl =r[item].dmg end
if r[item] then vq =r[item].qty end
r[item] = {dmg=vl+dmg,qty=q+vq};
end
end

end
for idx,name in ipairs(names) do
if r[name] == nil then
r[name] = {qty=0, dmg=0}
end
end
return r;
end

but I don't know how to use it.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 September 2012 - 02:52 PM

variable = "1xUranium [email protected]"
quantity, name, location = string.match(variable, "(%d+)x([%w%s]+)@(%d+)")

That should work.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users