Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 130 131 [132] 133 134 ... 360

Author Topic: DFHack 0.43.03-r1  (Read 1083384 times)

Gorobay

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1965 on: January 22, 2015, 11:57:36 am »

How can I create a new entity in DFHack? When I try
Code: [Select]
df.global.world.entities.all:insert(0, {new=true, type=1, id=df.global.entity_next_id})DF crashes when saving the world. When I add
Code: [Select]
entity_raw=another_entity.entity_rawto the new entity, it saves, but DF crashes when gets to the "Loading civilized populations" part of loading the world.
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1966 on: January 22, 2015, 12:24:31 pm »

I think the request was some way to automatically hoover up on-load scripts that come with mods, so the player doesn't need to stitch them together manually.  This might simplify mod merging.

I'm picturing this as a standard bit in DFHack's onload script that runs every file in the raw/scripts folder that matches a specific filename pattern, maybe onload_*.lua|onload_*.rb.  It should be deterministically before or after the onload.init script at the root of raw.  Or put it in the raw/onload.init file, but I think the feature would be more user-proof if it functioned with the main file missing.

I'll add it to the list.

Is the goal to make it easier for homebrewed combinations of mods?

How can I create a new entity in DFHack? When I try
Code: [Select]
df.global.world.entities.all:insert(0, {new=true, type=1, id=df.global.entity_next_id})DF crashes when saving the world. When I add
Code: [Select]
entity_raw=another_entity.entity_rawto the new entity, it saves, but DF crashes when gets to the "Loading civilized populations" part of loading the world.

One problem is it looks like you aren't updating entity_next_id.

If I understand what you're doing then it probably can't be done. Certain things get read from raw files every time the game loads so it will almost definitely crash if it loads all the raw entities and then sees a reference to an entity that doesn't exist yet because it was created at runtime before it was saved. My guess is that the save code does some sort of check which catches this and crashes as a sanity check because it can't happen in vanilla DF.


Creating a new civilization/group should be possible but I think that's a different struct.

edit: Never mind. entity_raw is probably the one you can't create more of and making new entities is fine.
« Last Edit: January 22, 2015, 12:35:08 pm by expwnent »
Logged

Dirst

  • Bay Watcher
  • [EASILY_DISTRA
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1967 on: January 22, 2015, 12:47:11 pm »

I think the request was some way to automatically hoover up on-load scripts that come with mods, so the player doesn't need to stitch them together manually.  This might simplify mod merging.

I'm picturing this as a standard bit in DFHack's onload script that runs every file in the raw/scripts folder that matches a specific filename pattern, maybe onload_*.lua|onload_*.rb.  It should be deterministically before or after the onload.init script at the root of raw.  Or put it in the raw/onload.init file, but I think the feature would be more user-proof if it functioned with the main file missing.

I'll add it to the list.

Is the goal to make it easier for homebrewed combinations of mods?
A starter pack's mod manager could in principle merge the scripts together, so yes this would be aimed at players throwing random and/or homebrewed mods together.  But it would also make the mod manager's job easier.
Logged
Just got back, updating:
(0.42 & 0.43) The Earth Strikes Back! v2.15 - Pay attention...  It's a mine!  It's-a not yours!
(0.42 & 0.43) Appearance Tweaks v1.03 - Tease those hippies about their pointy ears.
(0.42 & 0.43) Accessibility Utility v1.04 - Console tools to navigate the map

Gorobay

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1968 on: January 22, 2015, 01:01:40 pm »

One problem is it looks like you aren't updating entity_next_id.
[...]
edit: Never mind. entity_raw is probably the one you can't create more of and making new entities is fine.
Now I do update df.global.entity_next_id, but it still has the same problem. I tried making a new population and adding its id to the new entity’s populations, but that didn’t work either.

Are there any scripts that successfully create entities that I can use as examples?
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1969 on: January 22, 2015, 01:34:21 pm »

I'm trying to add announcements and combat log text to my scripts, I looked through the API and found
Code: [Select]
dfhack.gui.makeAnnouncement(type,flags,pos,text,color[,is_bright])and
Code: [Select]
dfhack.gui.addCombatReport(unit,slot,report_index)
But I am unsure what the type, flags, and slot should all be for a given announcement (also pos?). Anyone have any examples or a list of what the valid entries are?

EDIT: Also
Code: [Select]
dfhack.run_script('unit/body-change -unit 3399 -temperature fire -all')Is not working, it says
Code: [Select]
C:\Users\Miles\Desktop\My_DF2\hack\lua\dfhack.lua:410: Could not find script uni
t/body-change -unit 3399 -temperature fire -all
stack traceback:
        [C]: in function 'error'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\dfhack.lua:410: in function 'run_
script'
        (interactive):1: in main chunk
        [C]: in function 'safecall'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\dfhack.lua:366: in function 'inte
rpreter'
        C:\Users\Miles\Desktop\My_DF2\hack\scripts/lua.lua:47: in main chunk
        (...tail calls...)
Note that putting that exact string into the command line works fine.

EDIT2: @Gorobay, I'm pretty sure its because you have a lot of fields that are left undefined if you just make a new one with type and id. Try instead
Code: [Select]
old = df.global.world.entities.all[0]
new = old:new()
new.id = entity_next_id
new.type = 1
blah
blah
blah
« Last Edit: January 22, 2015, 02:20:08 pm by Roses »
Logged

4kn

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1970 on: January 22, 2015, 02:32:10 pm »

excuse me for interrupting, but what about 40.24?
Logged

Dirst

  • Bay Watcher
  • [EASILY_DISTRA
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1971 on: January 22, 2015, 02:32:16 pm »

Roses, I found the Announcement command from Rubble (probably several versions old by now) that is much easier to use.

After all of the preparatory work is done building your string, it basically comes down to

dfhack.gui.showAnnouncement("Hello world!", _G["COLOR_RED"])

At the time I lifted the script, milo was manually echoing the announcement into the game's logfile, but the showAnnouncement method now seems to do that by itself.

Of course, this doesn't have as many ways to customize as the code you showed above.  For example, the snippet here has no location, so there's no way for the player to zoom to the location.

Edit: Here is the documentation for showAnnouncement and makeAnnouncement.  Probably just need to experiment with the flags or find a script somewhere that uses it.
« Last Edit: January 22, 2015, 02:37:39 pm by Dirst »
Logged
Just got back, updating:
(0.42 & 0.43) The Earth Strikes Back! v2.15 - Pay attention...  It's a mine!  It's-a not yours!
(0.42 & 0.43) Appearance Tweaks v1.03 - Tease those hippies about their pointy ears.
(0.42 & 0.43) Accessibility Utility v1.04 - Console tools to navigate the map

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1972 on: January 22, 2015, 03:14:30 pm »

I'm trying to add announcements and combat log text to my scripts, I looked through the API and found
Code: [Select]
dfhack.gui.makeAnnouncement(type,flags,pos,text,color[,is_bright])and
Code: [Select]
dfhack.gui.addCombatReport(unit,slot,report_index)
But I am unsure what the type, flags, and slot should all be for a given announcement (also pos?). Anyone have any examples or a list of what the valid entries are?

https://github.com/DFHack/df-structures/blob/master/df.announcements.xml

I think the request was some way to automatically hoover up on-load scripts that come with mods, so the player doesn't need to stitch them together manually.  This might simplify mod merging.

I'm picturing this as a standard bit in DFHack's onload script that runs every file in the raw/scripts folder that matches a specific filename pattern, maybe onload_*.lua|onload_*.rb.  It should be deterministically before or after the onload.init script at the root of raw.  Or put it in the raw/onload.init file, but I think the feature would be more user-proof if it functioned with the main file missing.

I'll add it to the list.

Is the goal to make it easier for homebrewed combinations of mods?

Well, personally, I'm doing it so that others can do that more easily. I ended up going with a dfhack.run_command in my init.d/fortbent.lua file:

Code: [Select]
dfhack.run_command('script',SAVE_PATH..'/raw/fortbent_onload.init')
« Last Edit: January 22, 2015, 03:16:37 pm by Putnam »
Logged

Gorobay

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1973 on: January 22, 2015, 03:16:25 pm »

EDIT2: @Gorobay, I'm pretty sure its because you have a lot of fields that are left undefined if you just make a new one with type and id.
I wrote the following script as a test:
Code: [Select]
local old = df.global.world.entities.all[0]
local new = old:new()
new.id = df.global.entity_next_id
new.type = 1
df.global.world.entities.all:insert('#', new)
The game crashes when I exit the current mode and offload the world.

I have found reading the source code helpful for determining what the GUI functions do. The slot parameter of addCombatReport must be 0, 1, or 2 for combat, hunting, or sparring.
Logged

IndigoFenix

  • Bay Watcher
  • All things die, but nothing dies forever.
    • View Profile
    • Boundworlds: A Browser-Based Multiverse Creation and Exploration Game
Re: DFHack 0.40.23-r1
« Reply #1974 on: January 22, 2015, 03:19:14 pm »

Is there any simple way of getting the products of a reaction that is linked to a LUA_HOOK function?  The example function includes output_items as a parameter, but as far as I can tell it is always empty

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1975 on: January 22, 2015, 03:34:09 pm »

Is there any simple way of getting the products of a reaction that is linked to a LUA_HOOK function?  The example function includes output_items as a parameter, but as far as I can tell it is always empty

reaction.products

code where I use it
Code: [Select]
function upgradeitem(reaction,unit,input_items,input_reagents,output_items,call_native)
local ptype = reaction.products[0].mat_type
local pindx = reaction.products[0].mat_index
local product = dfhack.matinfo.decode(ptype,pindx)
local args = {}
for i,x in ipairs(product.material.syndrome[0].syn_class) do
args[i] = x.value
end

local dur = 0
if #args == 2 then dur = tonumber(args[2]) end

local sitems = {}
if args[0] == 'this' then
-- Upgrade only the input items with preserve reagent
for i,x in ipairs(input_reagents) do
if x.flags.PRESERVE_REAGENT then sitems[i] = input_items[i] end
end
elseif args[0] == 'all' then
-- Upgrade all items of the same type as input
local itemList = df.global.world.items.all
local k = 1
for j,y in ipairs(input_reagents) do
if y.flags.PRESERVE_REAGENT then
for i,x in ipairs(itemList) do
if itemSubtypes(x) then
if x.subtype.id == y.subtype.id then
sitems[k] = itemList[i]
k = k + 1
end
end
end
end
end
else
-- Randomly upgrade one specific item
local itemList = df.global.world.items.all
local k = 1
for j,y in ipairs(input_reagents) do
if y.flags.PRESERVE_REAGENT then
for i,x in ipairs(itemList) do
if itemSubtypes(x) then
if x.subtype.id == y.subtype.id then
sitems[k] = itemList[i]
k = k + 1
end
end
end
end
end
local rando = dfhack.random.new()
sitems = {sitems[rando:random(#sitems)]}
end

if args[1] == 'upgrade' then
-- Increase items number by one
for _,x in ipairs(sitems) do
local name = x.subtype.id
if dur > 0 then sid = x.subtype.subtype end
local namea = split(name,'_')
local num = tonumber(namea[#namea])
num = num + 1
namea[#namea] = tostring(num)
name = table.concat(namea,'_')
item_index = itemSubtypes(x)
for i=0,dfhack.items.getSubtypeCount(item_index)-1,1 do
item_sub = dfhack.items.getSubtypeDef(item_index,i)
if item_sub.id == name then x:setSubtype(item_sub.subtype) end
end
if dur > 0 then dfhack.timeout(dur,'ticks',createcallback(x,sid)) end
end
elseif args[1] == 'downgrade' then
-- Decrease items number by one
for _,x in ipairs(sitems) do
local name = x.subtype.id
if dur > 0 then sid = x.subtype.subtype end
local namea = split(name,'_')
local num = tonumber(namea[#namea])
num = num - 1
if num > 0 then namea[#namea] = tostring(num) end
name = table.concat(namea,'_')
item_index = itemSubtypes(x)
for i=0,dfhack.items.getSubtypeCount(item_index)-1,1 do
item_sub = dfhack.items.getSubtypeDef(item_index,i)
if item_sub.id == name then x:setSubtype(item_sub.subtype) end
end
if dur > 0 then dfhack.timeout(dur,'ticks',createcallback(x,sid)) end
end
else
-- Change item to new item
for _,x in ipairs(sitems) do
if dur > 0 then sid = x.subtype.subtype end
item_index = itemSubtypes(x)
for i=0,dfhack.items.getSubtypeCount(item_index)-1,1 do
item_sub = dfhack.items.getSubtypeDef(item_index,i)
if item_sub.id == args[1] then x:setSubtype(item_sub.subtype) end
end
if dur > 0 then dfhack.timeout(dur,'ticks',createcallback(x,sid)) end
end
end
end

-- START Taken from hire-guard.lua
local eventful = require 'plugins.eventful'
local utils = require 'utils'

function string.starts(String,Start)
   return string.sub(String,1,string.len(Start))==Start
end

dfhack.onStateChange.loadUpgradeItem = function(code)
local registered_reactions
if code==SC_MAP_LOADED then
--registered_reactions = {}
for i,reaction in ipairs(df.global.world.raws.reactions) do
-- register each applicable reaction (to avoid doing string check
-- for every lua hook reaction (not just ours), this way uses identity check
if string.starts(reaction.code,'LUA_HOOK_UPGRADE_ITEM') then
-- register reaction.code
eventful.registerReaction(reaction.code,upgradeitem)
-- save reaction.code
--table.insert(registered_reactions,reaction.code)
registered_reactions = true
end
end
--if #registered_reactions > 0 then print('HireGuard: Loaded') end
if registered_reactions then print('Upgradable Items: Loaded') end
elseif code==SC_MAP_UNLOADED then
--[[ doesn't seem to be working, and probably not needed
registered_reactions = registered_reactions or {}
if #registered_reactions > 0 then print('HireGuard: Unloaded') end
for i,reaction in ipairs(registered_reactions) do
-- un register each registered reaction (to prevent persistance between
-- differing worlds (probably irrelavant, but doesn't hurt)
-- un register reaction.code
eventful.registerReaction(reaction.code,nil)
end
registered_reactions = nil -- clear registered_reactions
--]]
end
end

-- if dfhack.init has already been run, force it to think SC_WORLD_LOADED to that reactions get refreshed
if dfhack.isMapLoaded() then dfhack.onStateChange.loadUpgradeItem(SC_MAP_LOADED) end
-- END Taken from hire-guard.lua

EDIT2: @Gorobay, I'm pretty sure its because you have a lot of fields that are left undefined if you just make a new one with type and id.
I wrote the following script as a test:
Code: [Select]
local old = df.global.world.entities.all[0]
local new = old:new()
new.id = df.global.entity_next_id
new.type = 1
df.global.world.entities.all:insert('#', new)
The game crashes when I exit the current mode and offload the world.

I have found reading the source code helpful for determining what the GUI functions do. The slot parameter of addCombatReport must be 0, 1, or 2 for combat, hunting, or sparring.

You might also have to change the value of save_file_id. Also I'm not sure if its going to freak out over having duplicate events and such.
« Last Edit: January 22, 2015, 03:39:34 pm by Roses »
Logged

IndigoFenix

  • Bay Watcher
  • All things die, but nothing dies forever.
    • View Profile
    • Boundworlds: A Browser-Based Multiverse Creation and Exploration Game
Re: DFHack 0.40.23-r1
« Reply #1976 on: January 22, 2015, 04:04:25 pm »

Is there any simple way of getting the products of a reaction that is linked to a LUA_HOOK function?  The example function includes output_items as a parameter, but as far as I can tell it is always empty

reaction.products

Not that, that's the data from the reaction's object.  I want the actual items produced from the reaction.

I'm trying to make a function that runs after a particular reaction that produces a tool.  I want the function to run some script and then set the 'maker' field of the tool to a certain number based on that script.  How would I go about doing that?

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1977 on: January 22, 2015, 04:22:52 pm »

Is there any simple way of getting the products of a reaction that is linked to a LUA_HOOK function?  The example function includes output_items as a parameter, but as far as I can tell it is always empty

reaction.products

Not that, that's the data from the reaction's object.  I want the actual items produced from the reaction.

I'm trying to make a function that runs after a particular reaction that produces a tool.  I want the function to run some script and then set the 'maker' field of the tool to a certain number based on that script.  How would I go about doing that?

Ah, I see what you mean. I misunderstood. As far as I know output_items should be what you want. If it isn't then I am of no help.
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1978 on: January 22, 2015, 04:30:35 pm »

Code: [Select]
dfhack.run_script('unit/body-change -unit 3399 -temperature fire -all')Is not working, it says
Code: [Select]
C:\Users\Miles\Desktop\My_DF2\hack\lua\dfhack.lua:410: Could not find script uni
t/body-change -unit 3399 -temperature fire -all
stack traceback:
        [C]: in function 'error'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\dfhack.lua:410: in function 'run_
script'
        (interactive):1: in main chunk
        [C]: in function 'safecall'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\dfhack.lua:366: in function 'inte
rpreter'
        C:\Users\Miles\Desktop\My_DF2\hack\scripts/lua.lua:47: in main chunk
        (...tail calls...)
Note that putting that exact string into the command line works fine.


For now try run_command instead of run_script.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.40.23-r1
« Reply #1979 on: January 22, 2015, 04:52:10 pm »

Or you could do this instead:

dfhack.run_script('unit/body-change', '-unit', '3399', '-temperature', 'fire', '-all')
Pages: 1 ... 130 131 [132] 133 134 ... 360