Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DFHACK lua script question. (Spawn nethercaps)  (Read 2428 times)

Weizen1988

  • Bay Watcher
    • View Profile
DFHACK lua script question. (Spawn nethercaps)
« on: July 30, 2019, 09:24:21 am »

So im trying to force nethercap to spawn in an area after the game has started, been poking around for two days and all ive found is this code from 2014

Code: [Select]
feat = df.global.world.cur_savegame.map_features[2]
num = #feat.feature.population
feat.feature.population:insert('#', { new = df.world_population, type = df.world_population_type.Tree, plant = dfhack.matinfo.find('PLANT:NETHER_CAP').index });
for i,j in pairs(df.global.world.populations) do if (j.population.cave_id == feat.layer and j.population.population_idx == num - 1) then df.global.world.populations:insert('#', { new = df.local_population, type = df.world_population_type.Tree, plant = dfhack.matinfo.find('PLANT:NETHER_CAP').index, population = {region_x = j.population.region_x, region_y = j.population.region_y, population_idx = num, cave_id = feat.layer, depth = feat.start_depth, unk_28 = -1 } } ) end end

Which claims to do exactly what Im trying to do, but i get this error

...\DWARFF~1\Dwarf Fortress 0.44.12/hack/scripts/nether.lua:1: Cannot read field world.T_cur_savegame.map_features: not found.
stack traceback:
        [C]: in metamethod '__index'
        ...\DWARFF~1\Dwarf Fortress 0.44.12/hack/scripts/nether.lua:1: in local 'script_code'
        ...ktop\DWARFF~1\Dwarf Fortress 0.44.12\hack\lua\dfhack.lua:680: in function 'dfhack.run_script_with_env'
        (...tail calls...)

I dont understand programming enough to understand what this is doing, or what the error is. Could someone help explain this to me? Or alternately direct me to a better tool to introduce biome/cavern appropriate trees/saplings/spores to an area? Its taken me nearly 4 days to generate a world i have any interest in playing in long term, and the only thing i lack is nethercap for a project. Thank you in advance, I hope this is the right forum.

Link to previous post on same topic I found. incase ive made a mistake or explained poorly.
http://www.bay12forums.com/smf/index.php?topic=135258.0
« Last Edit: July 30, 2019, 09:35:42 am by Weizen1988 »
Logged

ragundo

  • Bay Watcher
    • View Profile
Re: DFHACK lua script question. (Spawn nethercaps)
« Reply #1 on: July 30, 2019, 10:05:07 am »

Hmmm

As you can see, df.global.world.cur_savegame doesn't have a map_features field. That's why dfhack is complaining.

There's a df.global.world.features structure that has the fields that you are looking for. It seems that the script could be outdated and you would need to adapt the script using the newest fields.


Logged

Weizen1988

  • Bay Watcher
    • View Profile
Re: DFHACK lua script question. (Spawn nethercaps)
« Reply #2 on: July 30, 2019, 10:09:01 am »

So alter the lines referring to df.global.world.cur_savegame to look in df.global.world.features instead?

Ill give that a shot in a few minutes, see if that helps.

Edit: Okay, I got no errors this time. Hopefully by the time i breach that cavern (I was checking all this with prospect all) some of them will have grown. Its dumb but I like using nethercap for food prep/storage and things like that.

Thank you so much.
« Last Edit: July 30, 2019, 10:13:58 am by Weizen1988 »
Logged

ragundo

  • Bay Watcher
    • View Profile
Re: DFHACK lua script question. (Spawn nethercaps)
« Reply #3 on: July 30, 2019, 10:18:28 am »

I don't know why the script needs to use map_features[2] and not iterate over the vector. That's very suspicious to me.
Logged

Weizen1988

  • Bay Watcher
    • View Profile
Re: DFHACK lua script question. (Spawn nethercaps)
« Reply #4 on: July 30, 2019, 10:23:18 am »

I don't know why the script needs to use map_features[2] and not iterate over the vector. That's very suspicious to me.
I dont know enough about how any of this works to really answer that. All ive got is some old instructions from 2014 and no real understanding of lua or dwarf fortress coding in general. Is there some better method you know of to accomplish this? Alternately, can you explain why thats suspicious, or how to have it iterate over the vector, which, forgive me for being dumb, but i assume means it would add them to any allowable cavern level?
« Last Edit: July 30, 2019, 10:39:52 am by Weizen1988 »
Logged

ragundo

  • Bay Watcher
    • View Profile
Re: DFHACK lua script question. (Spawn nethercaps)
« Reply #5 on: July 30, 2019, 10:41:22 am »

I've no idea.
But providing that Quietust is the author of the script (he is one of the top dfhack gurus), may be he could clarify that for you.
Logged

Weizen1988

  • Bay Watcher
    • View Profile
Re: DFHACK lua script question. (Spawn nethercaps)
« Reply #6 on: July 30, 2019, 11:11:15 am »

Thank you, ive sent them a message, I didnt want to presume anyone from a post that long ago was still around, and thought it might have been weird to message them like that. If it doesnt work out its no big deal I suppose, the embark gave me nearly everything else I wanted, lacking a wood i intend to use for purely vanity projects is pretty minor.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHACK lua script question. (Spawn nethercaps)
« Reply #7 on: July 30, 2019, 07:26:58 pm »

I don't know why the script needs to use map_features[2] and not iterate over the vector. That's very suspicious to me.

That's addressed in the original thread:

Note that this assumes that the 3rd map feature in your embark is the 3rd cavern layer (e.g. if you type "feature list", then features 0-2 should all be "the cave" with type "subterranean_from_layer").

Also, Feature 0 is "candy deposit" so I assume I should raise the '2' in your script, or else I'll be inserting them into cavern level 2?
Unless you've modified your raws, the feature should be "raw adamantine deposit", but yes - if features #1, #2, and #3 are the caverns (subterranean_from_layer), then you'll want to use map_features[3].

That said, as long as feature 2 is some cavern, it should put nether-caps in that cavern. I don't know what will happen if feature 2 is something else.

Generally, resurrecting old threads for no reason is frowned upon, but this is a good reason to resurrect that thread. It would at least keep information together for anyone else who stumbles across the old thread.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Weizen1988

  • Bay Watcher
    • View Profile
Re: DFHACK lua script question. (Spawn nethercaps)
« Reply #8 on: August 01, 2019, 09:57:46 am »

Feature 2 was the correct feature in my case, id determined that much before posting. The modified version of the code did work, nethercap cups for all, assuming the baby trees will grow into adult ones after i chop some of the forest of bloodthorn down.
Logged