v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Editing Utility:DFusion

Jump to navigation Jump to search

Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.


The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 167: Line 167:
 
This section explains in detail some of more complex things that could be done with dfusion.
 
This section explains in detail some of more complex things that could be done with dfusion.
  
Individual units can be modified - skills, jobs, attributes, etc. This example selects a unit under the look cursor, updates the name and updates the level and experience for selected skills.  
+
...TODO...
<pre>
 
--Takes a selected unit and instantly turns them into Morul - upgrading all appropriate skills to Legendary or higher, as appropriate
 
--By Martin, 5/25/2012, excerpt for demonstration purposes
 
--This code gets cut/pasted at the end of /dfusion/tools/init.lua
 
function tools.morul(unit)
 
  --include the utils library which we need later
 
  utils = require 'utils'
 
  --a unit address can be passed into this function, handle the case where one isn't
 
  if unit==nil then
 
    unit=getCreatureAtPointer()  --place the x pointer on top of the creature you want to change. best use is the look pointer 'k' and not 'v'
 
  end
 
  --Set the name. Surname is comprised of an array of references [words] into the language file. Each entry grabs a word fragment and the name is all of these catenated
 
  unit.name.first_name = "Morul"
 
  unit.name.words[0] = 1416  --[T_WORD:CHANNEL:catten]
 
  unit.name.words[1] = 1304  --[T_WORD:BEND:mat]
 
 
 
  --skill level we wish to apply to all labors. Dabbling is 0, Legendary is 15
 
  labor_rating = 15
 
  --the skill level we wish to apply to all military skills.
 
  military_rating = 70
 
 
 
  --These are the skill ids we want to add. The ids were identified in game_data.ini in DwarfTherapist.
 
  skill = { 0,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,41,42,43,44,45,46,47,48,49,54,55,57,58,59,60,61,62,63,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,95,96,97,98,99,100,101,102,103,104,105,109,110,111,112,113,114,115 }
 
  --These are the military skills that will get higher values. Subset of the list above.
 
  military = { 38,39,41,42,43,44,45,46,54,99,100,101,102,103,104,105 }
 
 
 
  --ipairs iterates over each indexed item in the skill list. Lua index is 1 based, so remember that.
 
  for sk,sv in ipairs(skill) do
 
    --assume the labor rating will apply
 
    new_rating = labor_rating
 
    --iterate over the military list
 
    for _,v in ipairs(military) do
 
      --if the value from the skill list iteration is in the military list...
 
      if v == sv then
 
        --then use the military skill level
 
        new_rating = military_rating
 
      end
 
    end
 
    --the skills need to be inserted in a particular way. This standard function passes the id, the skill level, and the experience value, and tells the tool to keep the skills sorted by id.
 
    --the experience calculation reflects the minimum experience to earn the level and allows skills to continue to advance.
 
    utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = sv, rating = new_rating, experience = (new_rating * 500) + (new_rating * (new_rating - 1)) * 50}, 'id')
 
  end
 
 
 
  -- walk over each of the skills we just set and print them out so we can confirm each update
 
  for sk,sv in ipairs(unit.status.current_soul.skills) do
 
    -- print the skill data. Printall will print entire tables and is handy at poking at the data structures
 
    printall(sv)
 
  end
 
end
 
 
 
--add the function above to the dfusion menu system as a submenu under the 'Tools' menu.
 
tools.menu:add("Morul",tools.morul)
 
</pre>
 
  
 
== Tips and Tricks ==
 
== Tips and Tricks ==
 
* To use dfusion's functionality in lua first run ''dfuse'' and then use run ''lua''
 
* To use dfusion's functionality in lua first run ''dfuse'' and then use run ''lua''
 
* You can bind keys to lua commands (in dfusion context) like this: ''keybindings add Shift-R "dfuse adv_tools.reincarnate()"''
 
* You can bind keys to lua commands (in dfusion context) like this: ''keybindings add Shift-R "dfuse adv_tools.reincarnate()"''

Please note that all contributions to Dwarf Fortress Wiki are considered to be released under the GFDL & MIT (see Dwarf Fortress Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)