SpectralGamer Posted February 19, 2022 Share Posted February 19, 2022 As the title says, I am a HEAVILY inexperienced coder, but I've made a personal mod character, to play with some friends and their personal mod characters too. However, I'm wanting to upgrade, and make my character more... interesting to play. For personal reasons, I'm going to keep the character themselves anonymous, but the context behind them, is they they are a monster hunting deer satyr. As they stand now, they're very cookie cutter generic to play as, with only a few set unique aspects. These include: - Resistance to the cold/winter, weakness to heat/summer - Does not fear the dark, or monsters - Loses Sanity when killing Deer Here are the additions I want to add, so that they actually have some challenge to them: - Loses sanity around Mushtrees, spores, and eating mushrooms - Cannot regain sanity (or very few ways to recover sanity) - Changing power and speed with the seasons. Power peaks in Winter, Speed peaks in Spring - Crossbow (this idea can wait, as I'd like this to be the last thing to add completely.) The first topic I'd like to ask for help on, is the character losing Sanity with Mushrooms, I've seen a lot of different pieces of code, like Willow's fire sanity code, and Wigfried's meat eater code, but after a month of different methods, and code setups, I haven't made progress at all. I'd like to ask for help, so I can do more of this by myself at a later day. Link to comment https://forums.kleientertainment.com/forums/topic/137636-inexpereinced-at-coding-want-to-make-upgrades-to-a-mod-character-for-friends/ Share on other sites More sharing options...
Monti18 Posted February 21, 2022 Share Posted February 21, 2022 For your first topic you can add the sanityaura component to mushtrees and spores and define the aurafn so that it checks if the character is your character which then makes your character lose sanity. Spoiler --add this to a AddPrefabPostInit to the things you want your character to lose sanity from --don't forget to make the ismastersim check before adding this! inst:AddComponent("sanityaura") inst.components.sanityaura.aurafn = function(inst,observer) if observer and observer.prefab == "your_character" then --replace with your character prefab return -TUNING.SANITYAURA_MED else return 0 end end For not regaining sanity, you could overwrite the sanity component in the way you want it to work, for example: Spoiler AddComponentPostInit("sanity",function(self) local old_DoDelta = self.DoDelta self.DoDelta = function(self,delta,overtime,...) if self.inst.prefab == "your_character" and delta > 0 then --checks if the value of sanity is higher than 0, if yes it will be set to 0 delta = 0 end return old_DoDelta(self,delta,overtime,...) end end --if you want to have a way to bypass the setting to 0, you can use either inst.components.sanity:SetPercent or set it directly by using inst.components.sanity.current = 100 For your third point look for WatchWorldState, you can use it to run a function if a certain season starts. inst:WatchWorldState("isautumn",yourfunction) Look in the game files for examples on how to use it. For your fourth point you can have a look at other mods, there are some that added a bow, so this would be pretty similar I hope that helps! 2 Link to comment https://forums.kleientertainment.com/forums/topic/137636-inexpereinced-at-coding-want-to-make-upgrades-to-a-mod-character-for-friends/#findComment-1541133 Share on other sites More sharing options...
SpectralGamer Posted March 22, 2022 Author Share Posted March 22, 2022 Thank you so much for the help! I'm still working as diligently as I can on the help you've given me, but I've hit a roadblock while I was working on making the Character allergic to eating mushrooms, as this code only works when caves are disabled: Mushroom Allergy (edible)(does not work with caves).lua I'd like to ask anyone to help me figure out what I'm doing wrong, so I can move past this. Link to comment https://forums.kleientertainment.com/forums/topic/137636-inexpereinced-at-coding-want-to-make-upgrades-to-a-mod-character-for-friends/#findComment-1550962 Share on other sites More sharing options...
Monti18 Posted March 22, 2022 Share Posted March 22, 2022 The problem is that edible is a component which should only be on the server. When making a world without caves, the client and server are the same, with caves they are not. Spoiler local food_stat_dict = { red_cap = { health = -45, sanity = -10, hunger = 12.5 }, green_cap = { health = -20, sanity = -15, hunger = 12.5 }, blue_cap = { health = -40, sanity = -20, hunger = 12.5 }, moon_cap = { health = -400, sanity = 0, hunger = 0 }, red_cap_cooked = { health = -10, sanity = -10, hunger = 0 }, green_cap_cooked = { health = -5, sanity = -10, hunger = 0 }, blue_cap_cooked = { health = -5, sanity = -10, hunger = 0 }, moon_cap_cooked = { health = 0, sanity = -200, hunger = -175 }, } for food_prefab, food_stats in pairs(food_stat_dict) do AddPrefabPostInit(food_prefab, function(inst) if GLOBAL.TheWorld.ismastersim then inst.components.edible.healthvalue = food_stats["health"] or 0 inst.components.edible.hungervalue = food_stats["hunger"] or 0 inst.components.edible.sanityvalue = food_stats["sanity"] or 0 end end) end This way it should work Link to comment https://forums.kleientertainment.com/forums/topic/137636-inexpereinced-at-coding-want-to-make-upgrades-to-a-mod-character-for-friends/#findComment-1551050 Share on other sites More sharing options...
LucasM3 Posted March 22, 2022 Share Posted March 22, 2022 Wouldn't this code affect all characters that eat mushrooms? I feel like a better method would be to tie an "oneat" event listener to your character and then make the necessary stat changes there. That's just my initial impression on observing this code, I will admit I'm not the most versed DST coder so perhaps I am wrong. Link to comment https://forums.kleientertainment.com/forums/topic/137636-inexpereinced-at-coding-want-to-make-upgrades-to-a-mod-character-for-friends/#findComment-1551094 Share on other sites More sharing options...
penguin0616 Posted March 22, 2022 Share Posted March 22, 2022 3 hours ago, LucasM3 said: Wouldn't this code affect all characters that eat mushrooms? Correct. 3 hours ago, LucasM3 said: feel like a better method would be to tie an "oneat" event listener to your character and then make the necessary stat changes there. Klei actually added support for modded-food-eater-related stuff. It would be better to use Eater.custom_stats_mod_fn(inst, health_delta, hunger_delta, sanity_delta, food, feeder) The above method is called by line 229 in the Eater:Eat method in components/eater.lua 2 Link to comment https://forums.kleientertainment.com/forums/topic/137636-inexpereinced-at-coding-want-to-make-upgrades-to-a-mod-character-for-friends/#findComment-1551146 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