Bay 12 Games Forum

Dwarf Fortress => DF Modding => Utilities and 3rd Party Applications => Topic started by: Max™ on March 08, 2015, 11:24:45 pm

Title: prefchange--now with artifake working in fortress or adventurer mode!
Post by: Max™ on March 08, 2015, 11:24:45 pm
So I figure this is where to put it, as I said above, I looked around at a couple of scripts to figure out how to turn the all dorfs/all cleared/all same script into this one.

I think I found the "getselectedunit" bit in one from Putnam, and I poked around at a few different things before I got it working in a basic split up form, and then bit by bit was able to assemble it into a single script you can just drop in /hack/scripts:

Code: [Select]
-- Allows setting useful preferences for forcing moods
-- based on pref_adjust by vjek, version 4, 20141016, for DF(hack) 40.08, with the getselectedunit portion from a Putnam script (and the dfhack lua API but he's still a wizard)
-- turned into this hacked together version by some jerk named Max™ on the 8th of March 2015
-- updated with print all and clear all functions on the 11th of April 2015
-- Praise Armok!
-- ---------------------------------------------------------------------------
function axeplate(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- axes and breastplates
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.ARMOR , creature_id = df.item_type.ARMOR , color_id = df.item_type.ARMOR , shape_id = df.item_type.ARMOR , plant_id = df.item_type.ARMOR , item_subtype = 0 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function hammershirt(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- hammers and mail shirts
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 2 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.ARMOR , creature_id = df.item_type.ARMOR , color_id = df.item_type.ARMOR , shape_id = df.item_type.ARMOR , plant_id = df.item_type.ARMOR , item_subtype = 1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function swordboot(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- short swords and high boots
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 3 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.SHOES , creature_id = df.item_type.SHOES , color_id = df.item_type.SHOES , shape_id = df.item_type.SHOES , plant_id = df.item_type.SHOES , item_subtype = 1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function spearboot(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- spears and high boots
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 4 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.SHOES , creature_id = df.item_type.SHOES , color_id = df.item_type.SHOES , shape_id = df.item_type.SHOES , plant_id = df.item_type.SHOES , item_subtype = 1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function maceshield(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- maces and shields
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 5 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.SHIELD , creature_id = df.item_type.SHIELD , color_id = df.item_type.SHIELD , shape_id = df.item_type.SHIELD , plant_id = df.item_type.SHIELD , item_subtype = 0 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function xbowhelm(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- crossbows and helms
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 6 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.HELM , creature_id = df.item_type.HELM , color_id = df.item_type.HELM , shape_id = df.item_type.HELM , plant_id = df.item_type.HELM , item_subtype = 0 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function pickglove(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- picks and gauntlets
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 7 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.GLOVES  , creature_id = df.item_type.GLOVES  , color_id = df.item_type.GLOVES  , shape_id = df.item_type.GLOVES  , plant_id = df.item_type.GLOVES  , item_subtype = 0 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function longglove(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- long swords and gauntlets, skipped bows and whatnot
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 13 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.GLOVES  , creature_id = df.item_type.GLOVES  , color_id = df.item_type.GLOVES  , shape_id = df.item_type.GLOVES  , plant_id = df.item_type.GLOVES  , item_subtype = 0 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function daggerpants(unit)
local unit = dfhack.gui.getSelectedUnit()

if unit==nil then
print ("No unit available!  Aborting with extreme prejudice.")
return
end

local pss_counter=31415926

local prefcount = #(unit.status.current_soul.preferences)
print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

utils = require 'utils'

-- daggers and greaves, skipped the weapons which are too large for most dorfs
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 16 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.PANTS  , creature_id = df.item_type.PANTS  , color_id = df.item_type.PANTS  , shape_id = df.item_type.PANTS  , plant_id = df.item_type.PANTS  , item_subtype = 1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

prefcount = #(unit.status.current_soul.preferences)
print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences")

end
-- ---------------------------------------------------------------------------
function print_all(v)
unit=v

local kk,vv

for kk,vv in ipairs(unit.status.current_soul.preferences) do
printall(vv)
end
end
-- ---------------------------------------------------------------------------
function clear_all(v)
unit=v

local kk,vv,unk_counter
unk_counter=31415926

for kk,vv in ipairs(unit.status.current_soul.preferences) do
vv.type = -1
vv.item_type = -1
vv.creature_id = -1
vv.color_id = -1
vv.shape_id = -1
vv.plant_id = -1
vv.item_subtype = -1
vv.mattype = -1
vv.matindex = -1
vv.active = false
vv.prefstring_seed = unk_counter
unk_counter = unk_counter + 1
end
end
-- ---------------------------------------------------------------------------
function printpref_all_dwarves()
for _,v in ipairs(df.global.world.units.active) do
if v.race == df.global.ui.race_id then
print("Showing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v)))
print_all(v)
end
end
end
-- ---------------------------------------------------------------------------
function clearpref_all_dwarves()
for _,v in ipairs(df.global.world.units.active) do
if v.race == df.global.ui.race_id then
print("Clearing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v)))
clear_all(v)
end
end
end
-- ---------------------------------------------------------------------------
function clear_preferences(v)
local unit = dfhack.gui.getSelectedUnit()
local prefs=unit.status.current_soul.preferences
for index,pref in ipairs(prefs) do
    pref:delete()
end
prefs:resize(0)
end
-- ---------------------------------------------------------------------------
-- main script operation starts here
-- ---------------------------------------------------------------------------
local opt = ...
local profilename

if opt then
if opt=="show" then
printpref_all_dwarves()
return
end
if opt=="c" then
clear_preferences(v)
return
end
if opt=="all" then
clearpref_all_dwarves()
return
end
if opt=="axp" then
axeplate(unit)
return
end
if opt=="has" then
hammershirt(unit)
return
end
if opt=="swb" then
swordboot(unit)
return
end
if opt=="spb" then
spearboot(unit)
return
end
if opt=="mas" then
maceshield(unit)
return
end
if opt=="xbh" then
xbowhelm(unit)
return
end
if opt=="pig" then
pickglove(unit)
return
end
if opt=="log" then
longglove(unit)
return
end
if opt=="dap" then
daggerpants(unit)
return
end
else
print ("Sets preferences for mooding to include a weapon type, equipment type, and material.")
print ("Valid options:")
print ("show -- show preferences of all units")
print ("c -- clear preferences of selected unit")
print ("all -- clear preferences of all units")
print ("axp -- likes axes, breastplates, and steel")
print ("has -- likes hammers, mail shirts, and steel")
print ("swb -- likes short swords, high boots, and steel")
print ("spb -- likes spears, high boots, and steel")
print ("mas -- likes maces, shields, and steel")
print ("xbh -- likes crossbows, helms, and steel")
print ("pig -- likes picks, gauntlets, and steel")
print ("log -- likes long swords, gauntlets, and steel")
print ("dap -- likes daggers, greaves, and steel")
print ("Feel free to adjust the values as you see fit, change the has steel to platinum, change the axp axes to great axes, whatnot.")
end
By itself: prefchange prints the help, and below that is the error message from trying "prefchange daggerpants" in the thoughts screen (though it does work with anything else that targets a unit: adventurer mode z and l, fort mode k, v, and in even the dwarf manipulator interface thanks to the awesome bit I grabbed from Putnam!)
(http://i.imgur.com/R8fZS75.png)
I went with that order for pairings because that's the order they are in the item_*.txt files, though I skipped over stuff like bows and the weapons that are too large for the average dorf. Should be easy enough to alter them though since I put the smaller parts together first and then took all the axeplate.lua hammershirt.lua etc scripts and assembled them into this one, which works!

Result after using this with a unit selected: prefchange c
Spoiler (click to show/hide)

Result after using this with a unit selected: prefchange dap
Spoiler (click to show/hide)

Don't have a screenshot but I did force a mood and get a dorf to make a steel helmet after embarking and using prefchange xbh and strangemood -unit -type fey -skill armorsmith -force on them, so, I'd call it a success!

...I realized it was absurd that I had built enough muscle memory to almost go into a unit preferences and adjust them in gm-editor with my eyes closed, and now I've done gone and made a script type thingamajig!

Good lord, noticed I didn't have a space after the -- in the first comment, been wondering why it wouldn't show up for help or ls...

Added a clear all and print all function after figuring out how to work them back in without breaking everything, shortened the option names to three letter strings to be easier to type and remember.
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: vjek on March 08, 2015, 11:34:19 pm
Very cool, nice adaptation/re-use! :)
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Max™ on March 08, 2015, 11:43:07 pm
Oh good, figured you'd think it was cool, but yanno, didn't wanna step on your toes. Having a broad change for all dorfs is useful with a big fort, but doing a quick reclaim with the right stuff for forcemooding a set of artifact toys to grab on an adventurer it didn't quite work out right.

Not sure how I'd add back in the ability to apply it to all dorfs, I kept getting errors when I tried to just make yours single target until I pulled out just the parts I used for axeplate/hammershirt/etc and figured out how to reassemble them.

Very clever counter method btw, iterating the prefstring seed? I was worried how I'd do it, figured I'd need to target those individually until I really dug around in your old prefstring and new one to see what you had been doing.
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Max™ on March 09, 2015, 06:59:30 pm
Worth noting, it does work fine if you don't clear beforehand, but it replaces the first three preferences with a weapon/armor/material preference, so either clear first or make sure they don't overlap.

Actually used it on a dorf I wanted to force mood a gauntlet with (since they lined up in the new arrivals list conveniently, helm dorf, glove dorf, glove dorf, boot dorf, boot dorf, pants dorf, shirt dorf, plate dorf) and upon checking their preferences I saw they liked picks, gauntlets, steel, something else, steel, something else, gauntlets, and more stuff. Whoops. :D
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Snergler on March 09, 2015, 08:27:00 pm
very cool, I wanted to add a "by unit" option to vjek's pref-adjust script myself, but could not figure it out. I was just thinking about a thread for modding dfhack script. I modded the create-item script, so it has a few more options, I can't find who origanly wrote it, so I did not want to post mine, without giving the creater their credit... but here it is if your interested... it's a ruby script so I called it "make.rb"
Spoiler (click to show/hide)

I find it helpfull for testing new custom reactions quickly in fortress mode 
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Max™ on March 09, 2015, 08:43:46 pm
Ah, cool, like a command line version of hack-wish except you don't need a unit to target? I can see how that could be handy for a lot of stuff.

I was hoping there would be an easier way to add it in to vjeks script but figured I'd post this since I had to take it apart into chunks and then figure out how to get them reassembled without throwing errors at me constantly. Though that is why I made sure to point out that vjek did the actual work, I just cut and pasted until I got the order right. :D
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Snergler on March 09, 2015, 09:09:53 pm
basicaly for items with no quality level, like build materials, although I don't think the format is limited to that, I just can't figure out the syntax for declairing items with subtypes. anvils just come out base quality, i don't know if its possible to declare a quality in that format. I think the creation of the item is to"an unknown artist" , so hack-wish is still more sophisticated, but I don't think you can specify a quantity, and items like armor, gloves, shoes, etc... that i create with hack-wish don't seem to show up in the squad/equip/specific.. menu       
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Max™ on March 09, 2015, 09:25:05 pm
I have not been able to get hack-wish to respond properly regarding the quality of items, and have you tried your script with a unit targeted to see if it assigns them as the maker?

Wait, your stuff becomes available for military assignment without first designating it to be dumped/unforbidding it (the old workaround I used for createitem'D stuff) then having it stockpiled?

Also: I'm gonna kill you for putting that damn song in my head.
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Snergler on March 09, 2015, 09:38:41 pm
the create-items and my modded version won't assign creatorship, even with a unit selected unfortunatly. It's always an unknown artisan,  but the item is considerd native to your fortress (not imported). your right about hack-wish though, the quality level option does not seem to work for me, its always base. I think your right about having to put armor and stuff in stockpiles before it is recognized as available for squad assignment too. I've had that happen with regular "reaction created" armor before also. thanks for the help and the script, I pasted the "get selected unit" lines into my own mode of that script and it works great :)   

I felt the song would build up the anticipation for the next release, but it's probably not quit what Toadyone has in mind for it :P
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Max™ on March 09, 2015, 10:05:49 pm
Well, thank Putnam as I stole it from one of his scripts, remove-stress.lua to be exact, was looking at what I did and that was the one where it jumped out to me that it was exactly what I needed.
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Putnam on March 10, 2015, 01:53:58 am
hack-wish should assign quality properly in the next DFHack release, IIRC. I found the problem there, at least, and fixed at least one problem with hack-wish.

You really shouldn't be crediting me for the getSelectedUnit() thing, since it's part of the API... (https://github.com/DFHack/dfhack/blob/master/Lua%20API.rst)
Title: Re: I made a thing from vjek's pref_adjust script for easier forced mood pref choice
Post by: Max™ on March 10, 2015, 11:37:43 am
Just meant I got the idea to use it from seeing your use of it, so even though it might not be 'your' code it was one of your scripts that had the piece I needed to finally get a working but limited bit of script, which then allowed me to insert the standalone bits back into vjek's opt layout, so I feel a bit obligated to note where I got it from. if anything it seems like it would be more common since it trims a lot of extra code into the one line

Hmmm, didn't even realize I could check the api for that. I've never tried to do anything with modifying scripts or whatnot directly Just struck me that it would hopefully take less time to figure out how to make it work than I spend just doing a couple of tweaked preference sets.

Well I definitely feel more "wizard's apprentice"-y after looking through there, I'll say that much.

Oh yeah, this took the time required to select the units, type the two lines, and wait for them to finish their moods:
(http://i.imgur.com/LNRqgiY.png)
Breastplate, Mail Shirt, Greaves, Left/Right Gauntlets, Helm, High Boots, War Hammer, Battle Axe, Shield. Sooooo much easier than doing it in gm-editor per unit for a set of adventurer toys.
Title: Re: prefchange--set weapon/armor/material prefs per unit--fork of vjek's pref_adjust
Post by: StagnantSoul on March 16, 2015, 12:07:26 pm
How do I put it in there? Just wondering.
Title: Re: prefchange--set weapon/armor/material prefs per unit--fork of vjek's pref_adjust
Post by: Max™ on March 16, 2015, 04:34:00 pm
Oh, I just saved it in the scripts folder as prefchange.lua I would put it on a github page or something but I don't have one

To switch materials, I think you mentioned burning steel, that's probably after adamantine in the inorganic_metals right? So just swap the item_subtype = 8 to 26 or whichever one it is in order and it'll work fine.
Title: Re: prefchange--set weapon/armor/material prefs per unit--fork of vjek's pref_adjust
Post by: StagnantSoul on March 16, 2015, 04:39:17 pm
Thanks!
Title: Re: prefchange--set weapon/armor/material prefs per unit--fork of vjek's pref_adjust
Post by: Max™ on March 16, 2015, 04:56:00 pm
Worth noting if you want to add more preferences in a section then you could take say, the steel part (third part) of axeplate (the first section) and copy/paste it along with the pss_counter = pss_counter + 1 above it, so it would look like this:
Code: [Select]
pss_counter = pss_counter + 1
-- likes steel (8)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')
pss_counter = pss_counter + 1
-- likes burning steel (26)
utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL_BURNING").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed')

With the STEEL_BURNING being the appropriate name, you could probably replace the dfhack.matinfo.find("STEEL").index with just 26 if it is the 26th metal (which it should be if it is right after candy, the 25th metal) and it would add that preference accordingly.

I'm still amazed at how clever using the iterated prefstring_seed as a way to add the entries in order without conflicts turned out to be.
Title: Re: prefchange--set weapon/armor/material prefs per unit--fork of vjek's pref_adjust
Post by: Putnam on March 16, 2015, 05:19:34 pm
Oh, I just saved it in the scripts folder as prefchange.lua I would put it on a github page or something but I don't have one

It's completely free, y'know...
Title: Re: prefchange--set weapon/armor/material prefs per unit--fork of vjek's pref_adjust
Post by: Max™ on March 16, 2015, 05:40:39 pm
Yeah, kinda feels like a waste atm to set up for my massive collection of script, I suppose if I get around to some of the other stuff I was thinking about I'll need to make one.
Title: Re: prefchange--set weapon/armor/material prefs per unit--fork of vjek's pref_adjust
Post by: Max™ on April 11, 2015, 09:53:28 pm
Updated with a show all and clear all option, and shortened the option names.
Title: Re: prefchange--now with artifact faking advfort candy!
Post by: Max™ on May 24, 2015, 09:24:53 pm
So I worked out how to do something after having the idea for a while, it's still kinda cludgey and I intend to see if I can figure out how to have it assign the names and such but the important thing is it works!

(http://i.imgur.com/ORJ8102.png)
Yes, that is an artifact announcement from an advfort prompt!

(http://i.imgur.com/P70y9vO.png)
I am not sure what happens if you do it with no preferences, but when you have a preference it overwrites the queued job product with the preference product, I had to use a magma forge because I wasn't up for figuring out what the best way to grab the steel rather than the coal was, so bleh.

Then I tried to make it do armor and it kersploded at me so I added another option to set it properly:
(http://i.imgur.com/wWA0xl4.png)
(Hauberk is just the flavor name for mail shirts, it's actually [ITEM_ARMOR_MAIL_SHIRT] like normal)

On second thought it is easier to make a second version for adventurer stuff with adventurer relevant addresses.
Code: (artifake.lua) [Select]
local utils = require 'utils'

validArgs = validArgs or utils.invert({
 'help',
 'material',
 'item',
 'name'
})

local args = utils.processArgs({...}, validArgs)

if args.help then
 print(
[[artifake.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
]])
 return
end

args.creator = dfhack.gui.getSelectedUnit()

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.id==0 then
   local fake=k
   fake.id=df.global.artifact_next_id
   fake.item = {new=base}
fake.item.flags.artifact = 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=25,mat_index=474,quality=0,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_spikesst,mat_type=25,mat_index=493,quality=0,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=22,mat_index=474,quality=5,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=42,mat_index=480,quality=5,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=22,mat_index=497,quality=5,skill_rating=15})
   fake.anon_1 = -1000000
   fake.anon_2 = -1000000
   fake.anon_3 = -1000000
     base.flags.artifact = true
     base.general_refs = fake.item.general_refs
     base.improvements = fake.item.improvements
     fake.item:setQuality(5)
     base:setQuality(5)
     if fake.item == 'WEAPON' then item:setSharpness(1,0) end
     if base == 'WEAPON' then item:setSharpness(1,0) end
     df.global.artifact_next_id=df.global.artifact_next_id+1
 if args.name then do
  fake.name.first_name = args.name
  fake.name.language = 0
  fake.name.has_name = true
         end
      end
   end
end
Leaving the name blank just gives you a masterwork decorated item with artifact type decorations and artifact bonuses, and should you choose to name it later on you can go into df.global.world.artifacts and change it by hand.


OMG THIS IS MADDENING, I have one save that it works great on, I've tried repeatedly with other saves and it doesn't work, instead it just freezes up advfort.

https://github.com/maxthyme/dfstuff/blob/master/artifake.lua
Title: Re: prefchange--now with artifact faking advfort candy!
Post by: Snergler on June 01, 2015, 09:01:46 pm
nice work! I am having a hiccup though, creatorship is edit:always assigned to the first dwarf in the unit list random AFIAK, even when I use "v" or "k" to view a specific unit. is there a unit or target argument? or is it supposed to work with a unit selected?
i'm talking about artifake.lua :)
Title: Re: prefchange--now with artifact faking advfort candy!
Post by: Max™ on June 01, 2015, 09:15:56 pm
Sorry, it's not fully in for fort mode, lemme poke at it and I'll put in a change, atm it's grabbing the adventurer unit.

Code: (artifake.lua) [Select]
local utils = require 'utils'

validArgs = validArgs or utils.invert({
 'help',
 'material',
 'item',
 'name'
})

local args = utils.processArgs({...}, validArgs)

if args.help then
 print(
[[artifake.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
]])
 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.id==0 then
   local fake=k
   fake.id=df.global.artifact_next_id
   fake.item = {new=base}
fake.item.flags.artifact = true
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=25,mat_index=474,quality=0,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_spikesst,mat_type=25,mat_index=493,quality=0,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=22,mat_index=474,quality=5,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=42,mat_index=480,quality=5,skill_rating=15})
fake.item.improvements:insert('#',{new = df.itemimprovement_art_imagest,mat_type=22,mat_index=497,quality=5,skill_rating=15})
   fake.anon_1 = -1000000
   fake.anon_2 = -1000000
   fake.anon_3 = -1000000
     base.flags.artifact = true
     base.flags.artifact_mood = true
     base.general_refs = fake.item.general_refs
     base.improvements = fake.item.improvements
     fake.item:setQuality(5)
     base:setQuality(5)
     if fake.item == 'WEAPON' then item:setSharpness(1,0) end
     if base == 'WEAPON' then item:setSharpness(1,0) end
     df.global.artifact_next_id=df.global.artifact_next_id+1
 if args.name then do
  fake.name.first_name = args.name
  fake.name.language = 0
  fake.name.has_name = true
         end
      end
   end
end

There ya go, that will assign the selected unit as the creator.

https://github.com/maxthyme/dfstuff/blob/master/artifake.lua

Note that I'm still trying to figure out exactly how to get classes and stuff working, I think this is close to working but I'm missing something still:
Code: (nametest.lua) [Select]
name_change = defclass(name_change, choices)
choices = df.new(df.viewscreen_setupadventurest) ; choices.subscreen = 3 ; gui = require 'gui' ; gui.simulateInput(choices, 'A_RANDOM_NAME') ; gui.simulateInput(choices, 'A_CUST_NAME')


function name_change:init()
 local n = dfhack.gui.getCurViewscreen()
end

function name_change:postinit()
  if df.viewscreen_layer_choose_language_namest:is_instance(n) then
      local newn = n.name
    end
  return newn
end

if dfhack.gui.getCurViewscreen().parent == df.viewscreen_itemst then
 local trg = dfhack.gui.getCurViewscreen().parent.item.general_refs[0].artifact_id
 local fact = df.artifact_record.find(trg)
 local oldn = fact.name
elseif dfhack.gui.getCurViewscreen().parent == df.viewscreen_dungeon_monsterstatusst then
 local trg = dfhack.gui.getCurViewscreen().parent.unit
 local oldn = trg.name
return oldn
end

function name_change:onInput(keys)
 if keys.SELECT then
  newn = oldn
 elseif keys.LEAVESCREEN then
  if newn ~= oldn then
     newn = oldn
     self:dismiss()
     choices:dismiss()
    end 
  end
end
The end goal is to have it pull up the name choice screen like when you name a fort or adventurer and then rename the selected unit or artifact with the name from that screen.

Also worth noting that launch.lua no longer slams you into the ground thanks to toady pointing out which flag does the "land on your feet" type jumps:
Code: (launch.lua) [Select]
-- Activate with a cursor on screen and you will go there rapidly, attack something first to send them there.
-- Based on propel.lua by Roses, molested by Rumrusher and I until this happened, sorry.
function launch(unitSource,unitTarget)

local curpos
if df.global.ui_advmode.menu==1 then
curpos=df.global.cursor
else
print ("No cursor located!  You would have slammed into the ground and exploded.") --seriously, kasplut!
return
end


 local count=0
 local l = df.global.world.proj_list
 local lastlist=l
 l=l.next
 while l do
  count=count+1
  if l.next==nil then
   lastlist=l
  end
  l = l.next
 end

resultx = curpos.x - unitSource.pos.x
resulty = curpos.y - unitSource.pos.y
resultz = curpos.z - unitSource.pos.z


 newlist = df.proj_list_link:new()
 lastlist.next=newlist
 newlist.prev=lastlist
 proj = df.proj_unitst:new()
 newlist.item=proj
 proj.link=newlist
 proj.id=df.global.proj_next_id
 df.global.proj_next_id=df.global.proj_next_id+1
 proj.unit=unitSource
 proj.origin_pos.x=unitSource.pos.x
 proj.origin_pos.y=unitSource.pos.y
 proj.origin_pos.z=unitSource.pos.z
 proj.target_pos.x=curpos.x
 proj.target_pos.y=curpos.y
 proj.target_pos.z=curpos.z
 proj.prev_pos.x=unitSource.pos.x
 proj.prev_pos.y=unitSource.pos.y
 proj.prev_pos.z=unitSource.pos.z
 proj.cur_pos.x=unitSource.pos.x
 proj.cur_pos.y=unitSource.pos.y
 proj.cur_pos.z=unitSource.pos.z
 proj.flags.no_impact_destroy=true
 proj.flags.piercing=true
 proj.flags.high_flying=true --this probably doesn't do anything, let me know if you figure out what it is
 proj.flags.parabolic=true
 proj.flags.no_collide=true
 proj.flags.unk9=true
 proj.flags[12]=true
 proj.speed_x=resultx*10000
 proj.speed_y=resulty*10000
 proj.speed_z=resultz*12500 --higher z speed makes it easier to reach a target safely
 unitoccupancy = dfhack.maps.ensureTileBlock(unitSource.pos).occupancy[unitSource.pos.x%16][unitSource.pos.y%16]
 if not unitSource.flags1.on_ground then
  unitoccupancy.unit = false
 else
  unitoccupancy.unit_grounded = false
 end
 unitSource.flags1.projectile=true
 unitSource.flags1.on_ground=false
 end

unitTarget = curpos
if df.global.world.units.active[0].job.hunt_target==nil then
unitSource = df.global.world.units.active[0]
else
unitSource = df.global.world.units.active[0].job.hunt_target --kudos Rumrusher for including this, allowing you to fling others around!
end
 
launch(unitSource,unitTarget)
Though unfortunately that means when you fling people they also land on their feet and I haven't yet tried to make it not do that.
Title: Re: prefchange--now with artifake working in fortress or adventurer mode!
Post by: Snergler on June 01, 2015, 09:39:02 pm
thanks, it works like a glove!, you rock :D
as a reward, here is an updated version of make.rb
it makes just about every item type, exept items with subtypes, i don't know how to do that :'(
items that have quality levels are base quality, and imported.
Spoiler (click to show/hide)
great for quick fortress mode "testing" :P 
Title: Re: prefchange--now with artifake working in fortress or adventurer mode!
Post by: Max™ on June 01, 2015, 09:45:05 pm
Nice.

Also figured out how to do the launch stuff properly:
Code: (launch.lua) [Select]
-- Activate with a cursor on screen and you will go there rapidly, attack something first to send them there.
-- Based on propel.lua by Roses, molested by Rumrusher and I until this happened, sorry.
function launch(unitSource,unitTarget)

local curpos
if df.global.ui_advmode.menu==1 then
curpos=df.global.cursor
else
print ("No cursor located!  You would have slammed into the ground and exploded.") --seriously, kasplut!
return
end


 local count=0
 local l = df.global.world.proj_list
 local lastlist=l
 l=l.next
 while l do
  count=count+1
  if l.next==nil then
   lastlist=l
  end
  l = l.next
 end

resultx = curpos.x - unitSource.pos.x
resulty = curpos.y - unitSource.pos.y
resultz = curpos.z - unitSource.pos.z


 newlist = df.proj_list_link:new()
 lastlist.next=newlist
 newlist.prev=lastlist
 proj = df.proj_unitst:new()
 newlist.item=proj
 proj.link=newlist
 proj.id=df.global.proj_next_id
 df.global.proj_next_id=df.global.proj_next_id+1
 proj.unit=unitSource
 proj.origin_pos.x=unitSource.pos.x
 proj.origin_pos.y=unitSource.pos.y
 proj.origin_pos.z=unitSource.pos.z
 proj.target_pos.x=curpos.x
 proj.target_pos.y=curpos.y
 proj.target_pos.z=curpos.z
 proj.prev_pos.x=unitSource.pos.x
 proj.prev_pos.y=unitSource.pos.y
 proj.prev_pos.z=unitSource.pos.z
 proj.cur_pos.x=unitSource.pos.x
 proj.cur_pos.y=unitSource.pos.y
 proj.cur_pos.z=unitSource.pos.z
 proj.flags.no_impact_destroy=true
 proj.flags.piercing=true
 proj.flags.high_flying=true --this probably doesn't do anything, let me know if you figure out what it is
 proj.flags.parabolic=true
 proj.flags.no_collide=true
 proj.flags.unk9=true
 proj.speed_x=resultx*10000
 proj.speed_y=resulty*10000
 proj.speed_z=resultz*12500 --higher z speed makes it easier to reach a target safely
 if df.global.world.units.active[0].job.hunt_target==nil then
  proj.flags[12]=true
 elseif df.global.world.units.active[0].job.hunt_target then
  proj.flags[12]=false
 end
 unitoccupancy = dfhack.maps.ensureTileBlock(unitSource.pos).occupancy[unitSource.pos.x%16][unitSource.pos.y%16]
 if not unitSource.flags1.on_ground then
  unitoccupancy.unit = false
 else
  unitoccupancy.unit_grounded = false
 end
 unitSource.flags1.projectile=true
 unitSource.flags1.on_ground=false
 end

unitTarget = curpos
if df.global.world.units.active[0].job.hunt_target==nil then
unitSource = df.global.world.units.active[0]
else
unitSource = df.global.world.units.active[0].job.hunt_target --kudos Rumrusher for including this, allowing you to fling others around!
end
 
launch(unitSource,unitTarget)

Now it will let YOU land on your feet and THEM slide across the ground.
Title: Re: prefchange--now with artifake working in fortress or adventurer mode!
Post by: Max™ on June 03, 2015, 11:46:03 am
Whoa, fixed artifake because it was crashing if you didn't select a unit, now it defaults to the adventurer unit unless you select someone else.

Ah ha, thought there was something missing, forgot to flip the artifact_mood flag, that's where the all craftsdwarfship is of the highest quality line comes from!
Title: Re: prefchange--now with artifake working in fortress or adventurer mode!
Post by: PeridexisErrant on August 31, 2015, 08:43:44 pm
So I figure this is where to put it, as I said above, I looked around at a couple of scripts to figure out how to turn the all dorfs/all cleared/all same script into this one.  I think I found the "getselectedunit" bit in one from Putnam, and I poked around at a few different things before I got it working in a basic split up form, and then bit by bit was able to assemble it into a single script you can just drop in /hack/scripts:

Code: [Select]
-- Allows setting useful preferences for forcing moods
-- based on pref_adjust by vjek, version 4, 20141016, for DF(hack) 40.08, with the getselectedunit portion from a Putnam script (and the dfhack lua API but he's still a wizard)

By itself: prefchange prints the help, and below that is the error message from trying "prefchange daggerpants" in the thoughts screen (though it does work with anything else that targets a unit: adventurer mode z and l, fort mode k, v, and in even the dwarf manipulator interface thanks to the awesome bit I grabbed from Putnam!)

I went with that order for pairings because that's the order they are in the item_*.txt files, though I skipped over stuff like bows and the weapons that are too large for the average dorf. Should be easy enough to alter them though since I put the smaller parts together first and then took all the axeplate.lua hammershirt.lua etc scripts and assembled them into this one, which works!

Don't have a screenshot but I did force a mood and get a dorf to make a steel helmet after embarking and using prefchange xbh and strangemood -unit -type fey -skill armorsmith -force on them, so, I'd call it a success!

Very cool, nice adaptation/re-use! :)

@vjek, @Max - I've been thinking about getting vjek's scripts into the standard DFHack package for a while now, which would be dead easy with permission and maybe some minor changes.  Are either of you interested in helping, or at least OK with me starting from your work?
Title: Re: prefchange--now with artifake working in fortress or adventurer mode!
Post by: Max™ on August 31, 2015, 09:22:21 pm
I'm cool with whatever's clever if he is.
Title: Re: prefchange--now with artifake working in fortress or adventurer mode!
Post by: lethosor on August 31, 2015, 09:42:48 pm
I did some work here (https://github.com/DFHack/dfhack/pull/667) that makes it fairly easy to pull in scripts from third-party repos (they just have to add a CMakeLists.txt file to specify which scripts should be included). As far as I can tell, your scripts are here (http://github.com/maxthyme/dfstuff), which would be easy to work with, but Vjek's aren't.
Title: Re: prefchange--now with artifake working in fortress or adventurer mode!
Post by: Max™ on September 01, 2015, 04:50:31 am
Yeah I think his are mostly on the wiki as I recall.