Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [DFHack script help request] Foreign nobles  (Read 1919 times)

Button

  • Bay Watcher
  • Plants Specialist
    • View Profile
[DFHack script help request] Foreign nobles
« on: October 16, 2013, 11:55:38 am »

OK so.

It has come to my attention that invaders stop being fun after their general/princess/whatever shows up. The goblins stop bringing fun animals; and in the case of the elves, it looks like they've stopped sending me ambushes entirely ( :( ).

So my idea is to write a script which will pick a random* member of the civilization in question from Legends mode and elevate them to nobility to continue the fun!

* living, adult, with a preference for demons

Alternately, if this isn't possible or wouldn't accomplish the goal of continuing exotic animal imports, simply forbidding the general/princess/whatever from showing up with sieges would be fine too.

I've looked through the DFHack Lua API but haven't found any way to tell what civilization an NPC belongs to (except a boolean 'does it belong to mine', which isn't very helpful). I've not done any memory hacking before so I could use some pointers on where to start?
Logged
I used to work on Modest Mod and Plant Fixes.

Always assume I'm not seriously back

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack script help request] Foreign nobles
« Reply #1 on: October 17, 2013, 01:08:11 am »

The civilization a unit belongs to can be found with df.historical_entity.find(unit.civ_id).

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: [DFHack script help request] Foreign nobles
« Reply #2 on: October 17, 2013, 01:20:20 am »

When you get the historical entity you need, you need to add an appointment (afcourse first selecting valid choice for a general...)
Code: [Select]
--get hist entity by putnam's way
local civ=df.historical_entity.find(unit.civ_id) -- <-- here unit is e.g. dfhack.gui.getSelectedUnit() or something
--iterate over hist figures and select the one you like:
local newGeneral
for idx,figure in ipairs(civ.hist_figures) do
   if figure.died_year~=-1 then -- i'm lazy and only check if it's not dead
      newGeneral=figure
      break
   end
end
--now generate an appointment, you could (might need) to add appropriate historical events
--maybe this too: for idx,assignment in pairs(<position assignments...>) do
local trgVector=civ.assignments_by_type.<some type(s) you need get from postions in entity>
trgVector:insert("#",{new=true,histfig=newGeneral.id,postion=<get from positions>})

Button

  • Bay Watcher
  • Plants Specialist
    • View Profile
Re: [DFHack script help request] Foreign nobles
« Reply #3 on: October 17, 2013, 01:27:51 pm »

Excellent! Thanks all.
Logged
I used to work on Modest Mod and Plant Fixes.

Always assume I'm not seriously back

rmblr

  • Bay Watcher
    • View Profile
Re: [DFHack script help request] Foreign nobles
« Reply #4 on: November 03, 2013, 05:16:43 am »

Anyone care to turn this into a dfhack script we could drop into hack/scripts/?
Logged