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.

Lua script examples

From Dwarf Fortress Wiki
Jump to navigation Jump to search


Main article: Lua scripting

Snippets of vanilla generation can be found in Category:Lua script pages, and all vanilla scripts can be found in data/vanilla/vanilla_procedural/scripts/.

Helper functions[edit]

Search by reaction class[edit]

This script returns a table of all inorganic materials with a given [REACTION_CLASS]. The mat table also has reaction_product_class, which includes both [MATERIAL_REACTION_PRODUCT] and [ITEM_REACTION_PRODUCT] IDs.

Languages[edit]

Identity language[edit]

This makes a language called GEN_IDENTITY which is like: "Abbey abbeyabbeys the abbey of abbeys" - i.e. it's the "English" language you might see occasionally. It is present in vanilla_procedural and can be used for [TRANSLATION] by default.

Kobold language[edit]

This generates a language made of [UTTERANCES]. This is essentially a proper translation based on the kobold language. Note that the hardcoded utterance() function generates words independently of any existing words in the language, so you may get duplicate words.

Generators[edit]

Non-random generated material[edit]

Here's an example of an object registered through the do_once table. There are no random elements, it is equivalent (save for being [GENERATED]) to an object defined through Material definition tokens and registered through the raws.register_inorganics() function. It also prints itself to the lualog for debugging purposes.



You can register multiple objects at the same time. This script takes a table of color tokens, and makes a metal named after each of them, with a corresponding cheaty adventure reaction.

Random generation[edit]

Here's an example of various DF-specific randomizers in use:

  • trandom() is used to determine how many metals generate this way.
  • utterance() generates utterances from the Kobold language, e.g. "gorsnus", "stogodilmus", "gaylgis"
  • pick_random_no_replace() determines the color from the table, but removes the rolled value so there's no repeats.

New divine metals[edit]

Many of the tables used by vanilla procedural objects are global and thus can be added to or overwritten by mods. You can add new metal descriptions for divine metal pretty easily, for example:



You can also add alternatives to the default divine metal function, such as one based on the aforementioned kobold metals. Vanilla divine metal uses metal_by_sphere to determine its properties, and is thus valid only if the input sphere has an entry in that table. Note that even if the weights are nominally the same; because it is valid for all input spheres, it will outnumber instances of the more limited vanilla material.

Remove default functions[edit]

Just as easily as you can add new functions and table entries, you can overwrite default entries so that they cannot generate. This snippet removes the default forgotten beasts.

creatures.fb.default=nil


New forgotten beasts[edit]

You can add new types of forgotten beasts, generating as alternatives when populating the caverns with unique monsters. There are a number of options to interact with shared generation functions.

Unbidden spirits only appear in dry cave layers, and like "spirit" demons, are malevolent floating beings made of gas or dust.

Adamantine alloys[edit]

You can add your own arbitrary generated objects, though as of right now there's no way to make settings for them. This allows for some truly wild stuff; here's a fun example: adamantine-metal alloys for every single non-special metal, giving you an average of the properties of them.

CancelHideAbout

Rating Lua script examples