lakhnish Posted July 25, 2018 Share Posted July 25, 2018 (edited) My mod adds the component moisture to mobs, allowing them to get wet from water balloons. No problems occur with mobs that only have one prefab listed under in their lua. For example, frog.lua is simply frog. This is what I would add in the local function fn(). inst:AddComponent("moisture") The issue arises with mobs that have multiple prefabs listed under a single lua. For example, koalefant.lua has both "koalefant_summer" and "koalefant_winter" as well as common function for the basis of their creation. What I've done is implemented that code above into the common function, but in the modmain.lua, refer to both prefabs of the mobs. This results in a crash, and I only have this issue with mobs with multiple prefabs. I'm new to modding in general and not the best coder. Any help is appreciated. Attached are the modmain.lua, modinfo.lua, as well as the crash logs and the mod itself. The only difference between the one attached here and the one I've published on steam is the addition of the koalefant.lua and addition of the prefabs "koalefant_summer", and "kalefant_winter" in the modmain.lua. Thank you. To put in workshop.zip client_log.txt Edited July 25, 2018 by lakhnish Added client_log.txt Link to comment Share on other sites More sharing options...
ksaab Posted July 25, 2018 Share Posted July 25, 2018 (edited) Why do not you use AddPrefabPostInit? It is a bad practice to replace original game files. local addMoistTo = {"frog", "spider", "beefalo", etc} for _, prefab in pairs(addMoistTo) do AddPrefabPostInit(prefab, function(inst) inst:AddComponent("moisture") end) end And there aren't any details in your crash log, you should check the server_log.txt Edited July 25, 2018 by ksaab Link to comment Share on other sites More sharing options...
lakhnish Posted July 27, 2018 Author Share Posted July 27, 2018 (edited) Thank you very much. For those who are looking at this in the future, this is what I did in the modmain.lua addMoistTo = { --[[ Stupidly long list of mobs to get wet ]]-- } for k,v in pairs(addMoistTo) do AddPrefabPostInit(v, function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end; inst:AddComponent("moisture") end) end Edited July 27, 2018 by lakhnish Words Link to comment Share on other sites More sharing options...
IronHunter Posted July 27, 2018 Share Posted July 27, 2018 An alternative way which would probably be more useful for custom mobs. Would be to hook into the health/combat component and add moisture. AddComponentPostInit("health", function(self) if self.inst.components.moisture == nil and self.inst.components.inventoryitemmoisture == nil then self.inst:AddComponent("moisture") self.inst.components.moisture.baseDryingRate = 2 -- if self.inst.components.temperature == nil then -- self.inst:AddComponent("temperature") -- end end end) Could also use AddPrefabPostInitAny(function(inst) if inst.components.health and inst.components.moisture == nil and inst.components.inventoryitemmoisture == nil then inst:AddComponent("moisture") end end) Afterware you can then exclude prefabs with tags like walls or other things that don't fit your criteria. This way you basically have a blanket way to make everything even modded stuff have moisture. Not sure if you want inventoryitemmoisture creatures like birds but you can customize it until your hearts content. Link to comment Share on other sites More sharing options...
lakhnish Posted July 28, 2018 Author Share Posted July 28, 2018 (edited) @IronHunter Thanks! For some reason, I was running into performance issues (server lag, not FPS) using the AddPrefabPostInitAny, but there was a thunderstorm in my area at the time, even though I have a wired connection. I'm going to wait before I push an update for the mod, but look forward to seeing not only mod compatibility, but also compatibility with future updates that add mobs. Edit: Attached files of my latest hosted game where I did not have performance issues, in case you see something I don't, though I was at two bars instead of three, but will try again when weather conditions are better in case something was b/c of that. To put in workshop.zip client_log.txt server_log.txt Edited July 28, 2018 by lakhnish Added files Link to comment Share on other sites More sharing options...
lakhnish Posted July 28, 2018 Author Share Posted July 28, 2018 The weather conditions have cleared, but I still have performance issues. I've also tried it with both versions. I think I'm going to stick with what I have for now for users who don't have as beefy a cpu as mine or not that great connection. Thanks though. 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