kabik Posted August 17, 2023 Share Posted August 17, 2023 Is there anything similar to inheritance for lua modding? I mean if I want to create a character "Wormwood v.2" with the only difference being his food health modifier, do I have to make a whole new character and copy everything or can I do it in a simpler way? I want to keep the original Wormwood and have a second copy of him aswell. I also have a bonus question . What is the difference between coding the same functionality in these two different ways? And is any of those alternatives preferred over the other? Spoiler alternative 1. AddPrefabPostInit("wormwood", function(inst) inst:AddTag("reader") inst:AddComponent("reader") end) alternative 2. local function ReadBook(prefab) prefab:AddTag("reader") prefab:AddComponent("reader") end AddPrefabPostInit("wormwood", ReadBook) I can add this line to alternative 1 but does it also work for alternative 2? inst.components.eater:SetOnEatFn() Link to comment https://forums.kleientertainment.com/forums/topic/150464-can-you-inherit-code/ Share on other sites More sharing options...
_zwb Posted August 18, 2023 Share Posted August 18, 2023 On 8/17/2023 at 8:41 AM, kabik said: mean if I want to create a character "Wormwood v.2" with the only difference being his food health modifier, do I have to make a whole new character and copy everything or can I do it in a simpler way? Making a mod that bypass Klei's purchase system is not allowed, it sounds like your mod is going to do that. On 8/17/2023 at 8:41 AM, kabik said: What is the difference between coding the same functionality in these two different ways? It's the same, the only difference is readability(sometimes). Link to comment https://forums.kleientertainment.com/forums/topic/150464-can-you-inherit-code/#findComment-1659877 Share on other sites More sharing options...
kabik Posted August 18, 2023 Author Share Posted August 18, 2023 (edited) 2 hours ago, _zwb said: Making a mod that bypass Klei's purchase system is not allowed, it sounds like your mod is going to do that. I took Wormwood as an example since it was easier. I play with my children and want to use Charlie, a character mod from the workshop, I want to make a version that have less sanity/hunger drain for my children to play and one that have more sanity drain for myself. I could just make 2 copy of the character but if there is a way to "inherit" the character I won't be force to redo it every time the workshop is updated. Why would Wormwood bypass Klei's purchase system? Is it because he is a locked character? I have all characters but its a mod character that I was interested in. Edit: The mod I'm trying to make is not for the workshop, I know I need the modders approval if I wanted to upload something like that to the workshop. Edited August 18, 2023 by kabik Added information Link to comment https://forums.kleientertainment.com/forums/topic/150464-can-you-inherit-code/#findComment-1659902 Share on other sites More sharing options...
Rickzzs Posted August 18, 2023 Share Posted August 18, 2023 Yes you can. use Prefabs.charlie.fn() to create a same prefab, but then you need to modify much more. It is not too easy. If you only want to modify a certain player, use inst.userid to determine who is playing. Link to comment https://forums.kleientertainment.com/forums/topic/150464-can-you-inherit-code/#findComment-1659924 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