Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 24

Author Topic: Roses' Script, System, and Utilities Collection (07/06/2021)  (Read 87415 times)

Roses

  • Bay Watcher
    • View Profile
Roses' Script, System, and Utilities Collection (07/06/2021)
« on: August 24, 2015, 08:39:56 am »

https://github.com/Pheosics/roses_collection
Use the master branch for the most recent stable version, and the devel branch for the most recent developments

UPDATE 07/06/2021
Fixed the {ATTRIBUTE} and {SKILL} shortcuts for the enhanced items. Now the attributes/skills are correctly increased/decreased when the item is equipped/unequipped

What is it
This is a collection of scripts, systems, and utilities that can be used with DFHack to modify the DF experience. The two main folders are Scripts (which include scripts and systems) and Utilities. All Utilities are built with Python 3+ and are run outside of the game. The scripts and systems are lua files that are run through DFHack. Scripts are run just like any other DFHack script and can be called from the command line or through any other method used to call the base DFHack scripts. Each script contains a help message which can be accessed by using script-name -help. The systems are called automatically behind the scenes and gather information through the raws (or in the case where there are no corresponding raws, such as the Class System, it uses a fake raw file).

Design philosophy
As many of you know, I have been around on this forum for awhile (over 11 years) and have created many scripts. Unfortunately they often became unusably complex as I added more and more to each script while still trying to maintain each scripts individuality. It eventually got to the point where even I had trouble running my own scripts and so I decided that a fresh start was needed. Instead of trying to make each script a stand alone download I have created a set of functions which act as the powerhouse behind the whole thing. These functions are made available through custom classes where appropriate, and through simple calls otherwise. Since each function serves a specific purpose they are relatively small and their use is shared across many different scripts. Additionally they can be called by other modders scripts if desired. Each script included in the collection (except for the intialization script) is also available to be called as a module through dfhack.reqscript, providing a simpler interface to the functions.

In addition to the scripts and their functions, there are the systems. Systems are a somewhat unique method through which a modder can change the way the game works, without worrying about writing their own scripts or getting the DFHack syntax correct. These also take advantage of the functions, but operate behind the scenes by reading the raw/objects files. Some of what the systems do can already be done with the existing modding tools (e.q. you can put "modtools/outside-only -building SCREW_PRESS -type OUTSIDE_ONLY" in the onLoad init file or you can put {OUTSIDE_ONLY} under the SCREW_PRESS in the building_custom.txt raw file), but other uses are not currently found in other scripts. The advantage to this method of scripting is that it allows modders who want to interface only with the raws the ability to use DFHack still.

How to use it
  • Copy the Scripts/raw/scripts folder into your DF raw folder (hopefully there are no conflicts with any other scripts you have installed there)
  • Copy the Scripts/raw/systems folder into your DF raw folder (directly into the raw folder, not the raw/scripts folder)
  • Put core/initialize in your onLoad init file. If you want more verbose output you can use -v repeatedly (up to -vvvvv)
  • All available systems should now be working, and all scripts should now be callable through any other methods you want

Update history
UPDATE 10/13/2020
Added Reactions to the Enhanced System. More detail is on the third post

UPDATE 04/06/2020
Massive revamp of all scripts, functions, and systems. See next two posts for included scripts and systems. Utilities are not currently up to date and should not be used. More information coming soon.
« Last Edit: July 06, 2021, 03:16:48 pm by Roses »
Logged

Roses

  • Bay Watcher
    • View Profile
Re: Roses' Script, System, and Utilities Collection
« Reply #1 on: August 24, 2015, 08:40:24 am »

Current Scripts
unit Scripts
Spoiler: unit/attack (click to show/hide)
Spoiler: unit/butcher (click to show/hide)
Spoiler: unit/change-action (click to show/hide)
Spoiler: unit/change-attribute (click to show/hide)
Spoiler: unit/change-body (click to show/hide)
Spoiler: unit/change-skill (click to show/hide)
Spoiler: unit/propel (click to show/hide)
item Scripts
Spoiler: item/change-material (click to show/hide)
Spoiler: item/change-quality (click to show/hide)
Spoiler: item/change-subtype (click to show/hide)
Spoiler: item/create (click to show/hide)
Spoiler: item/destroy (click to show/hide)
Spoiler: item/projectile (click to show/hide)
entity Scripts
Spoiler: entity/change-resource (click to show/hide)
building Scripts
Spoiler: building/create (click to show/hide)
map Scripts
Spoiler: map/spawn-flow (click to show/hide)
Spoiler: map/spawn-liquid (click to show/hide)
« Last Edit: April 08, 2020, 11:42:05 am by Roses »
Logged

Roses

  • Bay Watcher
    • View Profile
Re: Roses' Script, System, and Utilities Collection v0.0
« Reply #2 on: August 24, 2015, 08:42:22 am »

Current Systems
Enhanced System
Purpose: The Enhanced System takes the raws as they are now and adds new token options to them. These additional tokens are declared in curly brackets {} and so are not read by DF itself, but instead by the system.
System Modules: Enhanced Buildings, Enhanced Items, Enhanced Reactions
enhancedBuildings
Raw File Type: Building
Eventful Functions:
  • onJobInitiated
  • onJobCompleted
Custom Events:
    Accepted Tokens: (in no particular order yet)
    • {POWER_PRODUCED:#} - Amount of power produced if {MECHANICAL}
    • {GEAR_POINT:x} - Location of gear connection point if {MECHANICAL}
    • {ON_FINISH} - Sets up a trigger for when the building is finished
    • {DESCRIPTION:string} - Sets a description to be used for the journal utility in the future
    • {ON_DECONSTRUCT} - Sets up a trigger for when the building is being deconstructed
    • {OUTSIDE_ONLY} - If present, will only allow construction if all squares are outside
    • {REPEATING_SCRIPT} - A dfhack script to run at a specific frequency (if # == 0 the script is only run once)
    • {ON_REMOVED} - Sets up a trigger for when the building is fully removed (from deconstruction)
    • {ON_START} - Sets up a trigger for when the building is started (after materials are gathered)
    • {MECHANICAL} - Sets the building as a mechanical building through require('plugins.building-hacks').registerBuilding
    • {REQUIRED_MAGMA:#} - Amount of magma needed around and/or under the building to be constructed
    • {POWER_CONSUMED:#} - Amount of power consumed if {MECHANICAL}
    • {CONSTRUCTION_TIME:skill:basedur:skilldecrease:mindur} - Changes the amount of time it takes to construct the building once all materials are brought to it
    • {MAX_AMOUNT:#} - Max number of this building that can be constructed (equivalent to {FORBIDDEN_BUILDING:THIS_BUILDING:#}
    • {FORBIDDEN_BUILDING:A:B} - Amount of specific building needed to exist in order for this building to not be constructed
    • {REQUIRED_BUILDING:A:B} - Amount of specific building needed to exist in order for this building to be constructed
    • {REQUIRED_WATER:#} - Amount of water needed around and/or under the building to be constructed
    • {ON_QUEUE} - Sets up a trigger for when the building is started (before materials are gathered)
    • {INSIDE_ONLY} - If present, will only allow construction if all squares are inside
    • {NEEDS_POWER} - Sets needs_power to true for registerBuilding
    • {AUTO_GEARS} - Sets auto_gears to true for registerBuilding
    • {SCRIPT} - A dfhack script to run once with a specific probability
    Simple Examples:
       [BUILDING_WORKSHOP:FOUNTAIN]
          [NAME:Fountain]
          {DESCRIPTION:A building that continually produces mist}
          ... DF Building Stuff ...
          {REQUIRED_WATER:4}
          {ON_FINISH}
             {REPEATING_SCRIPT:map/spawn-flow -pos [ BUILDING_LOCATION ] -type Mist -density 100:25}
          
       [BUILDING_WORKSHOP:COMPLEX_BUILDING]
          [NAME:Complex Building]
          {DESCRIPTION:A complex building that takes a long time to build}
          ... DF Building Stuff ...
          {CONSTRUCTION_TIME:MECHANICS:1000:10:1} Base construction time is 1000 ticks, lowers by 10 for each skill level, max build speed is 1
          
       [BUILDING_WORKSHOP:WINDMILL]
          [NAME:Windmill]
          {DESCRIPTION:A building that can only be built outside and makes power}
          ... DF Building Stuff ...
          {OUTSIDE_ONLY}
          {MECHANICAL}
             {AUTO_GEARS}
             {POWER_PRODUCED:25}
    enhancedItems
    Raw File Type: Item
    Eventful Functions:
    • onProjItemCheckImpact
    • onUnitAttack
    • onProjItemCheckMovement
    • onInventoryChange
    Custom Events:
    • onItemAction
    • onItemProjectile
    Accepted Tokens: (in no particular order yet)
    • {ON_PARRY} - Sets up a trigger for when a unit parries with the item
    • {ON_PROJECTILE_FIRED} - Sets up a trigger for when an item projectile is fired
    • {ATTRIBUTE_CHANGE:target:attribute:change:chance} - Equivalent to {SCRIPT:unit/change-attribute ...}
    • {DESCRIPTION:string} - Sets a description to be used for the journal utility in the future
    • {ON_PROJECTILE_HIT} - Sets up a trigger for when an item projectile hits
    • {SYNDROME_CHANGE:target:syndrome:change:chance} - Equivalent to {SCRIPT:unit/change-syndrome ...}
    • {SCRIPT} - A dfhack script to run with a specific chance when triggered
    • {ATTRIBUTE:A:B} - Used as a shortcut for ON_EQUIP and ON_UNEQUIP attribute changes
    • {ON_PROJECTILE_MOVE} - Sets up a trigger for when an item projectile moves
    • {ON_EQUIP} - Sets up a trigger for when the item is equipped
    • {CLASS:string} - Define an item class, not currently used for anything
    • {ON_BLOCK} - Sets up a trigger for when a unit blocks with the item
    • {ON_ATTACK} - Sets up a trigger for when a unit attacks (melee) with the item
    • {FIRE_RATE:base:change:max} - Adjust the fire rate for ranged weapons
    • {ON_UNEQUIP} - Sets up a trigger for when the item is unequipped
    • {REPEATING_SCRIPT} - A dfhack script to run with a specific frequency
    • {SKILL_CHANGE:target:skill:change:chance} - Equivalent to {SCRIPT:unit/change-skill ...}
    • {ON_SHOOT} - Sets up a trigger for when a unit attacks (ranged) with the item
    • {ON_WOUND} - Sets up a trigger for when a unit wounds another unit with the item
    • {SKILL:A:B} - Used as a shortcut for ON_EQUIP and ON_UNEQUIP skill changes
    Simple Examples:
       [ITEM_SHIELD:ITEM_SHIELD_EXAMPLE]
          [NAME:Example Shield]
          {DESCRIPTION:Knocks enemy backwards half the time when you block}
          ... DF Item Stuff ...
          {ON_BLOCK}
             {SCRIPT:unit/propel -unit OPPONENT -source BLOCKER -velocity [ 50 50 0 ] -mode Relative:50}

       [ITEM_WEAPON:RAPID_FIRE_CROSSBOW]
          [NAME:Fast Shooting Crossbow]
          {DESCRIPTION:Shoots bolts very fast}
          ... DF Item Stuff ...
          {FIRE_RATE:10:2:1} -- Base fire rate is 10, increases by 2 for each skill level, max shot speed is 1

       [ITEM_WEAPON:BLOOD_SWORD]
          [NAME:Blood Sword]
          {DESCRIPTION:Drains blood from opponent when wounded}
          ... DF Item Stuff ...
          {ON_WOUND}
             {SCRIPT:unit/change-body -unit OPPONENT -blood \-10:100}
             {SCRIPT:unit/change-body -unit HOLDER -blood 10:100}
    enhancedReactions
    Raw File Type: Reaction
    Eventful Functions:
    • onReactionComplete
    • onJobCompleted
    • onJobInitiated
    Custom Events:
      Accepted Tokens: (in no particular order yet)
      • {REACTION_TIME:skill:basedur:skilldecrease:mindur} - Changes the amount of time it takes to complete the reaction once all materials are brought to it
      • {REQUIRED_MAGMA:#} - Amount of nearby magma required for the reaction (does not consume the magma)
      • {ON_FINISH} - Sets up a trigger for when the reaction is finished (no product necessary)
      • {DESCRIPTION:string} - Sets a description to be used for the journal utility in the future
      • {REQUIRED_WATER:#} - Amount of nearby water required for the reaction (does not consume the water)
      • {PRODUCT:probability:amount:type:subtype:mattype:matsubtype} - Add custom products to a reaction (only for when the reaction finishes)
      • {REPEATING_SCRIPT} - A dfhack script to run with a specific frequency
      • {ON_QUEUE} - Sets up a trigger for when the reaction is started (before materials are gathered)
      • {SCRIPT} - A dfhack script to run with a specific chance when triggered
      • {ON_PRODUCT} - Sets up a trigger for when the reaction is finished and a product is created
      • {ON_START} - Sets up a trigger for when the reaction is started (after materials are gathered)
      • {CREATE:probability:amount:type:subtype:mattype:matsubtype} - Add custom products to a reaction (produced for any specified trigger)
      Simple Examples:
         [REACTION:MAKE_WAX_CRAFTS]
            {REACTION_TIME:WAX_WORKING:1:1:1}
            {PRODUCT:100:7:LIQUID:WATER:NONE:NONE}
            {PRODUCT:100:150:FLOW:MATERIALDUST:INORGANIC:SLADE}
            {ON_QUEUE} -- Triggers when the reaction is queued
               {SCRIPT:devel/print-args ON_QUEUE REACTION_NAME WORKER_ID BUILDING_ID [ LOCATION ]:100}
            {ON_START} -- Triggers after the ingredients are gathered
               {SCRIPT:devel/print-args ON_START REACTION_NAME WORKER_ID BUILDING_ID [ LOCATION ]:100}
            {ON_FINISH} -- Triggers when the reaction is finished, no product needed
               {SCRIPT:devel/print-args ON_FINISH REACTION_NAME WORKER_ID BUILDING_ID [ LOCATION ]:100}
            {ON_PRODUCT} -- Triggers when the reaction is finished and a product is produced
               {SCRIPT:devel/print-args ON_PRODUCT REACTION_NAME WORKER_ID BUILDING_ID [ LOCATION ]:100}
            [NAME:make wax crafts]
            [BUILDING:CRAFTSMAN:CUSTOM_SHIFT_W]
            [REAGENT:wax:150:GLOB:NONE:NONE:NONE]
            [REACTION_CLASS:WAX]
            [PRODUCT:100:1:CRAFTS:NONE:GET_MATERIAL_FROM_REAGENT:wax:NONE]
            [SKILL:WAX_WORKING]
      « Last Edit: October 13, 2020, 03:40:29 pm by Roses »
      Logged

      Roses

      • Bay Watcher
        • View Profile
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #3 on: August 24, 2015, 03:52:55 pm »

      Current Utilities (WIP)
      « Last Edit: April 06, 2020, 02:46:23 pm by Roses »
      Logged

      Meph

      • Bay Watcher
        • View Profile
        • worldbicyclist
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #4 on: August 24, 2015, 04:09:52 pm »

      Questions about the wrapper script.

      1. Does anyone other than myself use the 'wrapper' script?
      2. If so, what are your opinions on how the system currently works? There are a couple options to try and improve usability. (For instance instead of having to do -profession required:CARPENTER or -profession immune:MASON I could make a separate rprofession and iprofession).
      3. I would like to add more features (including checking for body parts, inventory items, etc...). But I am wondering when it becomes too much. I unfortunately can't think of a better way to allow more custom targeting options.
      4. Upper or lowercase? That is to say, currently if you want to require a target to have at least 2000 strength you would say -physical min:STRENGTH:2000. Should that instead be MIN:STRENGTH:2000? Something else entirely?
      5. Any other suggestions?
      1. I wanted to, but you changed syntax a lot, kept working on it, and then I went away on tour.
      2. None yet.
      3. Wait till someone requests it? It's complex enough as is; I think.
      4. Dont care if low/upper case, just keep it consistent.
      5. Probably later. ;)
      Logged
      ::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
      ::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
      ::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

      Isngrim

      • Bay Watcher
        • View Profile
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #5 on: August 24, 2015, 08:25:53 pm »

      Questions about the wrapper script.

      1. Does anyone other than myself use the 'wrapper' script?
      2. If so, what are your opinions on how the system currently works? There are a couple options to try and improve usability. (For instance instead of having to do -profession required:CARPENTER or -profession immune:MASON I could make a separate rprofession and iprofession).
      3. I would like to add more features (including checking for body parts, inventory items, etc...). But I am wondering when it becomes too much. I unfortunately can't think of a better way to allow more custom targeting options.
      4. Upper or lowercase? That is to say, currently if you want to require a target to have at least 2000 strength you would say -physical min:STRENGTH:2000. Should that instead be MIN:STRENGTH:2000? Something else entirely?
      5. Any other suggestions?

      1: I'm trying to, but the new structuring for using the scripts for modding is throwing me through a loop. Edit* as is my grammar
      2: as far as I can tell its great,though i do like the iprofession/rprofession
      3, 4, and  5 : I'd have to agree with Meph
      « Last Edit: August 24, 2015, 11:10:36 pm by Isngrim »
      Logged
      08:43 PM The wild animals and insects sang a merry tune and the trees performed a dance. I know you're trying to cheer me up, Vishnu, but that was actually a bit creepy.-Rhons

      expwnent

      • Bay Watcher
        • View Profile
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #6 on: August 24, 2015, 10:29:20 pm »

      Posting to watch.

      Have you switched the !BLAH system over to the \\BLAH system to make it more uniform with modtools stuff?
      Logged

      Roses

      • Bay Watcher
        • View Profile
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #7 on: August 25, 2015, 11:55:33 am »

      Posting to watch.

      Have you switched the !BLAH system over to the \\BLAH system to make it more uniform with modtools stuff?

      Yes, I did have a question about that though, and more specifically about the entire utils.processArgs thing. A couple questions actually;

      1. Is processArgs recursive? What I mean is when using something like modtools/interaction-trigger does it read through everything in the -command argument? Or does it just lump it all into one thing?
      2. Similarly, if I can't use the same \\BLAH that the other modtools things use correct? Because it would be overwritten?
      3. Should it always be two \? Is there ever a time you would only use one \?

      EDIT: Thanks for the feedback. My current plan is to rewrite the wrapper script to make it more intelligeble for people who want to see what is going on, and to make it easily addable to in the future. The rewrite shouldn't change the syntax from what it was before, and I am actually going to allow for both upper or lower case (since that is super easy to do). I am currently planning on breaking -profession, -noble, and -entity into a required and immune section (from #2 in the previous post)
      « Last Edit: August 25, 2015, 11:59:46 am by Roses »
      Logged

      Meph

      • Bay Watcher
        • View Profile
        • worldbicyclist
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #8 on: August 25, 2015, 12:00:04 pm »

      Quote
      EnchancedItems - similar to EnchancedCreatures, except for items. Will also display an items history.
      I've seen a script like this flying around, but it was never finished.
      Logged
      ::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
      ::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
      ::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

      Roses

      • Bay Watcher
        • View Profile
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #9 on: August 25, 2015, 12:01:49 pm »

      Quote
      EnchancedItems - similar to EnchancedCreatures, except for items. Will also display an items history.
      I've seen a script like this flying around, but it was never finished.

      Yes, I've seen one too, except I am planning on doing more advanced things (like sharpness increasing the more units the item kills, etc...)
      Logged

      Meph

      • Bay Watcher
        • View Profile
        • worldbicyclist
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #10 on: August 25, 2015, 12:34:02 pm »

      Call me boring, but shouldnt the sharpness decrease, the more the weapon is used? (except on magical weapons)
      Logged
      ::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
      ::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
      ::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

      Roses

      • Bay Watcher
        • View Profile
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #11 on: August 25, 2015, 12:45:08 pm »

      Call me boring, but shouldnt the sharpness decrease, the more the weapon is used? (except on magical weapons)

      Yes, and that would be possible too, but I was thinking more for magical weapons and such. Basically just to give items more flavor and options all around.
      Logged

      Meph

      • Bay Watcher
        • View Profile
        • worldbicyclist
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #12 on: August 25, 2015, 01:15:22 pm »

      Can you give artefacts some random effects? For example a file with X effects that are user-defined, and any artefact created in dwarf mode gets a random one from the list?

      But I probably should not make suggestions at this point, seeing how full (and unfinished) your todo list is.
      Logged
      ::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
      ::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
      ::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

      Roses

      • Bay Watcher
        • View Profile
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #13 on: August 25, 2015, 01:59:09 pm »

      Hahaha, yeah that todo list is just staring at me. Wish I could just take a month break from real life and get everything done. But, actually, yes, that was one of the plans. The actual DFHack part of it all is rather simple, but it's going to be figuring out how to make it module and customizable that is more difficult.
      Logged

      Max™

      • Bay Watcher
      • [CULL:SQUARE]
        • View Profile
      Re: Roses' Script, System, and Utilities Collection v0.0
      « Reply #14 on: August 25, 2015, 04:03:15 pm »

      That artifact idea is why I left the artifact critical script just artifacts rather than all attacks.
      Logged
      Pages: [1] 2 3 ... 24