Bay 12 Games Forum

Please login or register.

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

Author Topic: DFHack 50.14-r1.1  (Read 892109 times)

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1965 on: November 25, 2019, 10:25:14 am »

dfhack-config/script-paths.txt is a more permanent place to set that up, if you prefer.
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.

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1966 on: November 25, 2019, 10:47:03 am »

Is it possible to add a new folder search location to DFHack so that it will looks for scripts in raw/blah/ in addition to raw/scripts/?
Yes: search for "addScriptPath" in https://dfhack.readthedocs.io/en/stable/docs/Lua%20API.html

dfhack-config/script-paths.txt is a more permanent place to set that up, if you prefer.

Thank you both!
Logged

doublestrafe

  • Bay Watcher
  • [PONY_DEPENDENT]
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1967 on: December 01, 2019, 03:58:52 pm »

I've got the formerly reanimated corpse of one of my dwarves being carried back and forth from a refuse stockpile in the kitchen to his tomb...which happens to be in the middle of the inn. For reasons. My still-alive dwarves don't seem to be super happy about it.

This is described in this bug, in which the reporter says:

Quote from: PatrikLundell
Using DFHack to change the "dead_dwarf" flag on the skeleton in a52's save causes the corpse to be laid to rest in the coffin...

I don't see anything in the DFHack documentation that explains how one would even begin to go about changing an arbitrary flag on an item. Can someone point me in the right direction please?
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1968 on: December 01, 2019, 05:00:17 pm »

Typing gui/gm-editor into console with the item selected in DF is one possible right direction.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1969 on: December 01, 2019, 06:24:59 pm »

As Fleeting Frames indicated, the comment skipped a fair number of "obvious" steps:
- gui/gm-editor is the typical tool to use, with is "obvious" to everyone hacking around, but not to those who just want to solve their problems.
- Once you start the tool with the right item (i.e. the corpse) selected, you have to navigate the data structure, which is reasonably easy to get used to. I don't have DF active at the moment, but there typically is one or more elements called flags (or some variation of that), and in one of these (going down a level and back up if it was the wrong set of flags) you'd find the flag you're looking at, and you can then flip it (boolean flags flip between true and false, which value fields bring up a box that allows you to select/type a new value).
Logged

doublestrafe

  • Bay Watcher
  • [PONY_DEPENDENT]
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1970 on: December 02, 2019, 01:03:04 am »

That's what I needed. Lokum has been laid to rest. Thanks!
Logged

Clément

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1971 on: December 03, 2019, 08:26:02 am »

I am trying to import df structures in ghidra, using codegen_c_hdr.pl from df_misc. But I have issues with nested types, for example: unitst.job use type unit_action::T_job instead of unitst::T_job, leading to invalid offsets. Has anyone successfully imported df structures into ghidra and how?
Logged

fortunawhisk

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1972 on: December 04, 2019, 11:11:06 pm »

Does anyone know what's required to force dwarves to take a bath? I'm trying to write a script that recreates the conditions on the dwarf that makes them decide to take a bath as their next job. Unfortunately, I can't seem to find whatever is required. It doesn't appear to be unit's bodypart grime number, spatter, spatter content, etc. I also tried just directly forcing them to do a "Clean Self" job, but that got really complicated by having to find well and soap stockpile coordinates.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1973 on: December 06, 2019, 01:28:13 pm »

Is it possible to add faux virtual methods to objects with lua. For instance if you have an item (say from item = df.item.find(#)) you can do item:getSubtype(), but I'd like to be able to be able to do something like item:getRandomAttack().

I have it working so far where I create a new metatable that has all the functions I want, but I can't seem to get inheritance to work for df structures. Below is a small excerpt of the ITEM metatable I am using at the moment (it's called by just doing item = ITEM(#))

Code: [Select]
ITEM = {}
ITEM.__index = ITEM
setmetatable(ITEM, {
__call = function (cls, ...)
local self = setmetatable({},cls)
self:_init(...)
return self
end,
})
function ITEM:_init(item)
if tonumber(item) then item = df.item.find(tonumber(item)) end
self.id = item.id
end

function ITEM:getRandomAttack()
local item = df.item.find(self.id)
local rand = dfhack.random.new()
local weights = {}
weights[0] = 0
local n = 0
for _,attacks in pairs(item.subtype.attacks) do
if attacks.edged then x = 100 else x = 1 end
n = n + 1
weights[n] = weights[n-1] + x
end
local pick = rand:random(weights[n])
for i = 1,n do
if pick >= weights[i-1] and pick < weights[i] then attack = i-1 break end
end
if not attack then attack = n end
return item.subtype.attacks[attack]
end
Logged

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1974 on: December 07, 2019, 04:00:53 am »

Is it possible to add faux virtual methods to objects with lua. For instance if you have an item (say from item = df.item.find(#)) you can do item:getSubtype(), but I'd like to be able to be able to do something like item:getRandomAttack().

I have it working so far where I create a new metatable that has all the functions I want, but I can't seem to get inheritance to work for df structures. Below is a small excerpt of the ITEM metatable I am using at the moment (it's called by just doing item = ITEM(#))
<...>

This seems to work, but i'm pretty sure there is still a better way:
Code: [Select]
ITEM = defclass(ITEM)
function ITEM:__index(key)
if rawget(self,key) then return rawget(self,key) end
if rawget(ITEM,key) then return rawget(ITEM,key) end
local item = df.item.find(self.id)
return item[key]
end
function ITEM:init(item)
--??
if tonumber(item) then item = df.item.find(tonumber(item)) end
self.id = item.id
end

function ITEM:getRandomAttack()
local item = df.item.find(self.id)
local rand = dfhack.random.new()
local weights = {}
weights[0] = 0
local n = 0
for _,attacks in pairs(item.subtype.attacks) do
if attacks.edged then x = 100 else x = 1 end
n = n + 1
weights[n] = weights[n-1] + x
end
local pick = rand:random(weights[n])
for i = 1,n do
if pick >= weights[i-1] and pick < weights[i] then attack = i-1 break end
end
if not attack then attack = n end
return item.subtype.attacks[attack]
end

local it=ITEM(0)
printall(it:getRandomAttack())

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1975 on: December 07, 2019, 08:36:59 pm »

well worked on a script on what if you could dodge farther distances which in turn became what if you can just dodge and attack in a way that kills the opponent setting you up to take on the next person.
 
Code: (Dodgeport.lua) [Select]
local D=df.global.world.units.active[0]
local Xi=df.global.cursor.x
local Yi=df.global.cursor.y
local Zi=df.global.cursor.z
for k,v in pairs(D.actions) do
if v.type == 1 then
v.data.attack.attack_velocity=910000009
v.data.attack.attack_accuracy=100
v.data.attack.timer1=1
v.data.attack.timer2=0
end
if v.type == 11 then
v.data.dodge.timer= 0
v.data.dodge.x2=Xi
v.data.dodge.y2=Yi
v.data.dodge.z2=Zi

end
end

the result turn out to be dodge teleporting next to someone doesn't give you your turn back and you're just placing yourself in position for an attack, also teleporting behind someone would lead to the person doing a 180 and hit you if they have an attack primed.
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1976 on: December 10, 2019, 01:22:34 pm »

Is it possible to add faux virtual methods to objects with lua. For instance if you have an item (say from item = df.item.find(#)) you can do item:getSubtype(), but I'd like to be able to be able to do something like item:getRandomAttack().

I have it working so far where I create a new metatable that has all the functions I want, but I can't seem to get inheritance to work for df structures. Below is a small excerpt of the ITEM metatable I am using at the moment (it's called by just doing item = ITEM(#))
<...>

This seems to work, but i'm pretty sure there is still a better way:

Thanks, this works perfectly. It's odd that I never got it to work, I swear I tried something similar, but I probably messed up the rawget().

well worked on a script on what if you could dodge farther distances which in turn became what if you can just dodge and attack in a way that kills the opponent setting you up to take on the next person.

<snip>

the result turn out to be dodge teleporting next to someone doesn't give you your turn back and you're just placing yourself in position for an attack, also teleporting behind someone would lead to the person doing a 180 and hit you if they have an attack primed.

Commenting on the 180 turn thing, I've found that once an attack is queued up with an action and everything has been calculated, nothing can stop it (short of modifying the action itself). I was even getting attacks to land when the attacker was many squares away from the target by teleporting right next to them, triggering the attack and then teleporting away, all in one tick. That *may* have been fixed though as the code I had that did that no longer seems to work 100% of the time, but it doesn't surprise me at all about the 180 degree turn.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1977 on: December 11, 2019, 12:44:06 am »

This seems to work, but i'm pretty sure there is still a better way:
Code: [Select]
ITEM = defclass(ITEM)
function ITEM:__index(key)
if rawget(self,key) then return rawget(self,key) end
if rawget(ITEM,key) then return rawget(ITEM,key) end
local item = df.item.find(self.id)
return item[key]
end
One suggestion to improve efficiency: set "self._item = df.item.find(id)" in the constructor (init()) and then look up fields on that in __index() (i.e. replace the last two lines with "return self._item[key]").
Of course, this will crash if the underlying item is ever deleted from DF, so be aware of that (I'm not sure what the use case is; if you're accessing item fields infrequently, then calling find() every time should be fine).
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.

methylatedspirit

  • Bay Watcher
  • it/its
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1978 on: December 11, 2019, 09:23:09 pm »

I'm trying to run DF 0.44.12 with DFhack on my phone using Exagear. It crashes whenever I try to load a world (Arena loads fine, though). It doesn't crash when I copy the installation to my computer, which probably means it's a problem with Exagear or something.

Spoiler: stderr.log (click to show/hide)

Spoiler: stdout.log (click to show/hide)


Unfortunately, I can't get the details.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r2
« Reply #1979 on: December 11, 2019, 10:15:49 pm »

This seems to work, but i'm pretty sure there is still a better way:
Code: [Select]
ITEM = defclass(ITEM)
function ITEM:__index(key)
if rawget(self,key) then return rawget(self,key) end
if rawget(ITEM,key) then return rawget(ITEM,key) end
local item = df.item.find(self.id)
return item[key]
end
One suggestion to improve efficiency: set "self._item = df.item.find(id)" in the constructor (init()) and then look up fields on that in __index() (i.e. replace the last two lines with "return self._item[key]").
Of course, this will crash if the underlying item is ever deleted from DF, so be aware of that (I'm not sure what the use case is; if you're accessing item fields infrequently, then calling find() every time should be fine).

The main use case is essentially to replace any dfhack.item.find() calls in my scripts with this class, which should allow me to do everything I am doing now, plus give me access to any extra functions and such I write. I will be doing this same thing for units, buildings, entities, etc... so that all of my scripts use the same base class, which should make it easier to update any scripts if information moves around as I will only have to update the class definition stuff.

I don't expect there to be frequent calls or for it to ever try and access a deleted item. But I will make sure to keep that in mind. Thank you
Logged
Pages: 1 ... 130 131 [132] 133 134 ... 244