Skip to content

Instantly share code, notes, and snippets.

View warmist's full-sized avatar
๐Ÿ•น๏ธ

Warmist warmist

๐Ÿ•น๏ธ
View GitHub Profile
@warmist
warmist / jobs.lua
Created February 25, 2014 20:35
a jobs module for creating/assigning jobs
--a library for creation and modification of jobs
--TODO: workshop jobs/reactions and building specific jobs in general
local _ENV = mkmodule('hack.scripts.jobs')
local buildings = require('dfhack.buildings')
local tile_attrs = df.tiletype.attrs
--[=[ helper functions ]=]
local function findRef(vector,ref_type)
for k,v in ipairs(vector) do
@warmist
warmist / healunit.lua
Created January 24, 2014 09:42
heals unit from damage
--heal unit from all wounds and damage
function healunit(unit)
if unit==nil then
unit=dfhack.gui.getSelectedUnit()
end
if unit==nil then
error("Failed to Heal unit. Unit not selected/valid")
end
for i=#unit.body.wounds-1,0,-1 do
@warmist
warmist / spawn-unit.lua
Last active January 4, 2016 03:39
Spawn unit at location or pointer
--create unit at pointer or given location and with given civ (usefull to pass -1 for enemy). Usage e.g. "spawnunit DWARF 0 Dwarfy"
--[=[
Creature (ID), caste (number), name, x,y,z , civ_id(-1 for enemy, optional) for spawn.
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
TODO:
birth time
death time
real body size
blood max
@warmist
warmist / rip-heart.lua
Last active November 30, 2020 07:26
Rip out the heart...
--removes heart
function findBodyPart(caste_raw,token)
for id,bp in ipairs(caste_raw.body_info.body_parts) do
if bp.token==token then
return id,bp
end
end
end
local trg=dfhack.gui.getSelectedUnit()
local heart_id=findBodyPart(df.creature_raw.find(trg.race).caste[trg.caste],"HEART")
@warmist
warmist / printEnum.lua
Created January 9, 2014 21:01
Print all enum values
--prints enum values
local args={...}
function isEnum(t)
return t._kind=='enum-type'
end
function printEnum(t)
if not isEnum(t) then
qerror("type is not an enum")
end
@warmist
warmist / init.lua
Created January 3, 2014 18:12
Steam engine and spatter init files
local G=_G
local _ENV={}
name="Spatter"
raws_list={"building_spatter.txt","reaction_spatter.txt"}
patch_entity=[[
[PERMITTED_REACTION:SPATTER_ADD_WEAPON_EXTRACT]
[PERMITTED_REACTION:SPATTER_ADD_AMMO_EXTRACT]
]]
patch_files={
--installs a modpack
-- args: modpack_name [-i|install|-if] [-u|uninstall] [entity_to_patch]
args={...}
if args[1]==nil or #args<2 then
print("Usage: modpack_name [-i|install|-if] [-u|uninstall] [entity_to_patch]")
end
local modPath=dfhack.getDFPath()..'/mods/'..args[1]..'/'
local dfMod=dofile(modPath..'init.lua')
local name=dfMod.name
@warmist
warmist / mod_init.lua
Last active January 2, 2016 03:18
A mod init file example
local G=_G
local _ENV={}
name="Mechanical Workshops"
raws_list={"building_dragon_engine.txt"}
patch_entity=[[
[PERMITTED_BUILDING:DRAGON_ENGINE_S]
[PERMITTED_BUILDING:DRAGON_ENGINE_E]
[PERMITTED_BUILDING:DRAGON_ENGINE_W]
[PERMITTED_BUILDING:DRAGON_ENGINE_N]
function loopFix()
dofile('hack/scripts/fix/population-cap.lua')
dfhack.timeout(3,'months',loopFix)
end
loopFix()
@warmist
warmist / testEventful.lua
Created October 20, 2013 21:06
A eventful test script
local ev=require("plugins.eventful")
local freq={[1]=10,[2]=5,[3]=500,[4]=1000,[5]=500,[6]=100,[7]=1,[8]=1000}
for k,v in pairs(freq) do
ev.enableEvent(k,v)
end
ev.onBuildingCreatedDestroyed.one=function(id) print("building cr/d:",id) end
ev.onConstructionCreatedDestroyed.one=function(id) print("construct cr/d:",id) end
ev.onJobInitiated.one=function(job) print("job init:",job) end
ev.onJobCompleted.one=function(job) print("job complete :",job) end
ev.onUnitDeath.one=function(id) print("death:",id) end