forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartimake.lua
More file actions
144 lines (134 loc) · 4.67 KB
/
artimake.lua
File metadata and controls
144 lines (134 loc) · 4.67 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
--Artimake an item and it will have properly inserted history/creator/properties.
--[====[
artimake
========
Create a new artifact with properly inserted historical links and properties.
Uses the same item and material syntax as createitem does.
]====]
local utils = require 'utils'
validArgs = validArgs or utils.invert({
'help',
'material',
'item',
'name',
'r',
'l'
})
local args = utils.processArgs({...}, validArgs)
if args.help then
print(
[[artimake.lua
arguments:
-help
print this help message
-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 itemstring
specify the itemdef of the item to be created
examples:
WEAPON:ITEM_WEAPON_PICK
-name namestring
specify a first name if desired
-r
for right handed gloves
-l
for left handed gloves
]])
return
end
if dfhack.gui.getSelectedUnit(true) then
args.creator = dfhack.gui.getSelectedUnit()
else args.creator = df.global.world.units.active[0]
end
if not args.item then
error 'Invalid item.'
end
local itemType = dfhack.items.findType(args.item)
if itemType == -1 then
error 'Invalid item.'
end
local itemSubtype = dfhack.items.findSubtype(args.item)
args.material = dfhack.matinfo.find(args.material)
if not args.material then
error 'Invalid material.'
end
local item = dfhack.items.createItem(itemType, itemSubtype, args.material['type'], args.material.index, args.creator)
local base=df.item.find(df.global.item_next_id-1)
df.global.world.artifacts.all:new()
df.global.world.artifacts.all:insert('#',{new=df.artifact_record})
local facts = df.global.world.artifacts.all
for _,k in ipairs(facts) do
if k.item==nil then
local fake=k
fake.id=df.global.artifact_next_id
fake.item = {new=base}
fake.item.flags.artifact = false
fake.item.flags.artifact_mood = true
fake.item.id = base.id
fake.item.general_refs:insert('#',{new =df.general_ref_is_artifactst})
fake.item.general_refs[0].artifact_id = fake.id
fake.item.spec_heat = base.spec_heat
fake.item.ignite_point = base.ignite_point
fake.item.heatdam_point = base.heatdam_point
fake.item.colddam_point = base.colddam_point
fake.item.boiling_point = base.boiling_point
fake.item.fixed_temp = base.fixed_temp
fake.item.weight = base.weight
fake.item.weight_fraction = base.weight_fraction
fake.item.improvements:insert('#',{new = df.itemimprovement_spikesst,mat_type=41,mat_index=3,quality=6,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_spikesst,mat_type=40,mat_index=3,quality=6,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=43,mat_index=3,quality=6,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=420,mat_index=230,quality=6,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=0,mat_index=9,quality=6,skill_rating=15})
fake.flags:new()
for i = 0,7 do
if #fake.flags < 8 then
fake.flags[i] = true
elseif #fake.flags==8 then
fake.flags[0] = false
fake.flags[i] = false
end
end
fake.anon_1 = -1000000
fake.anon_2 = -1000000
fake.anon_3 = -1000000
base.flags.artifact = false
base.flags.artifact_mood = true
base.general_refs = fake.item.general_refs
base.improvements = fake.item.improvements
fake.item:setQuality(6)
base:setQuality(6)
if (df.item_weaponst:is_instance(fake.item) or df.item_toolst:is_instance(fake.item)) then fake.item.sharpness=100000 end
if (df.item_weaponst:is_instance(base) or df.item_toolst:is_instance(base)) then base.sharpness=100000 end
df.global.artifact_next_id=df.global.artifact_next_id+1
df.global.world.history.events:new()
df.global.world.history.events:insert('#',{new=df.history_event_artifact_createdst,
year = df.global.cur_year,
seconds = df.global.cur_year_tick_advmode,
id = df.global.hist_event_next_id,
artifact_id = fake.id,
unit_id = args.creator.id,
hfid = args.creator.hist_figure_id,
}
)
df.global.hist_event_next_id = df.global.hist_event_next_id+1
if args.r then
base.handedness[0] = true
fake.item.handedness[0] = true
end
if args.l then
base.handedness[1] = true
fake.item.handedness[1] = true
end
if args.name then do
fake.name.first_name = args.name
fake.name.language = 0
fake.name.has_name = true
end
end
end
end