Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DFHack script: unblockmeetings  (Read 1361 times)

PatrikLundell

  • Bay Watcher
    • View Profile
DFHack script: unblockmeetings
« on: July 19, 2017, 07:03:03 am »

I think I've finally found a way to unblock stalled meetings (due to position holder replacements) without killing or driving away petitioners.

unblockmeetings.lua
Code: [Select]
--  Work around for blocked meetings where a change of position holder causes the meeting activities to
--  stall. The somewhat heavy handed approch wipes all meeting activities from the participants and the
--  internal store and relies on DF's ability to rebuild the ones that should actually be there.
--
function unblockmeetings ()
  if not dfhack.isWorldLoaded () or not dfhack.isMapLoaded () then
    dfhack.printerr ("Error: This script requires an embark to be loaded.")
return
  end

  dfhack.println ("Deleting " .. tostring (#df.global.ui.meeting_requests) .. " meeting requests")
  for i = #df.global.ui.meeting_requests - 1, 0, -1 do
    df.global.ui.meeting_requests:erase (i)
  end
 
  dfhack.println ("Deleting " .. tostring (#df.global.ui.activities) .. " activities")
  for i = #df.global.ui.activities - 1, 0, -1 do
    for k = #df.global.ui.activities [i].unit_actor.specific_refs - 1, 0, -1 do
  if df.global.ui.activities [i].unit_actor.specific_refs [k].type == 4 then  -- ACTIVITY
    dfhack.println ("Removing actor ACTIVITY from " .. dfhack.TranslateName (df.global.ui.activities [i].unit_actor.name, true))
    df.global.ui.activities [i].unit_actor.specific_refs:erase (k)
  end
end

    for k = #df.global.ui.activities [i].unit_noble.specific_refs - 1, 0, -1 do
  if df.global.ui.activities [i].unit_noble.specific_refs [k].type == 4 then  -- ACTIVITY
    dfhack.println ("Removing noble ACTIVITY from " .. dfhack.TranslateName (df.global.ui.activities [i].unit_noble.name, true))
    df.global.ui.activities [i].unit_noble.specific_refs:erase (k)
  end
end

df.global.ui.activities:erase (i)
  end
end

unblockmeetings ()

The script has only been tested to a limited extent (I've had a petitioner on route to a meeting, swapped out the expedition leader, ran the script, verified that the visitor did petition, dismissed the petitioner, waited until another petitioner showed up on the petitioner screen). I haven't tried it with diplomats. It may possibly remove things that should be retained in the data structures (I didn't have anything extra in my test case), but I don't know if there are other things that can show up there.

The code is stored in a "text" file called unblockmeetings.lua in the <DF>\hacks\scripts folder and is invoked by typing "unblockmeetings" in the DFHack command console.
Logged