Manually force traits on citizens?

I been bashing my head against a wall for like 2 weeks trying to figure this out on my own, so Now i will ask here…

Douse anyone know of a way to force every citizen on a kingdom to have the same trait?..

My current logic is inserting the command to add the trait into the initialization script for new hearthlings… But I cant find command, or the Initialization script specifically for hearthling generation.

Then again, I might be Terribly TERRIBLY off.

Just double checking you want them all to have the same trait, or a normal trait+ your new one?
In any case I suspect @kaimonkey is most likely to know, he’s been doing a bunch with traits

1 Like

So the function you’re looking for is in the file: stonehearth\services\server\population\population_faction.lua

The best function to latch onto is probably PopulationFaction:create_new_citizen_from_role_data.

Then then once you have the citizen object you can just run

local kingdom uri = "kmky:kingdom_of_nobels" # or whatever
if(self._sv.kingdom === kingdom_uri) then
   local my_trait = "kmnky_traits:traits:noble" # or whatever
   citizen:get_component('stonehearth:traits').add_trait(my_trait)
end

You can do this either by monkey patching that code into the end of that function (remember to return the citizen again) or, if you don’t care about compatibility, just override the whole file with that code copied into the file

(note: none of this code is tested, this is just me reading through the code and making conclusions, as always you will have to debug your own code, nothing works first time)

1 Like

awesome, thanks!

1 Like