Well, I've written a script to successfully add wounds to specified body parts and their layers. Now I just need to work on figuring out the numbers. So far it seems to be working just fine. Copying numbers from other wounds gives the exact same outcome. And you can even get messages like "His eyes are burnt". This is the code so far, but note that it doesn't have any of the number stuff in it. I am still doing that by hand until I figure out a convenient way to do it.
local utils = require 'utils'
function checkbodycategory(unit,bp)
local parts = {}
local body = unit.body.body_plan.body_parts
for i,x in ipairs(bp) do
local a = 1
for j,y in ipairs(body) do
if y.category == x and not unit.body.components.body_part_status[j].missing then
parts[a] = j
a = a + 1
end
end
end
return parts
end
function checkbodytoken(unit,bp)
local parts = {}
local body = unit.body.body_plan.body_parts
for i,x in ipairs(bp) do
local a = 1
for j,y in ipairs(body) do
if y.token == x and not unit.body.components.body_part_status[j].missing then
parts[a] = j
a = a + 1
end
end
end
return parts
end
function checkbodyflag(unit,bp)
local parts = {}
local body = unit.body.body_plan.body_parts
for i,x in ipairs(bp) do
local a = 1
for j,y in ipairs(body) do
if y.flags[x] and not unit.body.components.body_part_status[j].missing then
parts[a] = j
a = a + 1
end
end
end
return parts
end
function checkbodylayer(unit,parts,layers)
local a = 1
local array = {}
for i,x in pairs(parts) do
local part = unit.body.body_plan.body_parts[x]
for j,y in pairs(layers) do
for k,z in pairs(part.layers) do
if z.layer_name == y or y == 'ALL' then
array[a] = {x,k,z.layer_id}
a = a+1
end
end
end
end
return array
end
function addwound(unit,array)
local body = unit.body
local wound = df.unit_wound:new()
wound.id = body.wound_next_id
body.wound_next_id = body.wound_next_id + 1
for i,x in pairs(array) do
part = df.unit_wound.T_parts:new()
part.global_layer_idx = x[3]
part.layer_idx = x[2]
part.body_part_id = x[1]
wound.parts:insert('#',part)
end
body.wounds:insert('#',wound)
end
validArgs = validArgs or utils.invert({
'help',
'category',
'token',
'flag',
'all',
'layer',
'unit',
})
local args = utils.processArgs({...}, validArgs)
if args.help then -- Help declaration
print([[wound-add.lua
Assign a wound to a specific body part and layer of a unit
arguments:
-help
print this help message
-unit id
REQUIRED
id of the target unit
-all \
target all body parts |
-category TYPE |
examples: |
TENTACLE |
HOOF_REAR |
HEAD |
-token TYPE | Must have at least one of these
examples: |
UB |
LB |
REYE |
-flag FLAG |
examples: |
SIGHT |
LIMB |
SMALL /
-layer TYPE
examples:
SKIN
FAT
MUSCLE
ALL
examples:
unit/wound-add -unit \\UNIT_ID -all -layer SKIN
unit/wound-add -unit \\UNIT_ID -token UB -layer ALL
]])
return
end
if args.unit and tonumber(args.unit) then -- Check for unit declaration !REQUIRED
unit = df.unit.find(tonumber(args.unit))
else
print('No unit selected')
return
end
dur = tonumber(args.dur) or 0 -- Check if there is a duration (default 0)
parts = {}
recall = ''
tokens = args.all or args.category or args.token or args.flag
layers = args.layer or ''
if type(layers) == 'string' then layers = {layers} end
if type(tokens) == 'string' then tokens = {tokens} end
if args.all then -- Check for the all body parts flag. !!RUN EFFECT!!
body = unit.body.body_plan.body_parts
for k,v in ipairs(body) do
parts[k] = k
end
recall = 'all'
elseif args.category then -- Check for category body parts. !!RUN CHECKBODYCATEGORY!!. !!RUN EFFECT!!
parts = checkbodycategory(unit,tokens)
recall = 'category'
elseif args.token then -- Check for token body parts. !!RUN CHECKBODYTOKEN!!. !!RUN EFFECT!!
parts = checkbodytoken(unit,tokens)
recall = 'token'
elseif args.flag then -- Check for flag body parts. !!RUN CHECKBODYFLAG!!. !!RUN EFFECT!!
parts = checkbodyflag(unit,tokens)
recall = 'flag'
end
array = checkbodylayer(unit,parts,layers)
if #array >= 1 then
addwound(unit,array)
end