Skip to content

Instantly share code, notes, and snippets.

@Putnam3145
Putnam3145 / skillChange.lua
Created March 8, 2014 23:18
Allows skills to be changed with DFHack.
-- Allows skills to be changed with DFHack.
--[[
Args are arranged like this:
unitID SKILL level ADD/SUBTRACT/SET
SKILL being anything such as DETAILSTONE, level being a number that it will be set to (15 is legendary, 0 is dabbling).
Add will add skill levels, subtract will subtract, set will place it at exactly the level you put in.
]]
@Putnam3145
Putnam3145 / badThoughtCheck.lua
Created April 10, 2014 01:22
Looks through all negative thoughts, gives you the most common one.
do
local function thoughtIsNegative(thought)
return df.unit_thought_type.attrs[thought.type].value:sub(1,1)=='-' and df.unit_thought_type[thought.type]~='LackChairs'
end
local function write_gamelog_and_announce(msg,color)
dfhack.gui.showAnnouncement(msg,color)
local log = io.open('gamelog.txt', 'a')
log:write(msg.."\n")
log:close()
end
@Putnam3145
Putnam3145 / gaydar.lua
Last active August 29, 2015 14:04
Determines the orientation of a citizen, your citizens, everyone on the map or all named units.
local utils = require('utils')
validArgs = utils.invert({
'all',
'citizens',
'named',
'notStraight',
'gayOnly',
'biOnly',
'straightOnly',
@Putnam3145
Putnam3145 / add-thought.lua
Last active August 29, 2015 14:08
Allows the user to add emotions to a unit. Use the -gui argument to open a GUI for your editing needs.
-- Adds emotions to creatures.
local utils=require('utils')
local function addEmotionToUnit(emotions,thought,emotion,subthought,severity)
if not (type(emotion)=='number') then emotion=df.emotion_type[emotion] end
if not (type(thought)=='number') then thought=df.unit_thought_type[thought] end
emotions:insert('#',{new=df.unit_personality.T_emotions,
type=emotion,
unk2=1,
@Putnam3145
Putnam3145 / adoption.lua
Created December 8, 2014 20:37
Adoption!
-- lets babies be adopted by couples with no infants.
local function getSpouseOrLover(unit)
local lover_unit=df.unit.find(unit.relations.lover_id) or df.unit.find(unit.relations.spouse_id)
if lover_unit then
return lover_unit.hist_figure_id
else
local hist_fig=df.historical_figure.find(unit.hist_figure_id)
for k,v in ipairs(hist_fig.histfig_links) do
if df.histfig_hf_link_spousest:is_instance(v) or df.histfig_hf_link_loverst:is_instance(v) then
@Putnam3145
Putnam3145 / burial.lua
Created December 14, 2014 08:37
Automatically assigns all unowned coffins for burial. Use argument "-pets" to allow pets as well as citizens.
local utils=require('utils')
validArgs = validArgs or utils.invert({
'pets'
})
local args = utils.processArgs({...}, validArgs)
for k,v in ipairs(df.global.world.buildings.other.COFFIN) do
if v.owner_id==-1 then
@Putnam3145
Putnam3145 / badThoughtNotifier.lua
Created May 15, 2015 07:47
A script that notifies the user of the most common bad thoughts in the fort.
local function getRaceName()
return df.creature_raw.find(df.global.ui.race_id).name[1]
end
local function emotionIsNegative(thought)
return thought.type~=-1 and df.emotion_type.attrs[thought.type].divider>0
end
local function write_gamelog_and_announce(msg,color)
dfhack.gui.showAnnouncement(msg,color)
dfhack.gui.writeToGamelog(msg)
end
@Putnam3145
Putnam3145 / get_generated_raws.lua
Last active September 24, 2015 15:36
Outputs a few files containing generated raws.
local creatures = assert(io.open(dfhack.getDFPath()..'/generated_creatures.txt', 'w'))
local items = assert(io.open(dfhack.getDFPath()..'/generated_items.txt', 'w'))
local materials = assert(io.open(dfhack.getDFPath()..'/generated_materials.txt', 'w'))
local entities = assert(io.open(dfhack.getDFPath()..'/generated_entities.txt', 'w'))
local interactions = assert(io.open(dfhack.getDFPath()..'/generated_interactions.txt', 'w'))
@Putnam3145
Putnam3145 / unMount.lua
Last active December 25, 2015 16:19
Unmount for Rumrusher's mount here: https://gist.github.com/Rumrusher/6903877 Very, very adventurer-specific
function unMount (rider,horse)
--for k,horse in pairs(unit_list) do
--if unit_rider.pos.x==horse.pos.x and unit_rider.pos.y==horse.pos.y
--and unit_rider.pos.z==horse.pos.z then --check if they are on the same tile
for i=#horse.general_refs-1,0,-1 do
if df.general_ref_unit_riderst:is_instance(horse.general_refs[i]) then horse.general_refs:erase(i) end
end
rider.relations.rider_mount_id=-1
rider.flags1.rider=false
horse.flags1.ridden=false
@Putnam3145
Putnam3145 / projectileExpansion.lua
Last active December 25, 2015 16:29
projectileExpansion. It's all about the raws here. It only runs when projectiles hit and there shouldn't be *too* much of a performance hit.
-- Adds extra functionality to projectiles. Use the argument "disable" (minus quotes) to disable.
flowtypes = {
miasma = 0,
mist = 1,
mist2 = 2,
dust = 3,
lavaMist = 4,
smoke = 5,
dragonFire = 6,