v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "User:Andux/Scripts"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(→‎General: +GoodAsNew)
(+Kinsey, remove HealUnit (made obsolete by DFHack's included full-heal script))
 
(2 intermediate revisions by the same user not shown)
Line 58: Line 58:
 
"umma", "undi", "unga", "unni",  
 
"umma", "undi", "unga", "unni",  
 
"vala", "vali", "vara", "vari", "vina",
 
"vala", "vali", "vara", "vari", "vina",
 +
 
"ya",
 
"ya",
 
"zadi", "zani", "zara", "zi"
 
"zadi", "zani", "zara", "zi"
Line 103: Line 104:
 
if unit.flags1.important_historical_figure or unit.flags2.important_historical_figure then
 
if unit.flags1.important_historical_figure or unit.flags2.important_historical_figure then
 
--Use the same name as the histfig data
 
--Use the same name as the histfig data
unit.name.first_name = df.global.world.history.figures[unit.hist_figure_id].name.first_name;
+
unit.name.first_name = df.historical_figure.find(unit.hist_figure_id).name.first_name;
 
else
 
else
 
if (unit.sex ~= 0) then
 
if (unit.sex ~= 0) then
Line 152: Line 153:
  
 
===Urbanizer===
 
===Urbanizer===
Converts all forest retreats to visitable towns.
+
For older versions of Dwarf Fortress--converts all forest retreats to visitable towns.
 
<pre style="overflow: auto;">
 
<pre style="overflow: auto;">
 
for k,v in pairs(df.global.world.world_data.sites) do
 
for k,v in pairs(df.global.world.world_data.sites) do
Line 163: Line 164:
  
 
==General==
 
==General==
===HealUnit===
 
Repairs all health issues except for syndromes and severed limbs.
 
<pre style="overflow: auto;">
 
local unit=dfhack.gui.getSelectedUnit()
 
if unit then
 
print("Erasing wounds...")
 
while #unit.body.wounds > 0 do
 
unit.body.wounds:erase(#unit.body.wounds-1)
 
end
 
unit.body.wound_next_id=1
 
 
print("Refilling blood...")
 
unit.body.blood_count=unit.body.blood_max
 
 
print("Resetting status flags...")
 
unit.status2.able_stand_impair=unit.status2.able_stand
 
unit.status2.able_grasp_impair=unit.status2.able_grasp
 
 
unit.flags2.has_breaks=false
 
unit.flags2.gutted=false
 
unit.flags2.circulatory_spray=false
 
unit.flags2.vision_good=true
 
unit.flags2.vision_damaged=false
 
unit.flags2.vision_missing=false
 
unit.flags2.breathing_good=true
 
unit.flags2.breathing_problem=false
 
 
unit.flags2.calculated_nerves=false
 
unit.flags2.calculated_bodyparts=false
 
 
print("Resetting counters...")
 
unit.counters.winded=0
 
unit.counters.stunned=0
 
unit.counters.unconscious=0
 
unit.counters.webbed=0
 
unit.counters.pain=0
 
unit.counters.nausea=0
 
unit.counters.dizziness=0
 
 
unit.counters2.paralysis=0
 
unit.counters2.fever=0
 
unit.counters2.exhaustion=0
 
unit.counters2.hunger_timer=0
 
unit.counters2.thirst_timer=0
 
unit.counters2.sleepiness_timer=0
 
unit.counters2.vomit_timeout=0
 
 
end
 
</pre>
 
  
 
===GoodAsNew===
 
===GoodAsNew===
Line 233: Line 185:
 
r.wear_timer=0
 
r.wear_timer=0
 
printall(r)
 
printall(r)
 +
end
 +
</pre>
 +
 +
===Kinsey===
 +
<pre style="overflow: auto;">
 +
-- View or change the sexual orientation of the selected unit.
 +
 +
--[====[
 +
 +
kinsey
 +
======
 +
View or change the sexual orientation of the selected unit. Usage:
 +
 +
:kinsey:
 +
    Print the unit's orientation flags.
 +
:kinsey -asexual:
 +
    Change flags so that the unit will not romance or marry anyone.
 +
:kinsey -rf:
 +
    Allow the unit to romance females.
 +
:kinsey -rm:
 +
    Allow the unit to romance males.
 +
:kinsey -mf:
 +
    Allow the unit to marry females.
 +
:kinsey -mm:
 +
    Allow the unit to marry males.
 +
:kinsey -indeterminate:
 +
    Mark the unit's orientation as indeterminate (default for adventurers).
 +
 +
Apart from the -asexual flag, any of the options above can be used together;
 +
for example, ``kinsey -rm -mf`` will allow a unit to romance either sex, but
 +
only marry females.
 +
 +
]====]
 +
 +
local utils = require('utils')
 +
 +
local validArgs = utils.invert({
 +
    'asexual',
 +
    'rf',
 +
    'rm',
 +
    'mf',
 +
    'mm',
 +
    'indeterminate',
 +
    'help',
 +
})
 +
 +
local args = utils.processArgs({...}, validArgs)
 +
 +
if args.help then
 +
print(dfhack.script_help())
 +
return
 +
end
 +
 +
local unit = dfhack.gui.getSelectedUnit()
 +
if not unit then
 +
qerror('Error: please select a unit.')
 +
end
 +
 +
local hf = df.historical_figure.find(unit.hist_figure_id)
 +
if not hf then
 +
print("Warning: Couldn't find histfig data for this unit.")
 +
end
 +
 +
if unit then
 +
if args.asexual then
 +
unit.status.current_soul.orientation_flags.indeterminate = false
 +
unit.status.current_soul.orientation_flags.romance_male = false
 +
unit.status.current_soul.orientation_flags.marry_male = false
 +
unit.status.current_soul.orientation_flags.romance_female = false
 +
unit.status.current_soul.orientation_flags.marry_female = false
 +
print("Unit orientation flags cleared.")
 +
if hf then
 +
hf.orientation_flags.indeterminate = false
 +
hf.orientation_flags.romance_male = false
 +
hf.orientation_flags.marry_male = false
 +
hf.orientation_flags.romance_female = false
 +
hf.orientation_flags.marry_female = false
 +
print("Changes propagated to histfig data.")
 +
end
 +
 +
elseif args.indeterminate or args.rm or args.mm or args.rf or args.mf then
 +
unit.status.current_soul.orientation_flags.indeterminate = (args.indeterminate~=nil)
 +
unit.status.current_soul.orientation_flags.romance_male = (args.rm~=nil)
 +
unit.status.current_soul.orientation_flags.marry_male = (args.mm~=nil)
 +
unit.status.current_soul.orientation_flags.romance_female = (args.rf~=nil)
 +
unit.status.current_soul.orientation_flags.marry_female = (args.mf~=nil)
 +
print("Unit orientation flags updated.")
 +
if hf then
 +
hf.orientation_flags.indeterminate = unit.status.current_soul.orientation_flags.indeterminate
 +
hf.orientation_flags.romance_male = unit.status.current_soul.orientation_flags.romance_male
 +
hf.orientation_flags.marry_male = unit.status.current_soul.orientation_flags.marry_male
 +
hf.orientation_flags.romance_female = unit.status.current_soul.orientation_flags.romance_female
 +
hf.orientation_flags.marry_female = unit.status.current_soul.orientation_flags.marry_female
 +
print("Histfig data updated to match.")
 +
end
 +
end
 +
 +
print("Current orientation flags:")
 +
print("  indeterminate: ", unit.status.current_soul.orientation_flags.indeterminate)
 +
print("  romance_male:  ", unit.status.current_soul.orientation_flags.romance_male)
 +
print("  marry_male:    ", unit.status.current_soul.orientation_flags.marry_male)
 +
print("  romance_female:", unit.status.current_soul.orientation_flags.romance_female)
 +
print("  marry_female:  ", unit.status.current_soul.orientation_flags.marry_female)
 
end
 
end
 
</pre>
 
</pre>

Latest revision as of 16:05, 19 July 2018

A collection of scripts for DFHack.

Fortress mode[edit]

Name generator[edit]

Based on Aerval's; changes:

  • Expanded selection of name parts.
  • Uses the world's name seed instead of the dwarf race index.
  • Better handling of historical figures.
--Nameparts by http://jtevans.kilnar.com/rpg/dnd/tools/dwarf.php, Aerval, and Andux
local firstnamepart = {
	"ad", "ak", "an", "ar", "ash", "at",
	"ba", "bal", "bar", "bel", "ber", "bil", "bof", "bol", "bro", "bul",
	"cal", "chal",
	"da", "das", "dal", "dim", "dor", "dru", "dur", "dwe", "dwin",
	"el",
	"fal", "far", "fash", "fel", "fim", "ful", "fun",
	"gal", "gar", "ger", "gil", "gim", "gom", "gol", "gri", "gro", "gru", "grun",
	"ha", "hal", "ham", "har", "hel", "her", "ho", "hol", "hor", "hul",
	"ing", "in", "ir",

	"kal", "kas", "ket", "kha", "khor", "kil", "kin", "ko", "kor", "kul",
	"lam", "lar", "lon", "lun",
	"mag", "mal", "mar", "mor", "mun",
	"nal", "nar", "nil", "nor",
	"ol", "or", "ov",

	"rag", "ral", "ram", "rim", "ron", "run", 
	"sal", "sar", "shal", "shar", "shor", "sim", "sor", "stal", "stav", "sven",
	"tan", "tha", "thal", "thin", "thor", "thra", "thu", 
	"um", "ur",
	"val", "van",
	"wil",

	"yar",
	"za", "zir", "zul"
};
local female_secondpart = {
	"a", "ada", "ala", "ana", "ani", "atha",
	"bari", "bina", "bine", "bura", 
	"cha", "chi",
	"da", "dana", "dani", "dili", "dina", "dola", "dora", "dri", "dria", 
	"edi", "ena", "eta", "eva", "eza",
	"fani", "fi",
	"ga", "gana", "gari", "gela", "gina", "gini", "goli", "grima", 

	"i", "ia", "ida", "ila", "ilda", "ili", "ika", "ina", "iri",

	"ka", "ki", "kia", "kona", "kuni",
	"la", "lani", "leda", "lena", "lia", "lina", "lona",
	"ma", "mani", "mela", "mina", "moda", "modi",
	"na", "neva", "ni", "nia", "nomi",
	"ola", "olga", "ona", "ondi", "oti", "ova",

	"ra", "raka", "rana", "ravi", "ri", "ria", "rimi", "rinda", "rundi", 
	"sha", "shi", "si", "ska",
	"ta", "tha", "ti", "tila", "tri", "tria", 
	"umma", "undi", "unga", "unni", 
	"vala", "vali", "vara", "vari", "vina",

	"ya",
	"zadi", "zani", "zara", "zi"
};
local male_secondpart = {
	"aim", "ain", "ak", "ald", "am", "ar", "ard", "ash", 
	"bain", "bald", "ban", "bar", "bash", "brun", "bur", 

	"dain", "dall", "dar", "din", "dok", "dol", "dor", "dum", "dun", "dur",
	"eff", "esh", "ev",
	"far", "fath", "feb",
	"gan", "gar", "gath", "gin", "gor", "grim", 

	"ik", "il", "im", "in", "ip", "isch", 

	"kad", "kar", "kash", "keld", "kesh", "kon", 
	"lek", "lem", "lesh", "let", "leth", "lin", "lor", 
	"mar", "mek", "min", "mok", "mon", "moth", "mund", 
	"nar", "nek", "nir", "nod", "nor", 
	"od", "oin", "ok", "old", "on", "ond", "or", 

	"rak", "ram", "rik", "rim", "rin", "ros", "roth", "rund", 
	"skal", "skar",
	"tar", "tek", "til", "tok", "tul",
	"um", "und", "unn", "ur", "urd",
	"val", "van", "var", "vath", "vek", "ven", "vesh", "veth", "vin", "von",

	"zad", "zar", "zek", "zim", "zin"
};

local dwarfRace = df.global.ui.race_id;

math.randomseed(tonumber(df.global.world.worldgen.worldgen_parms.name_seed,36));
for index,unit in pairs(df.global.world.history.figures) do --Renaming all the historical dwarves
	if ( unit.race == dwarfRace ) then
		if (unit.sex ~= 0) then
			unit.name.first_name = firstnamepart[math.random(#firstnamepart)]..male_secondpart[math.random(#male_secondpart)];
		else
			unit.name.first_name = firstnamepart[math.random(#firstnamepart)]..female_secondpart[math.random(#female_secondpart)];
		end
	end
end
for index,unit in pairs(df.global.world.units.all) do --Renaming pretty much everyone else
	if ( unit.race == dwarfRace ) then
		if unit.flags1.important_historical_figure or unit.flags2.important_historical_figure then
			--Use the same name as the histfig data
			unit.name.first_name = df.historical_figure.find(unit.hist_figure_id).name.first_name;
		else
			if (unit.sex ~= 0) then
				unit.name.first_name = firstnamepart[math.random(#firstnamepart)]..male_secondpart[math.random(#male_secondpart)];
			else
				unit.name.first_name = firstnamepart[math.random(#firstnamepart)]..female_secondpart[math.random(#female_secondpart)];
			end
		end
	end
end
print("firstnamepart: "..#firstnamepart.."\nfemale: "..#female_secondpart.."\nmale: "..#male_secondpart);

Adventure mode[edit]

Item material changer[edit]

Roughly equivalent to changeitem m, but works better in adventure mode.

local r=nil
local top=dfhack.gui.getCurViewscreen()
print(top.parent,top)
local cvstype=dfhack.gui.getFocusString(top)
print(dfhack.gui.getFocusString(top.parent).."/"..cvstype)
if cvstype=="dungeon_monsterstatus" then
	print("  inventory size: "..#top.inventory)
	print("  inventory_cursor: "..top.inventory_cursor)
	r=top.inventory[top.inventory_cursor].item
elseif cvstype=="item" then
	-- override getSelectedItem()'s default behaviour for containers
	r=top.item
else
	r=dfhack.gui.getSelectedItem()
end

if r then
	local m=...
	if not m then
		print("no material")
		return
	end

	r.mat_type=dfhack.matinfo.find(m).type
	r.mat_index=dfhack.matinfo.find(m).index
	r.flags.weight_computed=0

	printall(r)
end

Urbanizer[edit]

For older versions of Dwarf Fortress--converts all forest retreats to visitable towns.

for k,v in pairs(df.global.world.world_data.sites) do
	if v.type==4 then
		v.type=5
		print('Site #'..k..': '..dfhack.TranslateName(v.name)..', "'..dfhack.TranslateName(v.name,1)..'", converted to town.')
	end
end

General[edit]

GoodAsNew[edit]

Removes all wear from the selected item.

local r=nil
local top=dfhack.gui.getCurViewscreen()
print(top.parent,top)
local cvstype=dfhack.gui.getFocusString(top)
print(dfhack.gui.getFocusString(top.parent).."/"..cvstype)
if cvstype=="dungeon_monsterstatus" then
	print("  inventory size: "..#top.inventory)
	print("  inventory_cursor: "..top.inventory_cursor)
	r=top.inventory[top.inventory_cursor].item
else
	r=dfhack.gui.getSelectedItem()
end

if r then
	r.wear=0
	r.wear_timer=0
	printall(r)
end

Kinsey[edit]

-- View or change the sexual orientation of the selected unit.

--[====[

kinsey
======
View or change the sexual orientation of the selected unit. Usage:

:kinsey:
    Print the unit's orientation flags.
:kinsey -asexual:
    Change flags so that the unit will not romance or marry anyone.
:kinsey -rf:
    Allow the unit to romance females.
:kinsey -rm:
    Allow the unit to romance males.
:kinsey -mf:
    Allow the unit to marry females.
:kinsey -mm:
    Allow the unit to marry males.
:kinsey -indeterminate:
    Mark the unit's orientation as indeterminate (default for adventurers).

Apart from the -asexual flag, any of the options above can be used together;
for example, ``kinsey -rm -mf`` will allow a unit to romance either sex, but
only marry females.

]====]

local utils = require('utils')

local validArgs = utils.invert({
    'asexual',
    'rf',
    'rm',
    'mf',
    'mm',
    'indeterminate',
    'help',
})

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

if args.help then
	print(dfhack.script_help())
	return
end

local unit = dfhack.gui.getSelectedUnit()
if not unit then
	qerror('Error: please select a unit.')
end

local hf = df.historical_figure.find(unit.hist_figure_id)
if not hf then
	print("Warning: Couldn't find histfig data for this unit.")
end

if unit then
	if args.asexual then
		unit.status.current_soul.orientation_flags.indeterminate = false
		unit.status.current_soul.orientation_flags.romance_male = false
		unit.status.current_soul.orientation_flags.marry_male = false
		unit.status.current_soul.orientation_flags.romance_female = false
		unit.status.current_soul.orientation_flags.marry_female = false
		print("Unit orientation flags cleared.")
		if hf then
			hf.orientation_flags.indeterminate = false
			hf.orientation_flags.romance_male = false
			hf.orientation_flags.marry_male = false
			hf.orientation_flags.romance_female = false
			hf.orientation_flags.marry_female = false
			print("Changes propagated to histfig data.")
		end

	elseif args.indeterminate or args.rm or args.mm or args.rf or args.mf then
		unit.status.current_soul.orientation_flags.indeterminate = (args.indeterminate~=nil)
		unit.status.current_soul.orientation_flags.romance_male = (args.rm~=nil)
		unit.status.current_soul.orientation_flags.marry_male = (args.mm~=nil)
		unit.status.current_soul.orientation_flags.romance_female = (args.rf~=nil)
		unit.status.current_soul.orientation_flags.marry_female = (args.mf~=nil)
		print("Unit orientation flags updated.")
		if hf then
			hf.orientation_flags.indeterminate = unit.status.current_soul.orientation_flags.indeterminate
			hf.orientation_flags.romance_male = unit.status.current_soul.orientation_flags.romance_male
			hf.orientation_flags.marry_male = unit.status.current_soul.orientation_flags.marry_male
			hf.orientation_flags.romance_female = unit.status.current_soul.orientation_flags.romance_female
			hf.orientation_flags.marry_female = unit.status.current_soul.orientation_flags.marry_female
			print("Histfig data updated to match.")
		end
	end

	print("Current orientation flags:")
	print("  indeterminate: ", unit.status.current_soul.orientation_flags.indeterminate)
	print("  romance_male:  ", unit.status.current_soul.orientation_flags.romance_male)
	print("  marry_male:    ", unit.status.current_soul.orientation_flags.marry_male)
	print("  romance_female:", unit.status.current_soul.orientation_flags.romance_female)
	print("  marry_female:  ", unit.status.current_soul.orientation_flags.marry_female)
end