Update modding guide to reflect new action timer API

develop
Tachytaenius 2022-12-01 23:52:00 +00:00
parent 370ffe274f
commit cd5ee666cf
1 changed files with 7 additions and 7 deletions

@ -316,7 +316,7 @@ item in the raws::
[METAL] [METAL]
[LEATHER] [LEATHER]
[HARD] [HARD]
[PEGASUS_BOOTS_MOD_MOVEMENT_TIMER_REDUCTION_PER_TICK:5] custom raw token [PEGASUS_BOOTS_MOD_FOOT_MOVEMENT_TIMER_REDUCTION_PER_TICK:2] custom raw token
(you don't have to comment the custom token every time, (you don't have to comment the custom token every time,
but it does clarify what it is) but it does clarify what it is)
@ -327,8 +327,7 @@ Then, let's make a ``repeat-util`` callback for once a tick::
repeatUtil.scheduleEvery(modId, 1, "ticks", function() repeatUtil.scheduleEvery(modId, 1, "ticks", function()
Let's iterate over every active unit, and for every unit, iterate over their Let's iterate over every active unit, and for every unit, iterate over their
worn items to calculate how much we are going to take from their movement worn items to calculate how much we are going to take from their on-foot movement timers::
timer::
for _, unit in ipairs(df.global.world.units.active) do for _, unit in ipairs(df.global.world.units.active) do
local amount = 0 local amount = 0
@ -336,15 +335,16 @@ timer::
if entry.mode == df.unit_inventory_item.T_mode.Worn then if entry.mode == df.unit_inventory_item.T_mode.Worn then
local reduction = customRawTokens.getToken( local reduction = customRawTokens.getToken(
entry.item, entry.item,
'PEGASUS_BOOTS_MOD_MOVEMENT_TIMER_REDUCTION_PER_TICK') 'PEGASUS_BOOTS_MOD_FOOT_MOVEMENT_TIMER_REDUCTION_PER_TICK')
amount = amount + (tonumber(reduction) or 0) amount = amount + (tonumber(reduction) or 0)
end end
end end
-- Subtract amount from on-foot movement timers if not on ground
if not unit.flags1.on_ground then
dfhack.units.subtractActionTimers(unit, amount, df.unit_action_type_group.MovementFeet)
end
end end
-- Subtract amount from movement timer if currently moving
dfhack.units.addMoveTimer(-amount)
The structure of a full mod The structure of a full mod
--------------------------- ---------------------------