FurryEskimo Posted July 10, 2021 Share Posted July 10, 2021 I've been under the impression you add something like this to the ModMain: modimport("______________.lua") and then in the aformentioned file you'd add something like this: AddPlayerPostInit(function(inst) if inst.prefab == "____________" then --Code end end) This doesn't seem to be working though.. Am I overlooking something simple? Link to comment Share on other sites More sharing options...
SuperMeatGoy Posted July 10, 2021 Share Posted July 10, 2021 Pretty sure you can add to a character's postinit using the normal AddPrefabPostInit function. Link to comment Share on other sites More sharing options...
FurryEskimo Posted July 11, 2021 Author Share Posted July 11, 2021 @SuperMeatGoy Ok, I’ll give that a try tomorrow. If it’s adding a function, is it called automatically, or do I need to add something which calls the function? Link to comment Share on other sites More sharing options...
SuperMeatGoy Posted July 11, 2021 Share Posted July 11, 2021 1 minute ago, FurryEskimo said: @SuperMeatGoy Ok, I’ll give that a try tomorrow. If it’s adding a function, is it called automatically, or do I need to add something which calls the function? it's called when the game initializes just as if you put the code inside the prefab itself Link to comment Share on other sites More sharing options...
FurryEskimo Posted July 11, 2021 Author Share Posted July 11, 2021 (edited) @SuperMeatGoy Hi again. It appears to have almost worked.. The code ran through the character's prefab file, with the code imported, and went all the way through using the config variable, but failed to actually change the player's stat.. Any idea why this happened? I can take this code and put it directly into the master_postinit and it works fine. Is that the issue? Master_postinit vs comon_postinit? Edited July 11, 2021 by FurryEskimo Link to comment Share on other sites More sharing options...
penguin0616 Posted July 11, 2021 Share Posted July 11, 2021 (edited) Master_postinit runs on the server, common_postinit runs on both the server and the client. I'm guessing that you're fiddling with the foodaffinity component, which means your code needs to run only on the server side. So you need a mastersim check. Edited July 11, 2021 by penguin0616 2 Link to comment Share on other sites More sharing options...
Kyno Posted July 12, 2021 Share Posted July 12, 2021 Are you trying to add "favorite food" to your character? Link to comment Share on other sites More sharing options...
FurryEskimo Posted July 12, 2021 Author Share Posted July 12, 2021 @penguin0616 Not to sound like a broken record, but how do I do that? @Kyno Yes, that’s exactly what I’ve done. I wrote code that allows for the character’s favorite food to be configurable, but it’s really long, so I wanted to put it in it's own file. Link to comment Share on other sites More sharing options...
Kyno Posted July 12, 2021 Share Posted July 12, 2021 Sorry if I understand wrong, but can't you do like this for example? AddPrefabPostInit("willow", function(inst) if inst.components.foodaffinity then inst.components.foodaffinity:AddPrefabAffinity("feijoada", TUNING.AFFINITY_15_CALORIES_HUGE) end end) I've been using this for my mod and seems to work without problems, of course you would need to make your changes. Link to comment Share on other sites More sharing options...
FurryEskimo Posted July 12, 2021 Author Share Posted July 12, 2021 @Kyno That's basically what I did originally, and it works fine. I wanted to go the extra file and let people select their own favorite food. Link to comment Share on other sites More sharing options...
Kyno Posted July 12, 2021 Share Posted July 12, 2021 (edited) I think you can do like this but I didn't have time to test it properly. local FavoriteFood = GetModConfigData("favoritefood") AddPrefabPostInit("willow", function(inst) if inst.components.foodaffinity then inst.components.foodaffinity:AddPrefabAffinity(FavoriteFood, TUNING.AFFINITY_15_CALORIES_HUGE) end end) and in modinfo.lua configuration_options = { { name = "favoritefood", label = "Favorite Food", hover = "The character's favorite food.", options = { {description = "Meat Stew", hover = "Meat Stew as favorite food.", data = "bonestew"}, {description = "California Roll", hover = "California Roll as favorite food.", data = "californiaroll"}, }, default = "bonestew", } Edited July 12, 2021 by Kyno oops :P Link to comment Share on other sites More sharing options...
FurryEskimo Posted July 12, 2021 Author Share Posted July 12, 2021 (edited) @Kyno I've already created the code, and it works fine. The issue is that it's SO long (because there are ~170 different food items.) I want to import this code into the character's master_postinit, rather than cause the file to become bloated with all this irritating, repetitive code. PS- I tried making the data value the item's code name but it caused a ton of issues and didn't seem to work at all.. I created a post on the forums about configurable data with text values, but no one responded, so after a few days I deleted the post and just did it the way I knew would work. Edited July 12, 2021 by FurryEskimo Link to comment Share on other sites More sharing options...
Kyno Posted July 12, 2021 Share Posted July 12, 2021 Ah, my bad. would this help you then? -- winona.lua example local function master_postinit(inst) inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default inst.components.health:SetMaxHealth(TUNING.WENDY_HEALTH) inst.components.hunger:SetMax(TUNING.WENDY_HUNGER) inst.components.sanity:SetMax(TUNING.WENDY_SANITY) local FavoriteFood = GetModConfigData("favoritefood", KnownModIndex:GetModActualName("YourMod")) inst.components.foodaffinity:AddPrefabAffinity(FavoriteFood, TUNING.AFFINITY_15_CALORIES_MED) inst.customidleanim = "idle_winona" inst.components.grue:SetResistance(1) if TheNet:GetServerGameMode() == "lavaarena" then event_server_data("lavaarena", "prefabs/winona").master_postinit(inst) end end Link to comment Share on other sites More sharing options...
FurryEskimo Posted July 12, 2021 Author Share Posted July 12, 2021 @Kyno I wish, but I’m afraid not. See, the trouble is that you can’t apply the same food bonus to all items, and sometimes the same food comes in various forms, such as with a spice. When I was done writing this code it was around 800 lines long.. I took steps to reduce it, but it really is just, a lot, a lot.. I don’t want all that code in the character’s prefab file, but that’s currently where it is, and it works fine, but it makes working in the file more difficult. Link to comment Share on other sites More sharing options...
Monti18 Posted July 12, 2021 Share Posted July 12, 2021 What penguin0616 meant was that you use it like this: AddPrefabPostInit("your_character",function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end --code end) If you would use it like this, it should work. You could also post the code you have to apply the food bonus if you want, perhaps I can help you reduce it a bit. 2 1 Link to comment Share on other sites More sharing options...
FurryEskimo Posted July 12, 2021 Author Share Posted July 12, 2021 (edited) @Kyno I'm afraid I don't understand the code you've written.. @Monti18 I'll test that now. Update: That worked!! The code is still super-duper bloated, but it's working! Edited July 12, 2021 by FurryEskimo Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now