### Reset and Assign Attributes Example Source: https://github.com/dfhack/scripts/blob/master/docs/assign-attributes.rst This example demonstrates resetting all attributes to tier 0 and then setting Strength to tier 2, Agility to tier -1, and Spatial Sense to tier -1. The exact numerical ranges for these tiers depend on the unit's race. ```bash assign-attributes --reset --attributes [ STRENGTH 2 AGILITY -1 SPATIAL_SENSE -1 ] ``` -------------------------------- ### Configure Auto-Start Tools Source: https://github.com/dfhack/scripts/blob/master/docs/control-panel.rst Configure tools to automatically start when a new fortress is initialized. This can be for tools that are enabled or commands that run once. ```bash control-panel autostart|noautostart ``` ```bash control-panel autostart autofarm ``` ```bash control-panel autostart fix/blood-del ``` -------------------------------- ### Enable change-build-menu Ticker Source: https://github.com/dfhack/scripts/blob/master/docs/modtools/change-build-menu.rst Start the change-build-menu ticker to enable modifications to the build sidebar. This must be done before any changes take effect. ```bash enable modtools/change-build-menu ``` -------------------------------- ### Start Interactive Lua Interpreter Source: https://github.com/dfhack/scripts/blob/master/docs/lua.rst Launches an interactive Lua interpreter. Type 'quit' to exit. ```bash lua ``` -------------------------------- ### Create a new god with SPEECH, SALT, SACRIFICE spheres (neuter emu) Source: https://github.com/dfhack/scripts/blob/master/docs/modtools/moddable-gods.rst This example demonstrates creating a god with specific spheres, a genderless (neuter) attribute, and a unique depiction as an emu. This allows for highly customized deity creation. ```bash moddable-gods -n Og -s SPEECH,SALT,SACRIFICE -g neuter -d emu ``` -------------------------------- ### Quickfort Transformations Source: https://github.com/dfhack/scripts/blob/master/docs/quickfort.rst Illustrates the available geometric transformations that can be applied to blueprints before they are modified on the game map. These transformations are anchored at the blueprint start cursor position. ```bash quickfort orders -t rotcw ``` ```bash quickfort orders -t rotccw ``` ```bash quickfort orders -t fliph ``` ```bash quickfort orders -t flipv ``` -------------------------------- ### Item Script API: Execute Example Source: https://github.com/dfhack/scripts/blob/master/docs/item.rst Demonstrates how to use the item script API to find and modify items. Use this to reveal or hide items based on conditions. ```lua local itemtools = reqscript('item') local cond = {} itemtools.condition_type(cond, "BOULDER") itemtools.execute('unhide', cond, {}) -- reveal all boulders itemtools.condition_stockpiled(cond, { negate = true }) itemtools.execute('hide', cond, {}) -- hide all boulders not in stockpiles ``` -------------------------------- ### Apply Dig Blueprint with Table Data Source: https://github.com/dfhack/scripts/blob/master/docs/quickfort.rst This example shows how to apply a dig blueprint using a nested table structure for data, specifying an exact starting coordinate (x=30, y=40, z=50). This method is useful for precise placement. ```lua -- dig a 10x10 block starting at coordinate x=30, y=40, z=50 quickfort.apply_blueprint{mode='dig', data={[50]={[40]={[30]='d(10x10)'}}}} ``` -------------------------------- ### Enable Starving Dead with Default Settings Source: https://github.com/dfhack/scripts/blob/master/docs/starvingdead.rst Starts the starving dead process with its default configuration. This is the basic command to activate the undead decay feature. ```bash enable starvingdead ``` -------------------------------- ### Assign Skills Example Source: https://github.com/dfhack/scripts/blob/master/docs/assign-skills.rst Clears all existing skills for a unit and then assigns Woodcutter at competent level and Axeman at adequate level. ```bash assign-skills --reset --skills [ WOODCUTTING 3 AXE 2 ] ``` -------------------------------- ### Enable Deterioration Source: https://github.com/dfhack/scripts/blob/master/docs/deteriorate.rst Start deteriorating items with the current settings. This is the default command to activate the script. ```bash enable deteriorate ``` -------------------------------- ### Reset and Assign a Goal Source: https://github.com/dfhack/scripts/blob/master/docs/assign-goals.rst This example demonstrates clearing all existing goals for a unit and then assigning the 'master a skill' goal. The resulting dream will be 'dreams of mastering a skill'. ```bash assign-goals --reset --goals [ MASTER_A_SKILL false ] ``` -------------------------------- ### Make Walls Unbuildable via Module Source: https://github.com/dfhack/scripts/blob/master/docs/modtools/change-build-menu.rst Example of using the ChangeBuildingAdv function to make walls unbuildable. This is not recommended. ```lua local typ, styp = df.building_type.Construction, df.construction_type.Wall buildmenu.ChangeBuildingAdv(typ, styp, -1, "CONSTRUCTIONS", false) ``` -------------------------------- ### Autoload Savegame on DF Start (Windows) Source: https://github.com/dfhack/scripts/blob/master/docs/load-save.rst Launch Dwarf Fortress with the load-save script to automatically load a specified savegame. Use quotes if the executable path contains spaces. ```bash "Dwarf Fortress.exe" +load-save region1 ``` -------------------------------- ### Get Death Cause Programmatically (Lua) Source: https://github.com/dfhack/scripts/blob/master/docs/deathcause.rst Call the getDeathCause function from the deathcause script API. This example demonstrates retrieving the death reason for a selected unit. ```lua local dc = reqscript('deathcause') -- Note: this is an arguably bad example because this is the same as running deathcause -- from the launcher, but this would theoretically still work. local deathReason = dc.getDeathCauseFromUnit(dfhack.gui.getSelectedUnit()) print(deathReason) ``` -------------------------------- ### Quickfort Configuration Source: https://github.com/dfhack/scripts/blob/master/docs/quickfort.rst Shows how to set global configuration options for the quickfort script using the 'quickfort set' command. Note that these settings are session-specific. ```bash quickfort set blueprints_user_dir dfhack-config/blueprints ``` -------------------------------- ### Autoload Savegame on DF Start (Linux/MacOS) Source: https://github.com/dfhack/scripts/blob/master/docs/load-save.rst Start Dwarf Fortress with the load-save script to automatically load a specific savegame upon game launch. Ensure the path to dfhack is correct. ```bash ./dfhack +load-save region1 ``` -------------------------------- ### Create DFHack GUI Overlay Scripts Source: https://context7.com/dfhack/scripts/llms.txt A skeleton for building DFHack GUI overlay scripts using `gui.widgets`. Demonstrates creating custom windows, labels, and hotkey interactions. ```lua -- Console: open the hello-world GUI window -- devel/hello-world -- Skeleton for a new GUI script (based on devel/hello-world.lua): local gui = require('gui') local widgets = require('gui.widgets') MyWindow = defclass(MyWindow, widgets.Window) MyWindow.ATTRS{ frame = {w=40, h=20}, frame_title = 'My Tool', autoarrange_subviews = true, autoarrange_gap = 1, resizable = true, resize_min = {w=30, h=10}, } function MyWindow:init() self:addviews{ widgets.Label{text='Hello from my script!'}, widgets.HotkeyLabel{ label = 'Do something', key = 'CUSTOM_CTRL_D', on_activate = function() print('Action triggered!') end, }, } end MyScreen = defclass(MyScreen, gui.ZScreen) MyScreen.ATTRS{ focus_path='my-tool' } function MyScreen:init() self:addviews{MyWindow{}} end function MyScreen:onDismiss() view = nil end -- Toggle show/raise pattern (standard idiom): view = view and view:raise() or MyScreen{}:show() ``` -------------------------------- ### Set Up Custom Keybinding for Markdown Tool Source: https://github.com/dfhack/scripts/blob/master/docs/markdown.rst Configure a custom keybinding to quickly execute the 'markdown' command with specific arguments, such as a custom output filename. This can be done temporarily for the current session or permanently by adding it to the dfhack.init file. ```bash keybinding add Ctrl-Shift-S@dwarfmode/ViewSheets/UNIT|dwarfmode/ViewSheets/ITEM "markdown descriptions" ``` -------------------------------- ### Quickfort Command-Line Options Source: https://github.com/dfhack/scripts/blob/master/docs/quickfort.rst Demonstrates various command-line options for the quickfort script, including specifying cursor position, dry runs, applying markers, setting priorities, preserving engravings, quiet/verbose output, repeating blueprints, shifting, and transformations. ```bash quickfort orders -c ,, -d -m -p --preserve-engravings -q -r , -s , -t ``` -------------------------------- ### Equip Unit with Items Source: https://github.com/dfhack/scripts/blob/master/docs/modtools/create-unit.rst Creates and equips items onto the unit. Equipment is sized and placed appropriately. Item quantity defaults to 1. ```bash -equip [ RING:CREATURE:DWARF:BONE:3 ] ``` ```bash -equip [ ITEM_WEAPON_PICK:INORGANIC:IRON ] ``` ```bash -equip [ "ITEM_SHIELD_BUCKLER:PLANT:OAK:WOOD" "AMULET:AMBER" ] ``` -------------------------------- ### Remove Carpenters Workshop via Module Source: https://github.com/dfhack/scripts/blob/master/docs/modtools/change-build-menu.rst Example of using the change-build-menu module to remove the carpenters workshop from the build menu. ```lua buildmenu.ChangeBuilding("CARPENTERS", "WORKSHOPS", false) ``` -------------------------------- ### Display Help for Combine Source: https://github.com/dfhack/scripts/blob/master/docs/combine.rst Run the 'combine' command without arguments to display its help information. ```bash combine ``` -------------------------------- ### Show Unit Cave Adaptation Source: https://github.com/dfhack/scripts/blob/master/docs/adaptation.rst Display the current cave adaptation level for the currently selected unit. No setup is required. ```bash adaptation show ``` -------------------------------- ### Apply Dig Blueprint with String Data Source: https://github.com/dfhack/scripts/blob/master/docs/quickfort.rst Use this to apply a simple dig blueprint defined by a string, like 'd(10x10)', at the current mouse cursor position. Ensure the 'quickfort' script is required. ```lua local quickfort = reqscript('quickfort') -- dig a 10x10 block at the mouse cursor position quickfort.apply_blueprint{mode='dig', data='d(10x10)', pos=dfhack.gui.getMousePos()} ``` -------------------------------- ### Reset Timeskip Duration Source: https://github.com/dfhack/scripts/blob/master/docs/set-timeskip-duration.rst Use the --clear argument to reset the timeskip duration to its default value. This will not affect timeskips that have already started. ```bash set-timeskip-duration --clear ``` -------------------------------- ### List DFHack Tools and Preferences Source: https://github.com/dfhack/scripts/blob/master/docs/control-panel.rst Use `control-panel list` to view current settings and available tools or preferences. You can filter the list by providing a search string. ```bash control-panel list ``` ```bash control-panel list butcher ``` -------------------------------- ### Create Units with `modtools/create-unit` and `spawnunit` Source: https://context7.com/dfhack/scripts/llms.txt Use these commands to create new units of a specified race and caste at map locations. Options include setting nicknames, age, skills, and more. ```lua -- Console (spawnunit): spawn a goblin at cursor position -- spawnunit GOBLIN MALE GoblinRaider -- Console (spawnunit): spawn at explicit coordinates with nickname -- spawnunit DWARF FEMALE Urist 35 40 100 -- Console (modtools/create-unit): full control -- modtools/create-unit -race DWARF -caste FEMALE -location [ 35 40 100 ] -age 25 -domesticate -- Module usage via modtools/create-unit local create_unit = reqscript('modtools/create-unit') local units = create_unit.createUnit( 'DWARF', -- raceStr 'MALE', -- casteStr xyz2pos(35, 40, 100), -- pos nil, -- locationRange (nil = exact tile) 'Walkable', -- locationType 30, -- age in years true, -- domesticate (makes it a pet) df.global.plotinfo.civ_id, -- attach to player civ nil, -- group_id 'MOUNTAIN', -- entityRawName 'Urist McTest', -- nickname nil, -- vanishDelay 1 -- quantity ) print('Created ' .. #units .. ' unit(s).') print('Unit ID: ' .. units[1].id) ``` -------------------------------- ### Get Workshop ID by Numeric Triplet Source: https://github.com/dfhack/scripts/blob/master/docs/modtools/change-build-menu.rst Retrieve the string ID of a workshop or furnace using its numeric ID triplet (type, subtype, custom). ```lua GetWShopID(btype, bsubtype, bcustom) ``` -------------------------------- ### Script API for Autostart Status Source: https://github.com/dfhack/scripts/blob/master/docs/control-panel.rst Other scripts can query whether a command is set for autostart using the control-panel script API. ```APIDOC ## Script API: get_autostart ### Description Allows other DFHack scripts to query the autostart status of a given command. ### Method Signature ```lua control_panel.get_autostart(command) ``` ### Parameters - **command** (string) - The name of the command or tool to check. ### Returns - **enabled** (boolean) - `true` if the command is set for autostart, `false` otherwise. - **default** (boolean) - `true` if the command is set as a default autostart, `false` otherwise. (Note: The source text implies this return value, but its exact meaning or usage is not fully detailed.) ### Request Example ```lua local control_panel = reqscript('control-panel') local enabled, default = control_panel.get_autostart('autofarm') if enabled then print('Autofarm is set to autostart.') else print('Autofarm is not set to autostart.') end ``` ``` -------------------------------- ### Enable Prioritize Tool Source: https://github.com/dfhack/scripts/blob/master/docs/prioritize.rst Enables the prioritize tool to start automatically boosting job priorities. Use this to activate the script's monitoring and prioritization capabilities. ```bash enable prioritize ``` -------------------------------- ### Query Auto-Start Status via Script API Source: https://github.com/dfhack/scripts/blob/master/docs/control-panel.rst Access the DFHack control-panel script API to check if a command is configured for auto-start. ```lua local control_panel = reqscript('control-panel') local enabled, default = control_panel.get_autostart(command) ``` -------------------------------- ### Show all migration wave information Source: https://github.com/dfhack/scripts/blob/master/docs/list-waves.rst Run this command to see the count of dwarves per wave, arrival times, and the names of dwarves in each wave. This provides a comprehensive overview of your fort's population history. ```bash list-waves ``` -------------------------------- ### Set Timeskip Duration by Ticks Source: https://github.com/dfhack/scripts/blob/master/docs/set-timeskip-duration.rst Set the end of the timeskip using a specific number of ticks. The provided example sets the timeskip to approximately 2 years. ```bash set-timeskip-duration --ticks 851249 ``` -------------------------------- ### Set Embark Points with DFHack Source: https://github.com/dfhack/scripts/blob/master/docs/points.rst Use this command at the embark screen to set the total available points. Setting a high number allows for purchasing more items and skills, while setting it to zero provides a challenge. ```bash points 1000000 ``` ```bash points 0 ``` -------------------------------- ### Get All Civilization IDs Source: https://github.com/dfhack/scripts/blob/master/docs/force.rst This Lua script retrieves and prints the IDs for all civilizations currently present in your game. Useful for specifying civ IDs in other 'force' commands. ```lua :lua ids={} for _,en in ipairs(world.entities.all) do ids[en.entity_raw.code] = true end for id in pairs(ids) do print(id) end ``` -------------------------------- ### Enqueue Workorder with JSON Specification Source: https://github.com/dfhack/scripts/blob/master/docs/workorder.rst Create a workorder with properties defined in a JSON string. This example enqueues an 'EncrustWithGems' job for five 'finished_goods' without specifying a material. ```bash workorder "{\"job\":\"EncrustWithGems\",\"item_category\":[\"finished_goods\"],\"amount_total\":5}" ``` -------------------------------- ### Register and Load Default Color Scheme Quietly Source: https://github.com/dfhack/scripts/blob/master/docs/color-schemes.rst Register color schemes and then load the previously set default scheme without any output. This is ideal for inclusion in initialization files like `dfhack.init` to ensure a consistent color scheme on game startup. ```bash color-schemes -q register colorschemes color-schemes default load ``` -------------------------------- ### Add Thought with Specifics Source: https://github.com/dfhack/scripts/blob/master/docs/add-thought.rst Assign a specific emotion, thought, and strength to a given unit ID. This example makes unit 23142 feel gratitude for a good meal. ```bash add-thought --unit 23142 --emotion GRATITUDE --thought GoodMeal --strength 1 ``` -------------------------------- ### Preview Item Combinations Source: https://github.com/dfhack/scripts/blob/master/docs/combine.rst Use the '--dry-run' option with 'combine all' to see which items would be merged across all stockpiles without making any changes. ```bash combine all --dry-run ``` -------------------------------- ### Get Workshop Numeric ID Triplet by String ID Source: https://github.com/dfhack/scripts/blob/master/docs/modtools/change-build-menu.rst Retrieve the numeric ID triplet (type, subtype, custom) for a workshop or furnace using its string identifier. ```lua GetWShopType(id) ``` -------------------------------- ### Compare Tiletype Materials (Shell) Source: https://github.com/dfhack/scripts/blob/master/docs/devel/cmptiles.rst Use the cmptiles script with one or two material group names to compare them. Provide one material group to list its details, or two to compare them. ```shell devel/cmptiles material1 [material2] ``` -------------------------------- ### Get Item ID in DFHack Source: https://github.com/dfhack/scripts/blob/master/docs/remove-wear.rst This command is used within DFHack to retrieve the unique ID of a selected item. This ID can then be used with the 'remove-wear' tool to target specific items. ```lua :lua !item.id ``` -------------------------------- ### Open gm-editor Source: https://github.com/dfhack/scripts/blob/master/docs/gui/gm-editor.rst Launches the game data editor. Without arguments, it opens on the currently selected game element. ```bash gui/gm-editor ``` -------------------------------- ### Integrate Item Combining into Lua Script Source: https://context7.com/dfhack/scripts/llms.txt Integrate the 'combine' script into a periodic maintenance routine using dfhack.run_script. The example shows combining drinks, food, and meat with verbose output. ```lua -- Lua: integrate into a periodic maintenance routine dfhack.run_script('combine', 'all', '--types', 'drink', 'food', 'meat') -- Output (verbose): -- Combined 3 stacks of plump helmet wine into 1 stack of 21. -- Combined 5 stacks of cooked meals into 2 stacks. ``` -------------------------------- ### List Cages and Contents Source: https://github.com/dfhack/scripts/blob/master/docs/stripcaged.rst Use this command to see a list of all cages and the items they contain. This is useful for inventory management before dumping. ```bash stripcaged list ``` -------------------------------- ### Set Timeskip Duration by Years, Months, Days, and Hours Source: https://github.com/dfhack/scripts/blob/master/docs/set-timeskip-duration.rst Set the timeskip duration by specifying years, months, days, and hours. This example achieves the same duration as setting --ticks 851249. ```bash set-timeskip-duration --years 2 --months 1 --days 9 --hours 8 --ticks 49 ``` -------------------------------- ### List Available Confirmations Source: https://github.com/dfhack/scripts/blob/master/docs/confirm.rst Run without parameters to see a list of available confirmation dialogs and their IDs. This helps in managing which actions require confirmation. ```bash confirm list ``` -------------------------------- ### Apply Blueprints Programmatically with Quickfort Source: https://context7.com/dfhack/scripts/llms.txt Reads blueprint files (CSV/XLSX) to apply designations, constructions, stockpiles, zones, etc. Supports multi-z-level blueprints, transformations, and preview mode. Module usage requires `reqscript('quickfort')`. ```lua -- Console: list all blueprints in the default search directories -- quickfort list -- Console: run a blueprint file to apply dig designations -- quickfort run myblueprint.csv -- Console: run only the 'build' section of a multi-section blueprint -- quickfort run myblueprint.csv -s build -- Console: preview what a blueprint would do without applying it -- quickfort run myblueprint.csv --dry-run -- Console: undo a previously applied blueprint -- quickfort undo myblueprint.csv ``` ```lua -- Module usage (apply programmatic blueprint data) local quickfort = reqscript('quickfort') local stats = quickfort.apply_blueprint({ mode = 'dig', pos = xyz2pos(10, 10, 50), -- anchor point for the blueprint data = { -- Each entry: { [z_offset] = { [y_offset] = { [x_offset] = 'command' } } } [0] = { [0] = { [0]='d', [1]='d', [2]='d' }, -- dig three tiles east [1] = { [0]='d', [1]='d', [2]='d' }, } }, verbose = true, }) print(('Designated %d tiles for digging.'):format(stats.designated and stats.designated.value or 0)) ``` -------------------------------- ### Reset and Assign Facets Example Source: https://github.com/dfhack/scripts/blob/master/docs/assign-facets.rst Resets all unit facets to neutral and then sets specific facets to defined levels. Hate propensity is set to a very low level (-2), and cheer propensity to a low level (-1). ```bash assign-facets --reset --facets [ HATE_PROPENSITY -2 CHEER_PROPENSITY -1 ] ``` -------------------------------- ### Combine All Items in All Stockpiles Source: https://github.com/dfhack/scripts/blob/master/docs/combine.rst Execute 'combine all' to merge item stacks in all stockpiles for all item types. ```bash combine all ```