Jump to content

Recommended Posts

>>SOLVED<<

 

Hi there !

I haven't been modding lately and I feel a bit rusty.

So, I'm trying to make the reveal radius from my mod 'Wide FOV' work with custom characters. I'm using this for the vanilla characters :

for k,prefabname in ipairs(CHARACTERLIST) doAddPrefabPostInit(prefabname, addRevealer)end

where addRevealer is the function for the reveal radius.

Any help is welcome and happy holydays !

Edited by kiopho
Link to comment
https://forums.kleientertainment.com/forums/topic/30599-modcharacterlist/
Share on other sites

What is the addRevealer function doing?

If it's not adding a component (or if it is adding a component that doesn't need to save/load any data), just use AddSimPostInit instead. The callback function of that gets called with the player prefab as the parameter, no matter the character.

However, if it is adding a component and that component needs to save/load data, then see the Adding components to all players section of my Code Tips and Tricks thread.

Edited by squeek
for k,prefabname in ipairs(GLOBAL.MODCHARACTERLIST) do
AddPrefabPostInit(prefabname, addRevealer)
end

 

should work, just be sure you are loading after any characters are loaded by setting a very low priority in modinfo

Edited by Heavenfall

Thanks a lot for the help guys, I got it working.

 

@squeek It expands the reveal radius on the map to match the custom FOV. So it needs to save the extra map space revealed. But that's working fine. Thanks for the link mate.

 

@Heavenfall That's what I used but it didn't work because the custom character I was testing with had its priority higher than my mod. And of course the priority system went way over my head :/ Now it works fine. When you focus too much on a problem, you may end up missing the most obvious ><

if GLOBAL.MODCHARACTERLIST thenfor k,prefabname in ipairs(GLOBAL.MODCHARACTERLIST) doAddPrefabPostInit(prefabname, addRevealer)endend
Edited by kiopho

However, if it is adding a component and that component needs to save/load data, then see the Adding components to all players section of my Code Tips and Tricks thread.

That would be the way to handle this without depending on load priority. Though I suppose it's a more complex solution.

If you'd like to update that tip with a more "user-friendly" presentation, here's the method wrapped in a function (used just like AddSimPostInit):

function AddPlayerPrefabPostInit(postinitfn)	AddPrefabPostInit("world", function()		GLOBAL.assert( GLOBAL.GetPlayer() == nil )		local player_prefab = GLOBAL.SaveGameIndex:GetSlotCharacter()	 		-- Unfortunately, we can't add new postinits by now. So we have to do		-- it the hard way...	 		GLOBAL.TheSim:LoadPrefabs( {player_prefab} )		local oldfn = GLOBAL.Prefabs[player_prefab].fn		GLOBAL.Prefabs[player_prefab].fn = function(Sim)			local player = oldfn(Sim)	 			postinitfn(player)	 			return player		end	end)end
EDIT: I hadn't noticed until now I was shadowing an inst variable with another in a deeper scope. The code itself was correct, but nevertheless this is something that greatly hurts code legilibity and is prone to errors, so I fixed it. Edited by simplex

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...