Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DF-Hack script to save embark party - done ... sort of  (Read 2041 times)

SeelenJägerTee

  • Bay Watcher
    • View Profile
DF-Hack script to save embark party - done ... sort of
« on: August 16, 2014, 10:36:07 am »

Hello everyone.

Background info:
Spoiler (click to show/hide)
Basically what I want to do is copy the dwarfs on the embark screen to a file. Later load them from this file when in the embark screen.
If I'm not mistaken what would need to be done is go through the entire data structure of the embark-dwarves and copy all their relevant attributes into a file one by one. Or is it possible to write it all at once with something like write(df.world.....embarkDwarves[1]) to dump the whole content of this unit into the file? (Note: I'm totally aware that this syntax especially .embarkDwarves[1] is not correct)

I'm a dabbler in programming. I've basic knowledge about C++, R and python. However no formal education to speak of (I had one semester 2 hours per week bioinformatics, but there you learn only so much).
That said I don't really know DF-hack and I have NO CLUE about Lua so I'm gonna need some (extensive) help with this one.

save dwarf:
Code: [Select]
local file = io.open("SavedDwarves.txt", "w")
local table
for i = 1, 1, numberEmbarkDwarves do
     table = {["Dwarf No"] = i
                 ["caste"..i] = ...EmbarkDwarves[i].unit.caste   -- will this produce the string caste1, caste2 etc or have I misunderstood this?
                 ["sex"..i]    = ...EmbarkDwarves[i].unit.sex
                 -- etc.etc.
                 }
end

file.write(table) -- somehow write the table to file
file:close()

load dwarf:
Code: [Select]
local loadfile = io.open("SavedDwarves.txt", "r")
local table
file.read() -- somehow reconstruct table from file

for i = 1, 1, numberEmbarkDwarves do
       ...EmbarkDwarves[i].unit.caste = table["caste"..i]
       ...EmbarkDwarves[i].unit.sex    = table["sex"..i]
        -- etc.etc.
end

I guess the dwarves on embark screen are held in an array of size 7 (or larger when hacked), so it would be a matter of simply looping through it to get every dwarf. What's the syntax to access it?
Also how would i write the table to a file and restore it from there, preferably in a human readable format.
« Last Edit: August 25, 2014, 03:50:33 pm by SeelenJägerTee »
Logged

SeelenJägerTee

  • Bay Watcher
    • View Profile
Re: DF-Hack script to save embark party - how to?
« Reply #1 on: August 25, 2014, 03:49:54 pm »

It is done. Yay I'm M45ta scriptkiddy5000 !!!!!111!!einself
*clears throat*
Sorry I got a little carried away with this.

I dug into lua and it is now done.
Sort of at least.
While I wanted to be able to run this script on the embark screen and save/load all 7 dwarfs I couldn't figure out how to access them.
Now you have to select the dwarves after embark and call the script on every one of them separately.

Right now the script copies. Attributes (mental and body) and traits. It does NOT copy values, gender, preferences, body-size ...

Also I don't really get how the cultural values work. As the vector only has very few entries compared to existing values. If someone has insight into this please enlighten me.

Usage is explained by running
copyDwarf info
in the DFhack console.

copyDwarf.lua
Code: [Select]
-- By SeelenJägerTee
-- Published under the MIT License (http://opensource.org/licenses/MIT)

-- THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
-- BY USING THE CODE YOU IMPLICITLY STATE, THAT YOU HAVE SEEN AND UNDERSTOOD
-- THE CODE AND HAVE CORRECTED ANY ERRORS IT MAY CONTAIN.

local sepTab = false -- change separator between "\t" and "\t = " -- sepTab = true currently broken, no clue why
local theUnit=dfhack.gui.getSelectedUnit()
local params = {...}

local i = "default"
i = params[2]

if theUnit == nil then
print("error no unit selected")
return;
end

--ENUMS
local STRENGTH = 0
local AGILITY = 1
local TOUGHNESS = 2
local ENDURANCE = 3
local RECUPERATION = 4
local DISEASE_RESISTANCE = 5

local ANALYTICAL_ABILITY = 0
local FOCUS = 1
local WILLPOWER = 2
local CREATIVITY = 3
local INTUITION = 4
local PATIENCE = 5
local MEMORY = 6
local LINGUISTIC_ABILITY = 7
local SPATIAL_SENSE = 8
local MUSICALITY = 9
local KINESTHETIC_SENSE  = 10
local EMPATHY = 11
local SOCIAL_AWARENESS = 12

local LOVE_PROPENSITY = 0
local HATE_PROPENSITY = 1
local ENVY_PROPENSITY = 2
local CHEER_PROPENSITY = 3
local DEPRESSION_PROPENSITY = 4
local ANGER_PROPENSITY = 5
local ANXIETY_PROPENSITY = 6
local LUST_PROPENSITY = 7
local STRESS_VULNERABILITY = 8
local GREED = 9
local IMMODERATION = 10
local VIOLENT = 11
local PERSEVERENCE = 12
local WASTEFULNESS = 13
local DISCORD = 14
local FRIENDLINESS = 15
local POLITENESS = 16
local DISDAIN_ADVICE = 17
local BRAVERY = 18
local CONFIDENCE = 19
local VANITY = 20
local AMBITION = 21
local GRATITUDE = 22
local IMMODESTY = 23
local HUMOR = 24
local VENGEFUL = 25
local PRIDE = 26
local CRUELTY = 27
local SINGLEMINDED = 28
local HOPEFUL = 29
local CURIOUS = 30
local BASHFUL = 31
local PRIVACY = 32
local PERFECTIONIST = 33
local CLOSEMINDED = 34
local TOLERANT = 35
local EMOTIONALLY_OBSESSIVE = 36
local SWAYED_BY_EMOTIONS = 37
local ALTRUISM = 38
local DUTIFULNESS = 39
local THOUGHTLESSNESS = 40
local ORDERLINESS = 41
local TRUST = 42
local GREGARIOUSNESS = 43
local ASSERTIVENESS = 44
local ACTIVITY_LEVEL = 45
local EXCITEMENT_SEEKING = 46
local IMAGINATION = 47
local ABSTRACT_INCLINED = 48
local ART_INCLINED = 49




function SaveToFile()
local file = io.open("hack\\scripts\\SavedDwarves\\SavedDwarves_"..i..".txt", "w")

local table = { --["caste"..i] = theUnit.caste, -- I disabled sex and caste, as some descriptions are not updated properly.
--["sex"..i] = theUnit.sex, -- I have no clue what else doesn't get updated. Want to avoid pregnant males and such things.
["strength"..i] = theUnit.body.physical_attrs[STRENGTH].value,
["agility"..i] = theUnit.body.physical_attrs[AGILITY].value,
["toughness"..i] = theUnit.body.physical_attrs[TOUGHNESS].value,
["endurance"..i] = theUnit.body.physical_attrs[ENDURANCE].value,
["recuperation"..i] = theUnit.body.physical_attrs[RECUPERATION].value,
["disease_resistance"..i] = theUnit.body.physical_attrs[DISEASE_RESISTANCE].value,

["max_strength"..i] = theUnit.body.physical_attrs[STRENGTH].max_value,
["max_agility"..i] = theUnit.body.physical_attrs[AGILITY].max_value,
["max_toughness"..i] = theUnit.body.physical_attrs[TOUGHNESS].max_value,
["max_endurance"..i] = theUnit.body.physical_attrs[ENDURANCE].max_value,
["max_recuperation"..i] = theUnit.body.physical_attrs[RECUPERATION].max_value,
["max_disease_resist"..i] = theUnit.body.physical_attrs[DISEASE_RESISTANCE].max_value,

["analytical_ability"..i] = theUnit.status.current_soul.mental_attrs[ANALYTICAL_ABILITY].value,
["focus"..i] = theUnit.status.current_soul.mental_attrs[FOCUS].value,
["willpower"..i] = theUnit.status.current_soul.mental_attrs[WILLPOWER].value,
["creativity"..i] = theUnit.status.current_soul.mental_attrs[CREATIVITY].value,
["intuition"..i] = theUnit.status.current_soul.mental_attrs[INTUITION].value,
["patience"..i] = theUnit.status.current_soul.mental_attrs[PATIENCE].value,
["memory"..i] = theUnit.status.current_soul.mental_attrs[MEMORY].value,
["linguisitc_ability"..i] = theUnit.status.current_soul.mental_attrs[LINGUISTIC_ABILITY].value,
["spatial_sense"..i] = theUnit.status.current_soul.mental_attrs[SPATIAL_SENSE].value,
["musicality"..i] = theUnit.status.current_soul.mental_attrs[MUSICALITY].value,
["kinesthetic_sense" ..i] = theUnit.status.current_soul.mental_attrs[KINESTHETIC_SENSE].value,
["empathy"..i] = theUnit.status.current_soul.mental_attrs[EMPATHY].value,
["social_awareness"..i] = theUnit.status.current_soul.mental_attrs[SOCIAL_AWARENESS].value,

["max_analytical_ability"..i] = theUnit.status.current_soul.mental_attrs[ANALYTICAL_ABILITY].max_value,
["max_focus"..i] = theUnit.status.current_soul.mental_attrs[FOCUS].max_value,
["max_willpower"..i] = theUnit.status.current_soul.mental_attrs[WILLPOWER].max_value,
["max_creativity"..i] = theUnit.status.current_soul.mental_attrs[CREATIVITY].max_value,
["max_intuition"..i] = theUnit.status.current_soul.mental_attrs[INTUITION].max_value,
["max_patience"..i] = theUnit.status.current_soul.mental_attrs[PATIENCE].max_value,
["max_memory"..i] = theUnit.status.current_soul.mental_attrs[MEMORY].max_value,
["max_linguisitc_ability"..i] = theUnit.status.current_soul.mental_attrs[LINGUISTIC_ABILITY].max_value,
["max_spatial_sense"..i] = theUnit.status.current_soul.mental_attrs[SPATIAL_SENSE].max_value,
["max_musicality"..i] = theUnit.status.current_soul.mental_attrs[MUSICALITY].max_value,
["max_kinesthetic_sense" ..i] = theUnit.status.current_soul.mental_attrs[KINESTHETIC_SENSE].max_value,
["max_empathy"..i] = theUnit.status.current_soul.mental_attrs[EMPATHY].max_value,
["max_social_awareness"..i] = theUnit.status.current_soul.mental_attrs[SOCIAL_AWARENESS].max_value,

["LOVE_PROPENSITY"..i] = theUnit.status.current_soul.personality.traits[LOVE_PROPENSITY],
["HATE_PROPENSITY"..i] = theUnit.status.current_soul.personality.traits[HATE_PROPENSITY],
["ENVY_PROPENSITY"..i] = theUnit.status.current_soul.personality.traits[ENVY_PROPENSITY],
["CHEER_PROPENSITY"..i] = theUnit.status.current_soul.personality.traits[CHEER_PROPENSITY],
["DEPRESSION_PROPENSITY"..i] = theUnit.status.current_soul.personality.traits[DEPRESSION_PROPENSITY ],
["ANGER_PROPENSITY"..i] = theUnit.status.current_soul.personality.traits[ANGER_PROPENSITY],
["ANXIETY_PROPENSITY"..i] = theUnit.status.current_soul.personality.traits[ANXIETY_PROPENSITY],
["LUST_PROPENSITY"..i] = theUnit.status.current_soul.personality.traits[LUST_PROPENSITY],
["STRESS_VULNERABILITY"..i] = theUnit.status.current_soul.personality.traits[STRESS_VULNERABILITY],
["GREED"..i] = theUnit.status.current_soul.personality.traits[GREED],
["IMMODERATION"..i] = theUnit.status.current_soul.personality.traits[IMMODERATION],
["VIOLENT"..i] = theUnit.status.current_soul.personality.traits[VIOLENT],
["PERSEVERENCE"..i] = theUnit.status.current_soul.personality.traits[PERSEVERENCE],
["WASTEFULNESS"..i] = theUnit.status.current_soul.personality.traits[WASTEFULNESS],
["DISCORD"..i] = theUnit.status.current_soul.personality.traits[DISCORD],
["FRIENDLINESS"..i] = theUnit.status.current_soul.personality.traits[FRIENDLINESS],
["POLITENESS"..i] = theUnit.status.current_soul.personality.traits[POLITENESS],
["DISDAIN_ADVICE"..i] = theUnit.status.current_soul.personality.traits[DISDAIN_ADVICE],
["BRAVERY"..i] = theUnit.status.current_soul.personality.traits[BRAVERY],
["CONFIDENCE"..i] = theUnit.status.current_soul.personality.traits[CONFIDENCE],
["VANITY"..i] = theUnit.status.current_soul.personality.traits[VANITY],
["AMBITION"..i] = theUnit.status.current_soul.personality.traits[AMBITION],
["GRATITUDE"..i] = theUnit.status.current_soul.personality.traits[GRATITUDE],
["IMMODESTY"..i] = theUnit.status.current_soul.personality.traits[IMMODESTY],
["HUMOR"..i] = theUnit.status.current_soul.personality.traits[HUMOR],
["VENGEFUL"..i] = theUnit.status.current_soul.personality.traits[VENGEFUL],
["PRIDE"..i] = theUnit.status.current_soul.personality.traits[PRIDE],
["CRUELTY"..i] = theUnit.status.current_soul.personality.traits[CRUELTY],
["SINGLEMINDED"..i] = theUnit.status.current_soul.personality.traits[SINGLEMINDED],
["HOPEFUL"..i] = theUnit.status.current_soul.personality.traits[HOPEFUL],
["CURIOUS"..i] = theUnit.status.current_soul.personality.traits[CURIOUS],
["BASHFUL"..i] = theUnit.status.current_soul.personality.traits[BASHFUL],
["PRIVACY"..i] = theUnit.status.current_soul.personality.traits[PRIVACY],
["PERFECTIONIST"..i] = theUnit.status.current_soul.personality.traits[PERFECTIONIST],
["CLOSEMINDED"..i] = theUnit.status.current_soul.personality.traits[CLOSEMINDED],
["TOLERANT"..i] = theUnit.status.current_soul.personality.traits[TOLERANT],
["EMOTIONALLY_OBSESSIVE"..i] = theUnit.status.current_soul.personality.traits[EMOTIONALLY_OBSESSIVE],
["SWAYED_BY_EMOTIONS"..i] = theUnit.status.current_soul.personality.traits[SWAYED_BY_EMOTIONS],
["ALTRUISM"..i] = theUnit.status.current_soul.personality.traits[ALTRUISM],
["DUTIFULNESS"..i] = theUnit.status.current_soul.personality.traits[DUTIFULNESS],
["THOUGHTLESSNESS"..i] = theUnit.status.current_soul.personality.traits[THOUGHTLESSNESS],
["ORDERLINESS"..i] = theUnit.status.current_soul.personality.traits[ORDERLINESS],
["TRUST"..i] = theUnit.status.current_soul.personality.traits[TRUST],
["GREGARIOUSNESS"..i] = theUnit.status.current_soul.personality.traits[GREGARIOUSNESS],
["ASSERTIVENESS"..i] = theUnit.status.current_soul.personality.traits[ASSERTIVENESS],
["ACTIVITY_LEVEL"..i] = theUnit.status.current_soul.personality.traits[ACTIVITY_LEVEL],
["EXCITEMENT_SEEKING"..i] = theUnit.status.current_soul.personality.traits[EXCITEMENT_SEEKING],
["IMAGINATION"..i] = theUnit.status.current_soul.personality.traits[IMAGINATION],
["ABSTRACT_INCLINED"..i] = theUnit.status.current_soul.personality.traits[ABSTRACT_INCLINED],
["ART_INCLINED"..i] = theUnit.status.current_soul.personality.traits[ART_INCLINED]

      }

for key,value in pairs(table) do print(key,value) end -- print out the table in console for control reasons

for key, value in pairs(table) do
if sepTab == true then
file:write(key.."\t"..value.."\n")
else
file:write(key.."\t= "..value.."\n")
end
end

file:close()
end

function ReadFromFile()
local readfile = assert(io.open("hack\\scripts\\SavedDwarves\\SavedDwarves_"..i..".txt", "r")) -- crash script with assertion if file not found

local buftable = {} -- buffer table, which gets filled with loaded data
while true do
local line = readfile:read("*line")
if line == nil then
break
end
if sepTab == true then
local key, value = line:match('([%w_]+)%s+(.*)')
else
local key, value = line:match('([%w_]+)%s*=%s*(.*)')

buftable[key] = value
readfile.close() -- file can be closed here as scipt crashed if not open
end
end

print("\n\n")
for key,value in pairs(buftable) do print(key,value) end -- print out the table in console for control reasons

-- theUnit.caste = buftable["caste"..i] -- as noted under the write function disabled
-- theUnit.sex = buftable["sex"..i] -- due to unknown behaviour
theUnit.body.physical_attrs[STRENGTH].value = buftable["strength"..i]
theUnit.body.physical_attrs[AGILITY].value = buftable["agility"..i]
theUnit.body.physical_attrs[TOUGHNESS].value = buftable["toughness"..i]
theUnit.body.physical_attrs[ENDURANCE].value = buftable["endurance"..i]
theUnit.body.physical_attrs[RECUPERATION].value = buftable["recuperation"..i]
theUnit.body.physical_attrs[DISEASE_RESISTANCE].value = buftable["disease_resistance"..i]

theUnit.body.physical_attrs[STRENGTH].max_value = buftable["max_strength"..i]
theUnit.body.physical_attrs[AGILITY].max_value = buftable["max_agility"..i]
theUnit.body.physical_attrs[TOUGHNESS].max_value = buftable["max_toughness"..i]
theUnit.body.physical_attrs[ENDURANCE].max_value = buftable["max_endurance"..i]
theUnit.body.physical_attrs[RECUPERATION].max_value = buftable["max_recuperation"..i]
theUnit.body.physical_attrs[DISEASE_RESISTANCE].max_value = buftable["max_disease_resist"..i]

theUnit.status.current_soul.mental_attrs[ANALYTICAL_ABILITY].value = buftable["analytical_ability"..i]
theUnit.status.current_soul.mental_attrs[FOCUS].value = buftable["focus"..i]
theUnit.status.current_soul.mental_attrs[WILLPOWER].value = buftable["willpower"..i]
theUnit.status.current_soul.mental_attrs[CREATIVITY].value = buftable["creativity"..i]
theUnit.status.current_soul.mental_attrs[INTUITION].value = buftable["intuition"..i]
theUnit.status.current_soul.mental_attrs[PATIENCE].value = buftable["patience"..i]
theUnit.status.current_soul.mental_attrs[MEMORY].value = buftable["memory"..i]
theUnit.status.current_soul.mental_attrs[LINGUISTIC_ABILITY].value = buftable["linguisitc_ability"..i]
theUnit.status.current_soul.mental_attrs[SPATIAL_SENSE].value = buftable["spatial_sense"..i]
theUnit.status.current_soul.mental_attrs[MUSICALITY].value = buftable["musicality"..i]
theUnit.status.current_soul.mental_attrs[KINESTHETIC_SENSE].value = buftable["kinesthetic_sense" ..i]
theUnit.status.current_soul.mental_attrs[EMPATHY].value = buftable["empathy"..i]
theUnit.status.current_soul.mental_attrs[SOCIAL_AWARENESS].value = buftable["social_awareness"..i]

theUnit.status.current_soul.mental_attrs[ANALYTICAL_ABILITY].max_value = buftable["max_analytical_ability"..i]
theUnit.status.current_soul.mental_attrs[FOCUS].max_value = buftable["max_focus"..i]
theUnit.status.current_soul.mental_attrs[WILLPOWER].max_value = buftable["max_willpower"..i]
theUnit.status.current_soul.mental_attrs[CREATIVITY].max_value = buftable["max_creativity"..i]
theUnit.status.current_soul.mental_attrs[INTUITION].max_value = buftable["max_intuition"..i]
theUnit.status.current_soul.mental_attrs[PATIENCE].max_value = buftable["max_patience"..i]
theUnit.status.current_soul.mental_attrs[MEMORY].max_value = buftable["max_memory"..i]
theUnit.status.current_soul.mental_attrs[LINGUISTIC_ABILITY].max_value = buftable["max_linguisitc_ability"..i]
theUnit.status.current_soul.mental_attrs[SPATIAL_SENSE].max_value = buftable["max_spatial_sense"..i]
theUnit.status.current_soul.mental_attrs[MUSICALITY].max_value = buftable["max_musicality"..i]
theUnit.status.current_soul.mental_attrs[KINESTHETIC_SENSE].max_value = buftable["max_kinesthetic_sense" ..i]
theUnit.status.current_soul.mental_attrs[EMPATHY].max_value = buftable["max_empathy"..i]
theUnit.status.current_soul.mental_attrs[SOCIAL_AWARENESS].max_value = buftable["max_social_awareness"..i]

theUnit.status.current_soul.personality.traits[LOVE_PROPENSITY] = buftable["LOVE_PROPENSITY"..i]
theUnit.status.current_soul.personality.traits[HATE_PROPENSITY] = buftable["HATE_PROPENSITY"..i]
theUnit.status.current_soul.personality.traits[ENVY_PROPENSITY] = buftable["ENVY_PROPENSITY"..i]
theUnit.status.current_soul.personality.traits[CHEER_PROPENSITY] = buftable["CHEER_PROPENSITY"..i]
theUnit.status.current_soul.personality.traits[DEPRESSION_PROPENSITY] = buftable["DEPRESSION_PROPENSITY"..i]
theUnit.status.current_soul.personality.traits[ANGER_PROPENSITY] = buftable["ANGER_PROPENSITY"..i]
theUnit.status.current_soul.personality.traits[ANXIETY_PROPENSITY] = buftable["ANXIETY_PROPENSITY"..i]
theUnit.status.current_soul.personality.traits[LUST_PROPENSITY] = buftable["LUST_PROPENSITY"..i]
theUnit.status.current_soul.personality.traits[STRESS_VULNERABILITY] = buftable["STRESS_VULNERABILITY"..i]
theUnit.status.current_soul.personality.traits[GREED] = buftable["GREED"..i]
theUnit.status.current_soul.personality.traits[IMMODERATION] = buftable["IMMODERATION"..i]
theUnit.status.current_soul.personality.traits[VIOLENT] = buftable["VIOLENT"..i]
theUnit.status.current_soul.personality.traits[PERSEVERENCE] = buftable["PERSEVERENCE"..i]
theUnit.status.current_soul.personality.traits[WASTEFULNESS] = buftable["WASTEFULNESS"..i]
theUnit.status.current_soul.personality.traits[DISCORD] = buftable["DISCORD"..i]
theUnit.status.current_soul.personality.traits[FRIENDLINESS] = buftable["FRIENDLINESS"..i]
theUnit.status.current_soul.personality.traits[POLITENESS] = buftable["POLITENESS"..i]
theUnit.status.current_soul.personality.traits[DISDAIN_ADVICE] = buftable["DISDAIN_ADVICE"..i]
theUnit.status.current_soul.personality.traits[BRAVERY] = buftable["BRAVERY"..i]
theUnit.status.current_soul.personality.traits[CONFIDENCE] = buftable["CONFIDENCE"..i]
theUnit.status.current_soul.personality.traits[VANITY] = buftable["VANITY"..i]
theUnit.status.current_soul.personality.traits[AMBITION] = buftable["AMBITION"..i]
theUnit.status.current_soul.personality.traits[GRATITUDE] = buftable["GRATITUDE"..i]
theUnit.status.current_soul.personality.traits[IMMODESTY] = buftable["IMMODESTY"..i]
theUnit.status.current_soul.personality.traits[HUMOR] = buftable["HUMOR"..i]
theUnit.status.current_soul.personality.traits[VENGEFUL] = buftable["VENGEFUL"..i]
theUnit.status.current_soul.personality.traits[PRIDE] = buftable["PRIDE"..i]
theUnit.status.current_soul.personality.traits[CRUELTY] = buftable["CRUELTY"..i]
theUnit.status.current_soul.personality.traits[SINGLEMINDED] = buftable["SINGLEMINDED"..i]
theUnit.status.current_soul.personality.traits[HOPEFUL] = buftable["HOPEFUL"..i]
theUnit.status.current_soul.personality.traits[CURIOUS] = buftable["CURIOUS"..i]
theUnit.status.current_soul.personality.traits[BASHFUL] = buftable["BASHFUL"..i]
theUnit.status.current_soul.personality.traits[PRIVACY] = buftable["PRIVACY"..i]
theUnit.status.current_soul.personality.traits[PERFECTIONIST] = buftable["PERFECTIONIST"..i]
theUnit.status.current_soul.personality.traits[CLOSEMINDED] = buftable["CLOSEMINDED"..i]
theUnit.status.current_soul.personality.traits[TOLERANT] = buftable["TOLERANT"..i]
theUnit.status.current_soul.personality.traits[EMOTIONALLY_OBSESSIVE] = buftable["EMOTIONALLY_OBSESSIVE"..i]
theUnit.status.current_soul.personality.traits[SWAYED_BY_EMOTIONS] = buftable["SWAYED_BY_EMOTIONS"..i]
theUnit.status.current_soul.personality.traits[ALTRUISM] = buftable["ALTRUISM"..i]
theUnit.status.current_soul.personality.traits[DUTIFULNESS] = buftable["DUTIFULNESS"..i]
theUnit.status.current_soul.personality.traits[THOUGHTLESSNESS] = buftable["THOUGHTLESSNESS"..i]
theUnit.status.current_soul.personality.traits[ORDERLINESS] = buftable["ORDERLINESS"..i]
theUnit.status.current_soul.personality.traits[TRUST] = buftable["TRUST"..i]
theUnit.status.current_soul.personality.traits[GREGARIOUSNESS] = buftable["GREGARIOUSNESS"..i]
theUnit.status.current_soul.personality.traits[ASSERTIVENESS] = buftable["ASSERTIVENESS"..i]
theUnit.status.current_soul.personality.traits[ACTIVITY_LEVEL] = buftable["ACTIVITY_LEVEL"..i]
theUnit.status.current_soul.personality.traits[EXCITEMENT_SEEKING] = buftable["EXCITEMENT_SEEKING"..i]
theUnit.status.current_soul.personality.traits[IMAGINATION] = buftable["IMAGINATION"..i]
theUnit.status.current_soul.personality.traits[ABSTRACT_INCLINED] = buftable["ABSTRACT_INCLINED"..i]
theUnit.status.current_soul.personality.traits[ART_INCLINED] = buftable["ART_INCLINED"..i]


end


if params[1] == "save" then
SaveToFile()
elseif params[1] == "load" then
ReadFromFile()
elseif params[1] == "info" then
print("This script can be used to save dwarves and to load them later on. As of writing this line it can save and restore the attributes and traits of a dwarf. The script takes 2 parameters. The first parameter can be save or load or info. The second parameter is an identifier for the savefile and can be omitted when the first parameter is info. Typing copyDwarf save foo will save the currently selected dwarf in SavedDwarves_foo.txt. copyDwarf load bar5 will impose the values saved in SavedDwarves_bar5.txt onto the currently selected dwarf.")
else
print("For info on the script call it with copyDwarf info.\nTo use script call it with copyDwarf param1 param2. param1 needs to be save load or info. param2 is identifier of save-file.\nMAKE SURE YOU UNDERSTAND THIS SCRIPT BEFORE USING.")
end
Logged

Euius

  • Bay Watcher
    • View Profile
Re: DF-Hack script to save embark party - done ... sort of
« Reply #2 on: August 25, 2014, 04:46:55 pm »

Quote
While I wanted to be able to run this script on the embark screen and save/load all 7 dwarfs I couldn't figure out how to access them.

Pre-embark, the 7 dwarves are available in df.global.world.units.active

They're in the same table post-embark as well, but pre-embark it should be just those seven.
Logged

SeelenJägerTee

  • Bay Watcher
    • View Profile
Re: DF-Hack script to save embark party - done ... sort of
« Reply #3 on: August 25, 2014, 08:46:09 pm »

Ah, thanks for sharing that info.
So at embark screen it is populated only by 7 entries, that I could iterate over with ...active[0] to ...active[6]?
Logged

Nopenope

  • Bay Watcher
    • View Profile
Re: DF-Hack script to save embark party - done ... sort of
« Reply #4 on: August 26, 2014, 02:24:04 am »

Pretty sure Lua iterates from 1.
Logged

SeelenJägerTee

  • Bay Watcher
    • View Profile
Re: DF-Hack script to save embark party - done ... sort of
« Reply #5 on: August 26, 2014, 08:50:45 am »

Pretty sure Lua iterates from 1.
It does.
Nonetheless
Code: [Select]
theUnit.body.physical_attrs[1].value,should be Strength, because strength in DF is ...physical_attrs[0]. DF is written in C++ so it iterates from 0, however I'm using lua right now so I have to use ...physical_attrs[1] to access strength.
Well it isn't ...physical_attrs[1] in the lua script accesses AGILITY which is ...physical_attrs[0] in DFs C++.
This surprised me totally.
Logged

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: DF-Hack script to save embark party - done ... sort of
« Reply #6 on: August 26, 2014, 08:55:44 am »

Also there are enums for all of this stuff. E.g. "df.physical_attribute[0]" or "df.physical_attribute.STRENGTH" (i might be wrong, can't check now...)

Also the difference of starting from 0 and 1 was chosen to have EXACTLY the same indexing in df structures as it really is in reality.

Abadrausar

  • Bay Watcher
  • empowering ideas
    • View Profile
    • ♫♪♀HDFPS♂♪♫
Re: DF-Hack script to save embark party - done ... sort of
« Reply #7 on: September 18, 2014, 11:09:43 am »

This could be done in lua with dfhack support, but it would be a pity not reusing all or at least one part of the code that already does the same thing well in dwarf therapist.

As of now dwarf therapists is able to find the dwarves that are the best match to perform optimally every task of a predetermined list of roles taking into account his skills, attributes and preferences.

So every embark party list should be coupled with the corresponding Dwarf therapist optimization adapted for the 7 dwarfs of the embark.

Then the only missing piece would be the reordering of the skills to the dwarves selected by the optimization.  ;)
Logged
::: Humble Dwarf Fortress Publishing System ♫♪♀HDFPS♂♪♫ Mods Push Published in DFFD are auto updated in local Players Catalog :::