-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathremove-wear.lua
59 lines (54 loc) · 1.33 KB
/
remove-wear.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- 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 = {...}
if args[1] == 'help' then
print(help)
return
elseif args[1] == 'all' then
local count = 0;
for _,item in ipairs(df.global.world.items.all) do
if (item.wear > 0) then
item:setWear(0)
count = count+1
end
end
print('remove-wear removed wear from '..count..' objects')
else
local argIndex = 1
local isCompleted = {}
for i,x in ipairs(args) do
args[i] = tonumber(x)
end
table.sort(args)
for _,item in ipairs(df.global.world.items.all) do
local function loop()
if argIndex > #args then
return
elseif item.id > args[argIndex] then
argIndex = argIndex+1
loop()
return
elseif item.id == args[argIndex] then
--print('removing wear from item with id ' .. args[argIndex])
item:setWear(0)
isCompleted[args[argIndex]] = true
argIndex = argIndex+1
end
end
loop()
end
for _,arg in ipairs(args) do
if isCompleted[arg] ~= true then
print('failed to remove wear from item ' .. arg .. ': could not find item with that id')
end
end
end