|
|
@ -1,4 +1,4 @@
|
|
|
|
--attackTrigger.lua
|
|
|
|
--attack-trigger.lua
|
|
|
|
--author expwnent
|
|
|
|
--author expwnent
|
|
|
|
--based on itemsyndrome by Putnam
|
|
|
|
--based on itemsyndrome by Putnam
|
|
|
|
--triggers scripts when a unit attacks another with a weapon type, a weapon of a particular material
|
|
|
|
--triggers scripts when a unit attacks another with a weapon type, a weapon of a particular material
|
|
|
@ -7,7 +7,7 @@ local eventful = require 'plugins.eventful'
|
|
|
|
local utils = require 'utils'
|
|
|
|
local utils = require 'utils'
|
|
|
|
eventful.enableEvent(eventful.eventType.UNIT_ATTACK,1) -- this event type is cheap, so checking every tick is fine
|
|
|
|
eventful.enableEvent(eventful.eventType.UNIT_ATTACK,1) -- this event type is cheap, so checking every tick is fine
|
|
|
|
--eventful.enableEvent(eventful.eventType.INVENTORY_CHANGE,1000) --this is expensive, but you'll still want to set it lower
|
|
|
|
--eventful.enableEvent(eventful.eventType.INVENTORY_CHANGE,1000) --this is expensive, but you'll still want to set it lower
|
|
|
|
eventful.enableEvent(eventful.eventType.INVENTORY_CHANGE,1)
|
|
|
|
eventful.enableEvent(eventful.eventType.INVENTORY_CHANGE,1) --this is temporary
|
|
|
|
|
|
|
|
|
|
|
|
itemTriggers = itemTriggers or {}
|
|
|
|
itemTriggers = itemTriggers or {}
|
|
|
|
materialTriggers = materialTriggers or {}
|
|
|
|
materialTriggers = materialTriggers or {}
|
|
|
@ -49,18 +49,6 @@ function processTrigger(command)
|
|
|
|
dfhack.run_command(table.unpack(command2))
|
|
|
|
dfhack.run_command(table.unpack(command2))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function fillTable(table1,table2)
|
|
|
|
|
|
|
|
for k,v in pairs(table2) do
|
|
|
|
|
|
|
|
table1[k] = v
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function unfillTable(table1,table2)
|
|
|
|
|
|
|
|
for k,v in pairs(table2) do
|
|
|
|
|
|
|
|
table1[k] = nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handler(table)
|
|
|
|
function handler(table)
|
|
|
|
local itemMat = dfhack.matinfo.decode(table.item)
|
|
|
|
local itemMat = dfhack.matinfo.decode(table.item)
|
|
|
|
local itemMatStr = itemMat:getToken()
|
|
|
|
local itemMatStr = itemMat:getToken()
|
|
|
@ -70,17 +58,17 @@ function handler(table)
|
|
|
|
|
|
|
|
|
|
|
|
for _,command in ipairs(itemTriggers[itemType] or {}) do
|
|
|
|
for _,command in ipairs(itemTriggers[itemType] or {}) do
|
|
|
|
if command[table.mode] then
|
|
|
|
if command[table.mode] then
|
|
|
|
fillTable(command,table)
|
|
|
|
utils.fillTable(command,table)
|
|
|
|
processTrigger(command)
|
|
|
|
processTrigger(command)
|
|
|
|
unfillTable(command,table)
|
|
|
|
utils.unfillTable(command,table)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
for _,command in ipairs(materialTriggers[itemMatStr] or {}) do
|
|
|
|
for _,command in ipairs(materialTriggers[itemMatStr] or {}) do
|
|
|
|
if command[table.mode] then
|
|
|
|
if command[table.mode] then
|
|
|
|
fillTable(command,table)
|
|
|
|
utils.fillTable(command,table)
|
|
|
|
processTrigger(command)
|
|
|
|
processTrigger(command)
|
|
|
|
unfillTable(command,table)
|
|
|
|
utils.unfillTable(command,table)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -89,9 +77,9 @@ function handler(table)
|
|
|
|
local contaminantStr = contaminantMat:getToken()
|
|
|
|
local contaminantStr = contaminantMat:getToken()
|
|
|
|
table.contaminantMat = contaminantMat
|
|
|
|
table.contaminantMat = contaminantMat
|
|
|
|
for _,command in ipairs(contaminantTriggers[contaminantStr] or {}) do
|
|
|
|
for _,command in ipairs(contaminantTriggers[contaminantStr] or {}) do
|
|
|
|
fillTable(command,table)
|
|
|
|
utils.fillTable(command,table)
|
|
|
|
processTrigger(command)
|
|
|
|
processTrigger(command)
|
|
|
|
unfillTable(command,table)
|
|
|
|
utils.unfillTable(command,table)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.contaminantMat = nil
|
|
|
|
table.contaminantMat = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|