Skip to content

Commit

Permalink
clean up remove-wear code
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Oct 6, 2023
1 parent 71cd718 commit b74a293
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions remove-wear.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
-- Reset items in your fort to 0 wear
-- original author: Laggy, edited by expwnent
local help = [====[
remove-wear
===========
Sets the wear on items in your fort to zero. Usage:
:remove-wear all:
Removes wear from all items in your fort.
:remove-wear ID1 ID2 ...:
Removes wear from items with the given ID numbers.
]====]

local args = {...}
local count = 0

if args[1] == 'help' then
print(help)
if not args[1] or args[1] == 'help' or args[1] == '-h' or args[1] == '--help' then
print(dfhack.script_help())
return
elseif args[1] == 'all' or args[1] == '-all' then
for _, item in ipairs(df.global.world.items.all) do
if item.wear > 0 then --hint:df.item_actual
if item:getWear() > 0 then --hint:df.item_actual
item:setWear(0)
count = count + 1
end
end
else
for i, arg in ipairs(args) do
for _, arg in ipairs(args) do
local item_id = tonumber(arg)
if item_id then
local item = df.item.find(item_id)
Expand All @@ -43,4 +31,4 @@ else
end
end

print('remove-wear: removed wear from '..count..' objects')
print('remove-wear: removed wear from '..tostring(count)..' items')

0 comments on commit b74a293

Please sign in to comment.