I think the createitem plugin has something in there that makes it check the df.global.world.units.active[0] for the player controlled unit doesn't it?
Yep!
df::unit *unit = Gui::getSelectedUnit(out, true);
if (!unit)
{
if (*gametype == game_type::ADVENTURE_ARENA || World::isAdventureMode())
{
// Use the adventurer unit
unit = world->units.active[0];
}
Still getting the hang of the dfhack.createItem though, I was looking at uhh expwnents modtools/create-item.lua trying to figure out a better way to fake up an artifact (which was productive!) and I still feel like it shouldn't work every time I look at the parts I used but I'll be damned if it didn't start spitting out fake-ifacts for me while I was trying to get the right syntax for checking the newly spawned item id/assigning it to the artifact record.
local utils = require 'utils'
validArgs = validArgs or utils.invert({
'help',
'material',
'item',
})
local args = utils.processArgs({...}, validArgs)
if args.help then
print(
[[artifuckery.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 itemstr
specify the itemdef of the item to be created
examples:
WEAPON:ITEM_WEAPON_PICK
]])
return
end
args.creator = df.global.world.units.active[0]
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.mate
rial.index, args.creator)
local base=df.global.world.items.all[2015] --I know there's a way to pick up the item made by the function above
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.id==0 then
local fake=k
fake.id=df.global.artifact_next_id
--fake.name = --I bet I can get these randomly generated huh
--fake.flags = {new=df.bitarray} --still not sure how to get these to populate but they're all false anyways...
fake.item = {new=base}
fake.anon_1 = -1000000
fake.anon_2 = -1000000
fake.anon_3 = -1000000
fake.item.flags.artifact=true
base.flags.artifact=true
if fake.item == 'WEAPON' then item:setSharpness(1,0) end
if base == 'WEAPON' then item:setSharpness(1,0) end
fake.item:setQuality(5)
base:setQuality(5)
--fake.item.itemdecoration or something needs to be added but they randomize on first viewing happily
--base.itemdecoration there's also gotta be a way to have base copy over fully to fake instead of just portions
df.global.artifact_next_id=df.global.artifact_next_id+1
end
end
Pardon the mess, but it struck me to try something like this when I got stumped figuring out why my region7 save file can actually use advfort + these bits to trigger and complete strange moods:
function weapon()
df.global.world.units.active[0].flags1.has_mood=true
df.global.world.units.active[0].mood=0
df.global.world.units.active[0].job.current_job.job_type=57
df.global.world.units.active[0].job.mood_skill=27
df.global.world.units.active[0].job.current_job.job_items[0].mat_type=0 --went with a cheap solution
df.global.world.units.active[0].job.current_job.job_items[0].mat_index=8 --my first success was a coal battle axe >.<
end
-- ---------------------------------------------------------------------------
function armor()
df.global.world.units.active[0].flags1.has_mood=true
df.global.world.units.active[0].mood=0
df.global.world.units.active[0].job.current_job.job_type=57
df.global.world.units.active[0].job.mood_skill=28
df.global.world.units.active[0].job.current_job.job_items[0].mat_type=0
df.global.world.units.active[0].job.current_job.job_items[0].mat_index=8
I've got worlds which are generated with the exact same seeds and such, same raws, all that jazz for region8, 9, etc but none of them get past the screen where the job timer would count down after selecting the materials/using the artifake script. Keep having to devel/pop-screen out of it. Yet I go back to the first folder I tried it on and it just cranks em out all day long.