Jump to content

Recommended Posts

Now I'm using:

local all_chars={"wilson","willow","wendy","wolfgang","wickerbottom","wx78"}function add_all(fn)	for i=1,#all_chars do		AddPrefabPostInit(all_chars[i],fn)	endendadd_all(function(inst)	--some common codeend)

​But it does not affect characters from mods. 

Now I'm using:

local all_chars={"wilson","willow","wendy","wolfgang","wickerbottom","wx78"}function add_all(fn)	for i=1,#all_chars do		AddPrefabPostInit(all_chars[i],fn)	endendadd_all(function(inst)	--some common codeend)

​But it does not affect characters from mods. 

 

I don't know if this works, but here is what I personally use.

 

local function SOMEFUNCTION(inst)-- DO THINGS HERE.endfor _, v in ipairs(CHARACTERLIST) do    AddPrefabPostInit(v, SOMEFUNCTION)end for _, v in ipairs(MODCHARACTERLIST) do    AddPrefabPostInit(v, SOMEFUNCTION)end  

 

I have this as the very last thing to run in my modmain.lua file.

Edited by Kzisor

Kzisor's method is more efficient, I believe, but there is an AddPlayerPostInit(fn). It uses the "player" tag, however, and technically adds a small postinit overhead to every prefab since it's added to all, then checks for the tag.

Thank you all for your answers!

I don't like "postinit overhead", so I found best way:

function AddPlayersPostInit(fn)	for i,v in ipairs(MAIN_CHARACTERLIST) do -- DST_CHARACTERLIST + ROG_CHARACTERLIST		AddPrefabPostInit(v,fn)	end	for i,v in ipairs(MODCHARACTERLIST) do		AddPrefabPostInit(v,fn)	endend

@Maris, I didn't realize it at the time, but someone pointed out in another thread that the efficient method (going through the character lists) can miss some mod characters depending on load order. You can influence your mod's load order to be later on by reducing it's priority in the modinfo:

priority = -1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...