diff --git a/Lua API.html b/Lua API.html index e5318165d..232bfc8e4 100644 --- a/Lua API.html +++ b/Lua API.html @@ -402,10 +402,16 @@ ul.auto-toc {
  • Plugins @@ -3038,9 +3044,93 @@ set is the same as used by the command line.

    Does not export any native functions as of now. Instead, it calls lua code to perform the actual ordering of list items.

    +
    +

    Eventful

    +

    This plugin exports some events to lua thus allowing to run lua functions +on DF world events.

    +
    +

    List of events

    +
      +
    1. onReactionComplete(reaction,unit,input_items,input_reagents,output_items,call_native)

      +

      Auto activates if detects reactions starting with LUA_HOOK_. Is called when reaction finishes.

      +
    2. +
    3. onItemContaminateWound(item,unit,wound,number1,number2)

      +

      Is called when item tries to contaminate wound (e.g. stuck in).

      +
    4. +
    5. onProjItemCheckMovement(projectile)

      +

      Is called when projectile moves.

      +
    6. +
    7. onProjItemCheckImpact(projectile,somebool)

      +

      Is called when projectile hits something.

      +
    8. +
    9. onProjUnitCheckMovement(projectile)

      +

      Is called when projectile moves.

      +
    10. +
    11. onProjUnitCheckImpact(projectile,somebool)

      +

      Is called when projectile hits something.

      +
    12. +
    13. onWorkshopFillSidebarMenu(workshop,callnative)

      +

      Is called when viewing a workshop in 'q' mode, to populate reactions, usefull for custom viewscreens for shops.

      +
    14. +
    15. postWorkshopFillSidebarMenu(workshop)

      +

      Is called after calling (or not) native fillSidebarMenu(). Usefull for job button +tweaking (e.g. adding custom reactions)

      +
    16. +
    +
    +
    +

    Functions

    +
      +
    1. registerReaction(reaction_name,callback)

      +

      Simplified way of using onReactionComplete; the callback is function (same params as event).

      +
    2. +
    3. removeNative(shop_name)

      +

      Removes native choice list from the building.

      +
    4. +
    5. addReactionToShop(reaction_name,shop_name)

      +

      Add a custom reaction to the building.

      +
    6. +
    +
    +
    +

    Examples

    +

    Spawn dragon breath on each item attempt to contaminate wound:

    +
    +b=require "plugins.eventful"
    +b.onItemContaminateWound.one=function(item,unit,un_wound,x,y)
    +    local flw=dfhack.maps.spawnFlow(unit.pos,6,0,0,50000)
    +end
    +
    +

    Reaction complete example:

    +
    +b=require "plugins.eventful"
    +
    +b.onReactionComplete.one=function(reaction,unit,in_items,in_reag,out_items,call_native)
    +  local pos=copyall(unit.pos)
    +  -- spawn dragonbreath after 100 ticks
    +  dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end)
    +  --do not call real item creation code
    +  call_native.value=false
    +end
    +
    +

    Granade example:

    +
    +b=require "plugins.eventful"
    +b.onProjItemCheckImpact.one=function(projectile)
    +  -- you can check if projectile.item e.g. has correct material
    +  dfhack.maps.spawnFlow(projectile.cur_pos,6,0,0,50000)
    +end
    +
    +

    Integrated tannery:

    +
    +b=require "plugins.eventful"
    +b.addReactionToShop("TAN_A_HIDE","LEATHERWORKS")
    +
    +
    +
    -

    Scripts

    +

    Scripts

    Any files with the .lua extension placed into hack/scripts/* are automatically used by the DFHack core as commands. The matching command name consists of the name of the file sans @@ -3071,7 +3161,7 @@ The name argument should be the name stem, as

    Note that this function lets errors propagate to the caller.

    -

    Save init script

    +

    Save init script

    If a save directory contains a file called raw/init.lua, it is automatically loaded and executed every time the save is loaded. It can also define the following functions to be called by dfhack:

    diff --git a/Lua API.rst b/Lua API.rst index a6bdca4ef..19ba7132d 100644 --- a/Lua API.rst +++ b/Lua API.rst @@ -2967,51 +2967,85 @@ on DF world events. List of events -------------- -1. onReactionComplete(reaction,unit,input_items,input_reagents,output_items,call_native) - auto activates if detects reactions starting with ``LUA_HOOK_``. Is called when reaction finishes. -2. onItemContaminateWound(item,unit,wound,number1,number2) - Is called when item tries to contaminate wound (e.g. stuck in) -3. onProjItemCheckMovement(projectile) - is called when projectile moves -4. onProjItemCheckImpact(projectile,somebool) - is called when projectile hits something -5. onProjUnitCheckMovement(projectile) - is called when projectile moves -6. onProjUnitCheckImpact(projectile,somebool) - is called when projectile hits something -7. onWorkshopFillSidebarMenu(workshop,callnative) - is called when viewing a workshop in 'q' mode, to populate reactions, usefull for custom viewscreens for shops -8. postWorkshopFillSidebarMenu(workshop) - is called after calling (or not) native fillSidebarMenu(). Usefull for job button tweaking (e.g. adding custom reactions) +1. ``onReactionComplete(reaction,unit,input_items,input_reagents,output_items,call_native)`` + + Auto activates if detects reactions starting with ``LUA_HOOK_``. Is called when reaction finishes. + +2. ``onItemContaminateWound(item,unit,wound,number1,number2)`` + + Is called when item tries to contaminate wound (e.g. stuck in). + +3. ``onProjItemCheckMovement(projectile)`` + + Is called when projectile moves. + +4. ``onProjItemCheckImpact(projectile,somebool)`` + + Is called when projectile hits something. + +5. ``onProjUnitCheckMovement(projectile)`` + + Is called when projectile moves. + +6. ``onProjUnitCheckImpact(projectile,somebool)`` + + Is called when projectile hits something. + +7. ``onWorkshopFillSidebarMenu(workshop,callnative)`` + + Is called when viewing a workshop in 'q' mode, to populate reactions, usefull for custom viewscreens for shops. + +8. ``postWorkshopFillSidebarMenu(workshop)`` + + Is called after calling (or not) native fillSidebarMenu(). Usefull for job button + tweaking (e.g. adding custom reactions) Functions --------- -1. registerReaction(reaction_name,callback) - simplified way of using onReactionComplete, the callback is function (same params as event) -2. removeNative(shop_name) - removes native choice list from the building -3. addReactionToShop(reaction_name,shop_name) - add a custom reaction to the building +1. ``registerReaction(reaction_name,callback)`` + + Simplified way of using onReactionComplete; the callback is function (same params as event). + +2. ``removeNative(shop_name)`` + + Removes native choice list from the building. + +3. ``addReactionToShop(reaction_name,shop_name)`` + + Add a custom reaction to the building. Examples -------- -Spawn dragon breath on each item attempt to contaminate wound: -:: +Spawn dragon breath on each item attempt to contaminate wound:: - b=require "plugins.eventful" + b=require "plugins.eventful" b.onItemContaminateWound.one=function(item,unit,un_wound,x,y) local flw=dfhack.maps.spawnFlow(unit.pos,6,0,0,50000) end -Reaction complete example: -:: +Reaction complete example:: + b=require "plugins.eventful" + b.onReactionComplete.one=function(reaction,unit,in_items,in_reag,out_items,call_native) local pos=copyall(unit.pos) - dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end) -- spawn dragonbreath after 100 ticks - call_native.value=false --do not call real item creation code + -- spawn dragonbreath after 100 ticks + dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end) + --do not call real item creation code + call_native.value=false end -Granade example: -:: +Granade example:: + b=require "plugins.eventful" b.onProjItemCheckImpact.one=function(projectile) -- you can check if projectile.item e.g. has correct material dfhack.maps.spawnFlow(projectile.cur_pos,6,0,0,50000) end -Integrated tannery: -:: +Integrated tannery:: + b=require "plugins.eventful" b.addReactionToShop("TAN_A_HIDE","LEATHERWORKS") diff --git a/NEWS b/NEWS index d9c184832..91eab0ec0 100644 --- a/NEWS +++ b/NEWS @@ -4,7 +4,8 @@ DFHack future - support for displaying active keybindings properly. - support for reusable widgets in lua screen library. - Maps::canStepBetween: returns whether you can walk between two tiles in one step. - - EventManager: monitors various in game events centrally so that individual plugins don't have to monitor the same things redundantly. + - EventManager: monitors various in game events centrally so that individual plugins + don't have to monitor the same things redundantly. Notable bugfixes: - autobutcher can be re-enabled again after being stopped. - stopped Dwarf Manipulator from unmasking vampires. @@ -28,6 +29,7 @@ DFHack future - stripcaged: mark items inside cages for dumping, eg caged goblin weapons. - soundsense-season: writes the correct season to gamelog.txt on world load. - create-items: spawn items + - fix/cloth-stockpile: fixes bug 5739; needs to be run after savegame load every time. New GUI scripts: - gui/guide-path: displays the cached path for minecart Guide orders. - gui/workshop-job: displays inputs of a workshop job and allows tweaking them. diff --git a/Readme.html b/Readme.html index d9a3d0602..8cd192f35 100644 --- a/Readme.html +++ b/Readme.html @@ -510,41 +510,42 @@ access DF memory and allow for easier development of new tools.

  • lever
  • stripcaged
  • create-items
  • +
  • soundsense-season
  • -
  • In-game interface tools