Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 287 288 [289] 290 291 ... 373

Author Topic: DFHack 0.34.11 r3  (Read 1456420 times)

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4320 on: July 27, 2013, 09:32:41 pm »

...code...

Awesome, thanks.  I thought I'd seen you post code like that earlier in the thread but was too lazy to go find it.  :)

Here are redone versions of the marry and divorce scripts that use the interface to pick targets.  I just tested them both in my version of DFHack and they work fine.  I think that perhaps using this will help alleviate whatever was wrong in the newer version of DFHack.

Code: (divorce.lua) [Select]
-- Divorces a creature from its spouse and / or lover.  Run this per creature in a relationship.

function divorce (victim)

local historic_victim

for key, value in pairs(df.global.world.units.all) do
-- The arguments are strings, but the structs contain numbers
if value.id == unit_id then
victim = value
end
end

if df.isnull(victim) then
print('The unit was not found.')
return
end

if victim.relations.spouse_id == -1 and victim.relations.lover_id == -1 then
print('Warning: the unit has no lover or spouse, nothing to do.')
return
end

print("Divorcing " .. victim.name.nickname)

for key, value in pairs(df.global.world.history.figures) do
if value.id == victim.hist_figure_id then
historic_victim = value
end
end

if df.isnull(historic_victim) then
print('The historical figure for the unit was not found.')
return
end

local link_count = #historic_victim.histfig_links

-- Remove the spouse hf link, if it exists
for key, value in pairs(historic_victim.histfig_links) do
if df.histfig_hf_link_spousest:is_instance(value) then
if key ~= link_count -1 then
-- Moves the spouse entry to the end of the list, then resizes the list to size - 1, erasing it
historic_victim.histfig_links[key] = historic_victim.histfig_links[link_count - 1]
end

historic_victim.histfig_links:resize(link_count - 1)
link_count = link_count - 1
value:delete()

break
end
end

-- Remove the lover hf link, if it exists
for key, value in pairs(historic_victim.histfig_links) do
if df.histfig_hf_link_loverst:is_instance(value) then
if key ~= link_count -1 then
-- Moves the lover entry to the end of the list, then resizes the list to size - 1, erasing it
historic_victim.histfig_links[key] = historic_victim.histfig_links[link_count - 1]
end

historic_victim.histfig_links:resize(link_count - 1)
link_count = link_count - 1
value:delete()

break
end
end

victim.relations.spouse_id = -1
victim.relations.lover_id = -1
end

unit = dfhack.gui.getSelectedUnit()
if (unit == nil) then
print('You must place the cursor over the target.')
return
end

dfhack.with_suspend(divorce, unit)

Code: (marry.lua) [Select]
-- Marries two specified creatures.  Take care when using this on creatures that are already married!

function marry (victim1, victim2)

local historic_victim1
local historic_victim2

if df.isnull(victim1) then
print('The first unit was not found.')
return
end
if df.isnull(victim2) then
print('The second unit was not found.')
return
end

if victim1.relations.spouse_id ~= -1 then
print('Warning: the first unit is already married.  Their marriage will be replaced.')
end
if victim2.relations.spouse_id ~= -1 then
print('Warning: the second unit is already married.  Their marriage will be replaced.')
end

print("Marrying " .. victim1.name.nickname .. " and " .. victim2.name.nickname)

for key, value in pairs(df.global.world.history.figures) do
if value.id == victim1.hist_figure_id then
historic_victim1 = value
end
if value.id == victim2.hist_figure_id then
historic_victim2 = value
end
end

if df.isnull(historic_victim1) then
print('The historical figure for the first unit was not found.')
return
end
if df.isnull(historic_victim2) then
print('The historical figure for the second unit was not found.')
return
end

local new_link1 = df.histfig_hf_link_spousest:new()
local new_link2 = df.histfig_hf_link_spousest:new()

-- Not documented, but this is the historical figure id
new_link1.anon_1 = victim2.hist_figure_id
new_link1.link_strength = 100

new_link2.anon_1 = victim1.hist_figure_id
new_link2.link_strength = 100

local link_count1 = #historic_victim1.histfig_links
local link_count2 = #historic_victim2.histfig_links

historic_victim1.histfig_links:resize(link_count1 + 1)
historic_victim1.histfig_links[link_count1] = new_link1
historic_victim2.histfig_links:resize(link_count2 + 1)
historic_victim2.histfig_links[link_count2] = new_link2

victim1.relations.spouse_id = victim2.id
victim2.relations.spouse_id = victim1.id
end

unit_1 = dfhack.gui.getSelectedUnit()
if unit_1 == nil then
print ("You must place the cursor over the first target.")
return
end

print("Target second unit and press enter")
test = dfhack.lineedit("")

unit_2 = dfhack.gui.getSelectedUnit()
if unit_2 == nil then
print ("You must place the cursor over the second target.")
return
end

dfhack.with_suspend(marry, unit_1, unit_2)

They still do the unnecessary with_suspend thing and I never added in the code to add historical event entries for marriage and divorce, but that never mattered to me.
Logged
Through pain, I find wisdom.

Grax

  • Bay Watcher
  • The Only.
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4321 on: July 27, 2013, 10:35:49 pm »

Hey, clever lua guys, would somebody of you be so kind and release a newer version with all those beautiful additions?
Logged
Finis sanctificat media.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #4322 on: July 28, 2013, 12:11:12 am »

I encountered a little problem with the feature script. I want to run it with autosyndrome whenever the player spawns magma with magical means in a reaction. This way they can build magma furnaces without the need to dig down. I can already spawn magma (although my screw-pump like liquid-spawner idea still stands) and I can run the script manually. But it shows some odd behaviour.

When I type "feature list" it shows the map features. These differ from map to map. Each feature has a number, and a name. The script claims that you can run it by either.

"Feature show 8" and "Feature show magma_pool" should both enable the magma-pool in my test map. But only "feature show 8" works, while "feature show magma_pool" reveal the first feature in the list, a cave. Here a screenshot as proof:


The problem I have is that the numbers are different on each map. I can only have the reaction do one keyword, it is not smart enough to run "feature list" and then pick the correct number for magma-pool. I wanted to run "feature show magma_pool", but it does not work, as I said above. Anyone knows any solution to this?

EDIT: Oh, and another random thought: Is it possible to make a creature simply disappear? Just gone, no corpse, no ghosts, no negative thoughts for friends and family... I saw a threat about "migrants leaving the fort" in the suggestion board. Maybe that can be done with dfhack as is. :)
« Last Edit: July 28, 2013, 01:08:57 pm by Meph »
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4323 on: July 28, 2013, 02:33:12 pm »

EDIT: Oh, and another random thought: Is it possible to make a creature simply disappear? Just gone, no corpse, no ghosts, no negative thoughts for friends and family... I saw a threat about "migrants leaving the fort" in the suggestion board. Maybe that can be done with dfhack as is. :)
try unit.flags2.cleanup_1=true . There is also 2 and 3 and unit.flags3.cleanup_4 but i'm not sure how different they are.

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: DFHack 0.34.11 r3
« Reply #4324 on: July 29, 2013, 06:23:19 am »

"Feature show 8" and "Feature show magma_pool" should both enable the magma-pool in my test map. But only "feature show 8" works, while "feature show magma_pool" reveal the first feature in the list, a cave.
That's because it only accepts a number, so if you try to enter a string it'll interpret it as zero.

If you want to show/hide features programatically, then look at how the feature command works and then duplicate (and augment) its functionality in a Lua script - iterate across the list of features, find one of the appropriate type, then show/hide it accordingly. The 'feature' command is really only meant to be used interactively.

There's also the issue that not every map has a magma pool (most will only have the magma sea itself), so it's possible that your reaction won't have any effect at all.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: DFHack 0.34.11 r3
« Reply #4325 on: July 29, 2013, 11:35:01 am »

"Feature show 8" and "Feature show magma_pool" should both enable the magma-pool in my test map. But only "feature show 8" works, while "feature show magma_pool" reveal the first feature in the list, a cave.
That's because it only accepts a number, so if you try to enter a string it'll interpret it as zero.

If you want to show/hide features programatically, then look at how the feature command works and then duplicate (and augment) its functionality in a Lua script - iterate across the list of features, find one of the appropriate type, then show/hide it accordingly. The 'feature' command is really only meant to be used interactively.

There's also the issue that not every map has a magma pool (most will only have the magma sea itself), so it's possible that your reaction won't have any effect at all.
Discovering the magma-sea is fine as well. I just want to enable the magma furnaces, thats all. I am also somewhat illiterate when it comes to code, I have never written any scripts besides VisualBasics and Html. C++ is somewhat beyond me. Thats why I come here and ask ;)
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4326 on: July 29, 2013, 02:16:08 pm »

I was totally code-illiterate when I semi-wrote force and mostly code illiterate when I wrote itemsyndrome ;)

sirdodger

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4327 on: July 29, 2013, 07:40:04 pm »

I'm having two issues with DFHack (v0.34.11) under Windows, and I was wondering if anyone came across them or had a solution.  The first is that hotkeys sometimes fail.  The simple Ctrl-V digv binding works some of the time, and not others.  I haven't been able to repro the problem consistently, but sometimes switching out of the game, prodding the DFHack console, and switching back in will fix it.

The second is that the coloring of the military screen (tweak military-color-assigned) does not work for me.  Coloring elsewhere seems to work fine, and tweak military-stable-assigned works fine on that screen.

I'll post more if I can narrow down either of the issues.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4328 on: July 29, 2013, 07:56:13 pm »

1. When you alt-tab out, the alt key gets a bit "stuck" in the input phase. Press alt again when you go back into the game.

Kurik Amudnil

  • Bay Watcher
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4329 on: July 30, 2013, 01:11:40 am »

probably not related to your problem, but windows also doesn't like letting dfhack use Ctrl-Alt hotkeys nor Ctrl and/or Shift Z.  Hotkeys can also be blocked by other utilities/programs such as quickfort
« Last Edit: July 30, 2013, 01:13:31 am by Kurik Amudnil »
Logged

sirdodger

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4330 on: July 30, 2013, 01:42:45 am »

1. When you alt-tab out, the alt key gets a bit "stuck" in the input phase. Press alt again when you go back into the game.

Nailed it, thanks!


probably not related to your problem, but windows also doesn't like letting dfhack use Ctrl-Alt hotkeys nor Ctrl and/or Shift Z.  Hotkeys can also be blocked by other utilities/programs such as quickfort

I noticed that when I was fiddling with hotkeys during setup, but that was less astonishing than having simple hotkeys (like Ctrl-V) sporadically work.
« Last Edit: July 30, 2013, 01:45:14 am by sirdodger »
Logged

silentdeth

  • Bay Watcher
    • View Profile
    • Let's Play Dwarf Fortress: Mastwork Mod Season 1
Re: DFHack 0.34.11 r3
« Reply #4331 on: July 31, 2013, 01:16:02 pm »

I'm adding a LUA API to the feature plugin (assuming nothing is beyond my abilities), most so I can create a LUA script for the masterwork mod that enables magma workshops. Being that I am a lazy bastard I wasn't planning on do much more than just what I need to get that functioning. Is there anything request, or something that anyone feels should be included? I'm learning LUA as I go, so I am not entirely sure of what all the possibilities are. The currently planned functions are feature_list_type, feature_list_name, isDiscovered(int) [can you overload functions in LUA? can I have isDiscovered(string type) too?], setDiscovered(int) [or maybe show(int) to keep it in line with the feature plugin].

Once I am finished what is the process of submitting it to be included in the next dfhack release? I've never contributed to a github project before, mostly I just download them and fiddle with them on my own.

EDIT: is there a way to find a list of all the feature types? I don't know where it gets the names and such for these? Magic I'm pretty sure.

EDIT2: Thanks Putnam that is useful.
« Last Edit: July 31, 2013, 01:30:09 pm by silentdeth »
Logged
Let's Play Dwarf Fortress: Masterwork Mod Season 1 | Season 2
Let's Play Kobold Fortress: Masterwork Mod Season 1 | Season 2

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4332 on: July 31, 2013, 01:21:43 pm »

You can't overload functions, but you can have one function handle both strings and integers, sort of:

Code: [Select]
function typeHandleExample(argument)
    if tonumber(argument) then
        print("Argument is a number.")
    else
        print("Argument is not a number.")
    end
end

If you, say, run "typeHandleExample(5)", you'll get "Argument is a number". If you run "typeHandleExample("foo")", you'll get "Argument is not a number".

silentdeth

  • Bay Watcher
    • View Profile
    • Let's Play Dwarf Fortress: Mastwork Mod Season 1
Re: DFHack 0.34.11 r3
« Reply #4333 on: July 31, 2013, 04:44:15 pm »

I'm doing something wrong and I can't figure out what. I have:
Spoiler (click to show/hide)

And I keep getting the error:
Spoiler (click to show/hide)

So something is wrong with how I am trying to use the Lua::SetField things, but I cannot for the life of me see what the problem could be. Help :(
Logged
Let's Play Dwarf Fortress: Masterwork Mod Season 1 | Season 2
Let's Play Kobold Fortress: Masterwork Mod Season 1 | Season 2

Ccna

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.34.11 r3
« Reply #4334 on: August 01, 2013, 12:14:23 am »

I have been getting this in my stderr file:

Spoiler (click to show/hide)

after getting an error message that says:

Spoiler (click to show/hide)

upon starting dwarf fortress. Does anyone know the solution? thanks in advance.
« Last Edit: August 01, 2013, 03:48:08 pm by Ccna »
Logged
Pages: 1 ... 287 288 [289] 290 291 ... 373