The only way I've found, and it's exceptionally hacky, is to create portrait modifiers in
gfx\portraits\portrait_modifiers
and then apply them with a character flag. The first part of
the wiki gives some example code on how to do this.
There are a
lot of problems with this, though. For one, using
replace
to set genes in portrait modifiers requires setting values between 0 and 1 specified to at most 2 decimal places, whereas the DNA values output by the portrait editor have values in the 0–255 range, so you need to do the maths yourself for every single gene you want to replace. Once you do, though, it seems to work, but there's yet another catch: character flags get unset on death, which resets the appearance to the default.
All in all, it's just an awful lot of work when it seems to me
create_character
should just be able to take a
dna
string the same way historical characters do. Why those functions don't use the same format, I cannot fathom.
EDIT:
So I've found a workaround to preserve appearance after death, if that's important for you. Rather than setting a character flag that's cleared on death, you can set a global variable with the character whose appearance you want to modify as its value, then check for the variable in the portrait modifiers:—
Code:
# after create_character, with saved scope custom_character_001
set_global_variable = {
name = custom_character_001
value = scope:custom_character_001
}
# in your portrait modifier
weight = {
base = 0
modifier = {
add = 200
AND = {
exists = global_var:custom_character_001
global_var:custom_character_001 = {
this = root
}
}
}
}
Since I'm only doing a few characters where this matters, this isn't a big deal, but it does run the risk of becoming a resource drain if you needed to do a lot of them. But then, so too the portrait modifiers in the first place, I imagine, so… \
/
Keep in mind, as the numeric suffix attests, since the value gets overridden if you reset the global variable, each custom character needs his own global variable set to track him. You
may be able to fix this with a global list instead, but I haven't tested it, so I'm unsure if dead characters are pruned from those.