Add this to advfort in some of the functions around line #400 or so:
oh yeah I remember having a carry, drag, mount and Stuff folks into a item function for dfhack for several years now due to help by warmist.
kinda made looking at this thread in puzzle confusion though.
loads of fun for making a chain of dragging units each being pulled by another person.
the drag code that I had for years back, probably need an update since relationships section in dfhack got rewritten.
{name="Grab",f=function (unit_list)
for k,v in pairs(unit_list) do
if tofollow==nil then
tofollow=df.global.world.units.active[0]
end
if unit==nil then
print=("no one is selected")
end
v.following=tofollow
v.relationship_ids.dragger_id=tofollow.id
v.relationship_ids.draggee_id=v.id
v.unk_238=8
tofollow.relationship_ids.draggee_id=v.id
--[[unit.relations.following=tofollow
v.relations.unk_258=tofollow.id
v.relations.unk_238=8
tofollow.relations.unk_254=v.id]]--
end
return true
end},
{name="Let go",f=function (unit_list)
for k,v in pairs(unit_list) do
if tofollow==nil then
tofollow=df.global.world.units.active[0]
end
if unit==nil then
print=("no one is selected")
end
v.following=nil
v.relationship_ids.dragger_id=-1
v.relationship_ids.draggee_id=-1
v.unk_238=-1
tofollow.relationship_ids.draggee_id=-1
end
return true
end},
and the old script for shoving folks into an item
{name="Shove in",f=function (unit_list,pos)
unit=getCreatureAtPos(getxyz())
item=getItemAtPos(getxyz())
for a,b in ipairs(df.global.world.items.all) do for c,d in ipairs(b.general_refs) do end end
local u_ref=df.general_ref_contains_unitst:new()
u_ref.unit_id=unit.id
item.general_refs:insert(#item.general_refs,u_ref)
local u_cr_ref=df.general_ref_contained_in_itemst:new()
unit.flags1.caged=true
u_cr_ref.item_id=item.id
general_refs:insert(#general_refs,u_cr_ref)
return true
end},
though nice to see max making addons to advfort.
I was looking at the ride launch/ollie stuff and it clicked why the old cage creature/etc bits weren't working.
These are the bits I was tinkering with:
function SetCagedRef(args)
local caged
local pos=args.pos
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
caged = v
end
end
local adv=df.global.world.units.active[0]
local items=EnumItems{pos=adv.pos,unit=adv,
inv={[df.unit_inventory_item.T_mode.Hauled]=true,--[df.unit_inventory_item.T_mode.Worn]=true,
[df.unit_inventory_item.T_mode.Weapon]=true,},deep=true}
local choices={}
for k,v in pairs(items) do
table.insert(choices,{text=dfhack.items.getDescription(v,0),item=v})
end
dialog.showListPrompt("Item choice", "Choose item to put into:", COLOR_WHITE,choices,
function (idx,choice)
caged.flags1.on_ground = true
caged.flags1.move_state = false
choice.item.general_refs:insert('#',{new=df.general_ref_contains_unitst,unit_id=caged.id})
caged.general_refs:insert("#",{new=df.general_ref_contained_in_itemst,item_id=choice.item.id})
choice.item.flags.container = true
choice.item.flags.weight_computed = false
caged.flags1.caged = true
return
end)
dfhack.maps.ensureTileBlock(caged.pos).occupancy[caged.pos.x%16][caged.pos.y%16].unit = false
caged.flags1.on_ground = false
end
function SetCarryRef(args)
local mnt
local rid
local pos=args.pos
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
mnt = df.global.world.units.active[0]
rid = v
mnt.general_refs:insert("#",{new=df.general_ref_unit_riderst,unit_id=rid.id})
dfhack.maps.ensureTileBlock(rid.pos).occupancy[rid.pos.x%16][rid.pos.y%16].unit = false
rid.relationship_ids.RiderMount=mnt.id
rid.pos.x=mnt.pos.x
rid.pos.y=mnt.pos.y
rid.pos.z=mnt.pos.z
rid.flags1.rider=true
mnt.flags1.ridden=true
require("utils").insert_sorted(df.global.world.units.other.ANY_RIDER,rid,"id")
return
end
end
end
function SetPatientRef(args)
local job=args.job
local pos=args.pos
local doc=df.global.world.units.active[0]
-- doc.general_refs:insert("#",{new=df.general_ref_unit_workerst,unit_id=doc.id})
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
doc.general_refs:insert("#",{new=df.general_ref_unit_patientst,unit_id=v.id})
return
end
end
end
function SetGeldingRef(args)
local job=args.job
local pos=args.pos
local doc=df.global.world.units.active[0]
-- doc.general_refs:insert("#",{new=df.general_ref_unit_workerst,unit_id=doc.id})
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
doc.general_refs:insert("#",{new=df.general_ref_unit_geldeest,unit_id=v.id})
v.flags3.gelded=true
return
end
end
end
function SetFightRef(args)
local jerk
local mark
local job=args.job
if jerk==nil then
local pos1=args.pos
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos1.x and v.pos.y==pos1.y and v.pos.z==pos1.z then
jerk=v
jerk.job.current_job=job
-- jerk.general_refs:insert("#",{new=df.general_ref_unit_workerst,unit_id=jerk.id})
dfhack.gui.showAnnouncement("Selected Jerk",COLOR_YELLOW,true)
return jerk
end
end
elseif mark==nil then
local pos2=args.pos
for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos2.x and v.pos.y==pos2.y and v.pos.z==pos2.z then
mark=v
jerk.job.hunt_target=mark
dfhack.gui.showAnnouncement("Selected Mark",COLOR_YELLOW,true)
return mark
end
end
end
end
I almost had the patient stuff working I thought but I got lost because I started wondering if I could do the fight starting stuff similarly, I made the SetCageRef function into a "cram targeted unit into [choose an item]" option.
These are what I was trying to do for the actual interface option bits:
{"Recover" ,df.job_type.RecoverWounded,{SetCarryRef,SetPatientRef}},
{"Diagnose" ,df.job_type.DiagnosePatient,{SetPatientRef}},
{"Clean Patient" ,df.job_type.CleanPatient,{SetPatientRef}},
{"Dress Wound" ,df.job_type.DressWound,{SetPatientRef}},
{"Set Bone" ,df.job_type.SetBone,{SetPatientRef}},
{"Surgery" ,df.job_type.Surgery,{SetPatientRef}},
{"Suture" ,df.job_type.Suture,{SetPatientRef}},
{"Geld" ,df.job_type.GeldAnimal,{SetPatientRef}},
{"Carry" ,SetCarryRef,{}},
{"Instigate" ,df.job_type.StartingFistFight,{SetFightRef}},
{"Confine" ,SetCagedRef,{}},