I want to use the names of the villagers you spawn with in a mod,I have a little background in coding, but not LUA or C++, so if anyone could tell me if there is a way to retrieve the names of the villagers once they’ve spawned and what language that would need to be coded in that would be great!
Four ways to go there, depending on what you want.
You want to replace all names. You want to override “stonehearth/population/data/ascendancy.json” with your own file where you’ve changed the names.
You want to add names. You want to mixin your names to the same file as above.
You want to have fancier names. rp_alternate_naming adds a different naming generator that is “glueing” name parts together, maintained by @phoriist.
You want to change names during the game or do something completely different. Have a look at how rp_alternate_naming does it but keep in mind that it requires RP.
Bonus) You really just want to query the names. In that case, there’s a worker tracker somewhere (check the carpenter promotion stuff for it). Get every worker, then query its name (check population_faction.lua for how to set the name and likely just switch “set” and “get” in said function).
Which one of those options is what you had in mind?
Thanks. this seems most in line in what I was thinking. I don’t want to tell until I get it to work or I give up in rage, and just a quick question, what is ‘RP’?
An extension of some sorts of the current modding API.
But, yeah. For 4), you likely want to check the JS for the promotion on how to receive the list of workers. The same code should work in lua (with _radiant.call). After that, it’s just querying the names.
For 4, you want to take a look at population_faction.lua’s way of setting names. rp_alternate_naming messes around with those (by using the events RP provides). You could overwrite those functions yourself, which isn’t recommended however. Once you have an entity reference somehow, setting its display name (that’s what it’s called iirc) should be fairly simple.
Will that not work or is that just not relevant?
Nah, I was thinking you were referring to the bonus instead of 4 and got it mixed up. While that does work, it might not be what you want.
The tracker thingy that is implemented by default only tracks workers, i.e. no carpenters/weavers/trappers. I suppose you could derive an entity tracker from that one to get one that had all settlers.
If you were a bit more precise (as to when you need the list/if you need to be informed about new villagers/if you plan on modifying them/if you need a reference to their entities or really just their names) I could be more helpful.