Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Putnam3145
Putnam3145 / teleport.lua
Created October 31, 2013 02:58
Lets you teleport units; syntax is: number after unit is unit id, number after x,y,z is related position number, showunitid will show unit under cursor's ID, showpos will show position under cursor. Just a unit or just a position can be supplied; if either is the case, the cursor will be used to determine what the remaining variable is.
local function teleport(unit,pos)
local unitoccupancy = dfhack.maps.getTileBlock(unit.pos).occupancy[unit.pos.x%16][unit.pos.y%16]
unit.pos.x = pos.x
unit.pos.y = pos.y
unit.pos.z = pos.z
if not unit.flags1.on_ground then unitoccupancy.unit = false else unitoccupancy.unit_grounded = false end
end
local function getArgsTogether(args)
local settings={
@Putnam3145
Putnam3145 / Spawnunit.lua
Last active December 27, 2015 03:09 — forked from warmist/Spawnunit.lua
forked it so I can make age more proper. Also fixed it for r4's release and moved random numbers to local rng instead of global.
--create unit at pointer or given location. Usage e.g. "spawnunit DWARF 0 Dwarfy"
--Made by warmist, but edited by Putnam for the dragon ball mod to be used in reactions
--note that it's extensible to any autosyndrome reaction to spawn anything due to this; to use in autosyndrome, you want \COMMAND spawnunit CREATURE caste_number name \LOCATION
args={...}
local rando=dfhack.random.new()
@Putnam3145
Putnam3145 / itemsyndromeR3.lua
Last active December 29, 2015 03:39
Itemsyndrome for DFHack-0.34.11-r3.
-- Checks for inventory changes and applies or removes syndromes that items or their materials have. Use "disable" (minus quotes) to disable and "help" to get help.
local args = {...}
local function printItemSyndromeHelp()
print("Arguments:")
print(' "help": displays this dialogue.')
print(" ")
print(' "disable": disables the script.')
print(" ")
@Putnam3145
Putnam3145 / skilroll.lua
Created December 7, 2013 10:16
Allows for skill-based script running. DFHack Lua scripts only, unfortunately; no plugins or ruby scripts.
-- Allows skills to activate lua scripts.
--[[Example usage:
...syndrome stuff...
[SYN_CLASS:\COMMAND][SYN_CLASS:skillroll][SYN_CLASS:\WORKER_ID] For autoSyndrome/syndromeTrigger.
[SYN_CLASS:MELEE_COMBAT] Can use any skill.
[SYN_CLASS:20] Rolls d20. Skill will be weighted to this value.
[SYN_CLASS:DICEROLL_1] If diceroll ends up as one...
[SYN_CLASS:kill][SYN_CLASS:\SKILL_UNIT_ID] Theoretical kill-given-unit-id command; slayrace doesn't do so.
[SYN_CLASS:DICEROLL_10] If diceroll is between 1 and 10 (2-10, inclusive)...
@Putnam3145
Putnam3145 / hackWish.lua
Last active June 17, 2021 11:02
Allows for wishy-type reaction to get any item made of any material. Syntax is "hackWish" followed by x,y,z or a unit. If highlighting a tile, it will place the item there. If highlighting a unit, including with "v", it will put it at the feet of the unit.
-- Allows for script-based wishing.
function getGenderString(gender)
local genderStr
if gender==0 then
genderStr=string.char(12)
elseif gender==1 then
genderStr=string.char(11)
else
return ""
@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