diff --git a/docs/Lua API.rst b/docs/Lua API.rst index bbcf0b145..55a217757 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -4587,35 +4587,40 @@ on DF world events. List of events -------------- -1. ``onReactionComplete(reaction,reaction_product,unit,input_items,input_reagents,output_items,call_native)`` +1. ``onReactionCompleting(reaction,reaction_product,unit,input_items,input_reagents,output_items,call_native)`` - Auto activates if detects reactions starting with ``LUA_HOOK_``. Is called when reaction finishes. + Is called once per reaction product, before reaction had a chance to call native code for item creation. + Setting ``call_native.value=false`` cancels further processing: no items are created and ``onReactionComplete`` is not called. -2. ``onItemContaminateWound(item,unit,wound,number1,number2)`` +2. ``onReactionComplete(reaction,reaction_product,unit,input_items,input_reagents,output_items)`` + + Is called once per reaction product, when reaction finishes and has at least one product. + +3. ``onItemContaminateWound(item,unit,wound,number1,number2)`` Is called when item tries to contaminate wound (e.g. stuck in). -3. ``onProjItemCheckMovement(projectile)`` +4. ``onProjItemCheckMovement(projectile)`` Is called when projectile moves. -4. ``onProjItemCheckImpact(projectile,somebool)`` +5. ``onProjItemCheckImpact(projectile,somebool)`` Is called when projectile hits something. -5. ``onProjUnitCheckMovement(projectile)`` +6. ``onProjUnitCheckMovement(projectile)`` Is called when projectile moves. -6. ``onProjUnitCheckImpact(projectile,somebool)`` +7. ``onProjUnitCheckImpact(projectile,somebool)`` Is called when projectile hits something. -7. ``onWorkshopFillSidebarMenu(workshop,callnative)`` +8. ``onWorkshopFillSidebarMenu(workshop,callnative)`` Is called when viewing a workshop in 'q' mode, to populate reactions, useful for custom viewscreens for shops. -8. ``postWorkshopFillSidebarMenu(workshop)`` +9. ``postWorkshopFillSidebarMenu(workshop)`` Is called after calling (or not) native fillSidebarMenu(). Useful for job button tweaking (e.g. adding custom reactions) @@ -4683,7 +4688,7 @@ Functions 1. ``registerReaction(reaction_name,callback)`` - Simplified way of using onReactionComplete; the callback is function (same params as event). + Simplified way of using onReactionCompleting; the callback is function (same params as event). 2. ``removeNative(shop_name)`` @@ -4715,7 +4720,7 @@ Reaction complete example:: b=require "plugins.eventful" - b.registerReaction("LUA_HOOK_LAY_BOMB",function(reaction,unit,in_items,in_reag,out_items,call_native) + b.registerReaction("LAY_BOMB",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) diff --git a/docs/changelog.txt b/docs/changelog.txt index 4c034b5bc..1302cf82e 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -40,6 +40,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes - ``widgets.CycleHotkeyLabel``: allow initial option values to be specified as an index instead of an option value - ``job.removeJob()``: fixes regression in DFHack 0.47.05-r5 where items/buildings associated with the job were not getting disassociated when the job is removed. Now `build-now` can build buildings and `gui/mass-remove` can cancel building deconstruction again +- `eventful`: fix ``eventful.registerReaction`` to correctly pass ``call_native`` argument thus allowing canceling vanilla item creation. Updated related documentation. ## Misc Improvements - `confirm`: added a confirmation dialog for removing manager orders diff --git a/plugins/lua/eventful.lua b/plugins/lua/eventful.lua index 293874393..b1520dac1 100644 --- a/plugins/lua/eventful.lua +++ b/plugins/lua/eventful.lua @@ -93,7 +93,7 @@ end function registerReaction(reaction_name,callback) _registeredStuff.reactionCallbacks=_registeredStuff.reactionCallbacks or {} _registeredStuff.reactionCallbacks[reaction_name]=callback - onReactionComplete._library=onReact + onReactionCompleting._library=onReact dfhack.onStateChange.eventful=unregall end