Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: nuke-items global all items not returning accurate counts  (Read 780 times)

bananafishbones

  • Escaped Lunatic
    • View Profile
nuke-items global all items not returning accurate counts
« on: July 19, 2020, 05:19:24 pm »

I hope someone can point me in the right direction.

I'm using the nuke-items script within DFHack to simply grab all stock items and display them but for some reason I'm getting duplicate items (pairs of items with the same memory address) nor do the totals match.

--what I've done--
So I started a new game within DF, created a room for my bookkeeper and set the accuracy to the best settings. When I execute the script I'm getting the paired duplicates and even when I take this into account, the numbers are off from what DF is reporting within the Stock items screen. the nuke-items script removes in-building, under construction, in-job and held-by-unit.

Code: [Select]
local count = 0

for _,v in ipairs(df.global.world.items.all) do
    if not (v.flags.in_building or v.flags.construction or v.flags.in_job
            or dfhack.items.getGeneralRef(v,df.general_ref_type.UNIT_HOLDER))  then
        count = count + 1
        print(v)
        --v.flags.forbid = true
        --v.flags.garbage_collect = true
    end
end

Before I continue on with the script and try and attain my end-goal, I need to figure out why my numbers are off.

Any ideas?

NOTE: I'm no programmer but this is something I've wanted within DF and I've searched the DFHack and other online resources to the best of my ability to no avail.

My end-goal is to write to a file, each item and the amount of each item so I can display them with a small icon/graphic on a separate screen.

Below is another, more advanced version of my script which counts some items (hardcoded at the moment) but again, even in the advanced stock item screen, they don't match.

Code: [Select]
local count = 0
local thread = 0
local corpsepiece = 0
local corpse = 0
local remains = 0
local ammo = 0
local wood = 0
local stone = 0
local barrel = 0
local box = 0
local legwear = 0
local drinks = 0
local meat = 0
local itemname = "a"
local filename = "inventory.txt"

local file = io.open(filename, 'w')
if not file then error("could not open file: " .. filename) end

for _,v in ipairs(df.global.world.items.all) do
  if not (v.flags.in_building or v.flags.construction or v.flags.in_job
        or dfhack.items.getGeneralRef(v,df.general_ref_type.UNIT_HOLDER))  then
      count = count + 1
       --print(v)
       itemname = tostring(v)

        if string.match(itemname, "thread") then
           thread = thread + 1
        elseif string.match(itemname, "corpsepiece") then
           corpsepiece = corpsepiece + 1
           elseif string.match(itemname, "ammo") then
              ammo = ammo + 1
              elseif string.match(itemname, "corpse") then
                 corpse = corpse + 1
                 elseif string.match(itemname, "remains") then
                    remains = remains + 1
                    elseif string.match(itemname, "wood") then
                       wood = wood + 1
                       elseif string.match(itemname, "stone") then
                          stone = stone + 1
                          elseif string.match(itemname, "barrel") then
                             barrel = barrel + 1
                             elseif string.match(itemname, "box") then
                                box = box + 1
                                elseif string.match(itemname, "legwear") then
                                   legwear = legwear + 1
                                   elseif string.match(itemname, "drinks") then
                                      drinks = drinks + 1
                                      elseif string.match(itemname, "meat") then
                                         meat = meat + 1
       end

      --file:write(itemname, "\n")

  end
end

print('Total Stock Items: '..count)
print('Total Meat: '..meat)
print('Total Corpse Pieces: ' ..corpsepiece)
print('Total Drinks: ' ..drinks)
print('Total Thread: ' ..thread)
print('Total Legwear: ' ..legwear)
print('Total Ammo: '..ammo)
print('Total Corpses: '..corpse)
print('Total Wood: '..wood)
print('Total Remains: '..remains)
print('Total Stone: '..stone)
print('Total Barrels: '..barrel)
print('Total Boxes: '..box)

--END of Program

Any and all suggestions are welcomed.

Thanks!
Logged