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.

User:Fleeting Frames/assigndeathdate

From Dwarf Fortress Wiki
Jump to navigation Jump to search

Takes up to three numbers: unitid, deathyear and deathtick. If they're not given, uses currently selected unit, current year and current tick.

DF will fail to save and crash instead after running this script.

--assigns death date to an unit (cause: slaughter)
--cannot save after using
local args = {...}
local unitid = tonumber(args[1]) or dfhack.gui.getSelectedUnit().id
local unit = df.unit.find(unitid)
if unit.counters.death_id>-1 then 
	qerror("This unit's death has already been recorded")
end
local deathyear = tonumber(args[2]) or df.global.cur_year
local deathtick = tonumber(args[3]) or df.global.cur_year_tick


local myincident = df.incident:new()

for i,v in pairs(myincident) do
	if(i~="witnesses" and i~="flags") then
		myincident[i] = -1
	end
end

myincident.id = df.global.incident_next_id
myincident.unk_4 = 0--owo what's this? Probably the reason game can't save after using this script
myincident.victim=unitid
myincident.victim_race=unit.race
myincident.victim_caste=unit.caste
myincident.event_year = deathyear
myincident.event_time=deathtick
myincident.death_cause = 49
myincident.flags.announced_missing = true
myincident.flags.discovered = true
myincident.flags.unk2 = true
myincident.site=df.global.ui.site_id
myincident.entity=df.global.ui.group_id
myincident.unk_v40_3a=20 --what does this do? Linked to group? Who knows. Maybe instead this is the reason?
local playerfort = df.world_site.find(myincident.site)
myincident.world_x= 48*(playerfort.global_min_x)+unit.pos.x--dwarfmode tile scale
myincident.world_y= 48*(playerfort.global_min_y)+unit.pos.y
myincident.world_z= df.global.world.map.region_z+unit.pos.z --lowest map z-level.

df.global.world.incidents.all:insert("#",myincident)
df.global.incident_next_id = df.global.incident_next_id +1
unit.counters.death_id=myincident.id