forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-item.lua
More file actions
147 lines (126 loc) · 3.31 KB
/
Copy pathcreate-item.lua
File metadata and controls
147 lines (126 loc) · 3.31 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
--scripts/modtools/create-item.lua
--author expwnent
--creates an item of a given type and material
--[[
BEGIN_DOCS
.. _scripts/modtools/create-item:
modtools/create-item
====================
This is mostly the same as the other create item tools, but it uses standard
arguments. The other versions will be phased out in a later version.
END_DOCS
]]
local utils = require 'utils'
validArgs = --[[validArgs or--]] utils.invert({
'help',
'creator',
'material',
'item',
-- 'creature',
-- 'caste',
'leftHand',
'rightHand',
'quality'
})
organicTypes = organicTypes or utils.invert({
df.item_type.REMAINS,
df.item_type.FISH,
df.item_type.FISH_RAW,
df.item_type.VERMIN,
df.item_type.PET,
df.item_type.EGG,
})
badTypes = badTypes or utils.invert({
df.item_type.CORPSE,
df.item_type.CORPSEPIECE,
df.item_type.FOOD,
})
function createItem(creatorID, item, material, leftHand, rightHand, quality)
local itemQuality = quality and df.item_quality[quality]
print(itemQuality)
local creator = df.unit.find(creatorID)
if not creator then
error 'Invalid creator.'
end
if not item then
error 'Invalid item.'
end
local itemType = dfhack.items.findType(item)
if itemType == -1 then
error 'Invalid item.'
end
local itemSubtype = dfhack.items.findSubtype(item)
if organicTypes[itemType] then
--TODO: look up creature and caste
error 'Not yet supported.'
end
if badTypes[itemType] then
error 'Not supported.'
end
if not material then
error 'Invalid material.'
end
local materialInfo = dfhack.matinfo.find(material)
if not materialInfo then
error 'Invalid material.'
end
local item1 = dfhack.items.createItem(itemType, itemSubtype, materialInfo['type'], materialInfo.index, creator)
local item = df.item.find(item1)
if leftHand then
item:setGloveHandedness(2)
elseif rightHand then
item:setGloveHandedness(1)
end
if itemQuality then
item:setQuality(itemQuality)
end
--[[if matchingGloves or matchingShoes then
if matchingGloves then
item1 = df.item.find(item1)
item1:setGloveHandedness(1);
end
local item2 = dfhack.items.createItem(itemType, itemSubtype, materialInfo['type'], materialInfo.index, creator)
if matchingGloves then
item2 = df.item.find(item2)
item2:setGloveHandedness(2);
end
end --]]
return item1
end
if moduleMode then
return
end
local args = utils.processArgs({...}, validArgs)
if args.help then
print(
[[scripts/modtools/create-item.lua
arguments:
-help
print this help message
-creator id
specify the id of the unit who will create the item, or \\LAST to indicate the unit with id df.global.unit_next_id-1
examples:
0
2
\\LAST
-material matstring
specify the material of the item to be created
examples:
INORGANIC:IRON
CREATURE_MAT:DWARF:BRAIN
PLANT_MAT:MUSHROOM_HELMET_PLUMP:DRINK
-item itemstr
specify the itemdef of the item to be created
examples:
WEAPON:ITEM_WEAPON_PICK
-matchingShoes
create two of this item
-matchingGloves
create two of this item, and set handedness appropriately
]])
return
end
if args.creator == '\\LAST' then
args.creator = tostring(df.global.unit_next_id-1)
end
createItem(tonumber(args.creator), args.item, args.material, args.leftHand, args.rightHand, args.quality)