shadedareas Posted May 23, 2015 Share Posted May 23, 2015 (edited) If anyone could look this over and tell me if I'm right or I've missed anything obvious... or am misapplying the code... I'd very much appreciate it.I posted this in the wrong forum earlier and instead of getting much help I got asked if I bothered to search the forums. I promise I have read through everything I can find on sanity... I'm just having trouble grasping it and have zero confidence in my approach on this. And I'm not totally inept... earlier today I created another character who takes sanity losses for each tree they cut down. I do get some of this. Here are my attempts. Again... I seem to be lacking some fundamental understanding of how sanity works so go easy on me.1. Goal : Lower general decrease of sanity inst.components.sanity:SetRate(TUNING.WILSON_SANITY_RATE * 0.7)2. Goals : When around other people, I want those people to get a sanity boost... and him to get a sanity drain. inst:AddComponent("sanityaura") inst.components.sanityaura.aura = TUNING.SANITYAURA_LARGEinst.components.sanity.custom_rate_fn = function(inst, observer) if observer then return -TUNING.DAPPERNESS_SMALL else return 0end3. Goals : If possible I'd also like to give him a sanity boost at night or when it's raininginst.components.sanity.custom_rate_fn = function(inst) if TheWorld.state.israining then return TUNING.DAPPERNESS_MED else return 0endinst.components.sanity.custom_rate_fn = function() local night = GLOBAL.TheWorld.state.isnight local dusk = GLOBAL.TheWorld.state.isdusk if night then return TUNING.DAPPERNESS_MED else if dusk then return TUNING.DAPPERNESS_SMALL else return 0 endend(earlier I was trying for the gain to come from fishing but because of the flack I got I figure I should try something I understand better) Edited May 23, 2015 by shadedareas Link to comment https://forums.kleientertainment.com/forums/topic/54307-custom-character-needs-special-sanity-settings/ Share on other sites More sharing options...
Seiai Posted May 23, 2015 Share Posted May 23, 2015 (edited) @shadedareas, is that all like in your code at the same time? because if yes, then u are overwriting your earlier changes on the custom_rate_fn. meaning that while daytime, it always ends up at "return 0".^^ u have to combine that all into one function. just start with a local sanitybonus-variable of 0 and then add the different bonuses or maluses and return it in the end. Edited May 23, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/54307-custom-character-needs-special-sanity-settings/#findComment-639929 Share on other sites More sharing options...
shadedareas Posted May 23, 2015 Author Share Posted May 23, 2015 I don't think I understand coding enough to know what you mean. :-\I just sort of found examples close to what I want and edited them.I think I understand your meaning... that ... if it's night but not raining that the not raining makes it zero and vice versa.I don't know how to make this all one function. Link to comment https://forums.kleientertainment.com/forums/topic/54307-custom-character-needs-special-sanity-settings/#findComment-639959 Share on other sites More sharing options...
shadedareas Posted May 23, 2015 Author Share Posted May 23, 2015 (edited) would this be what you meant @Seiai ? inst.components.sanity.custom_rate_fn = function(inst, observer) local night = GLOBAL.TheWorld.state.isnight local dusk = GLOBAL.TheWorld.state.isdusk if observer then return -TUNING.DAPPERNESS_SMALL else if TheWorld.state.israining then return TUNING.DAPPERNESS_MED else if night then return TUNING.DAPPERNESS_MED else if dusk then return TUNING.DAPPERNESS_SMALL else return TUNING.WILSON_SANITY_RATE * (0.7)end Edited May 23, 2015 by shadedareas Link to comment https://forums.kleientertainment.com/forums/topic/54307-custom-character-needs-special-sanity-settings/#findComment-639963 Share on other sites More sharing options...
shadedareas Posted May 23, 2015 Author Share Posted May 23, 2015 Now it's crashing... :-\ so im guessing i did this wrong. Link to comment https://forums.kleientertainment.com/forums/topic/54307-custom-character-needs-special-sanity-settings/#findComment-639967 Share on other sites More sharing options...
DarkXero Posted May 23, 2015 Share Posted May 23, 2015 -- There is no such SetRate function in DST's sanity component -- Goal 1 -- in character's master_postinit inst.components.sanity.rate_modifier = 0.7 -- Goal 2 -- You give other people sanity -- in character's master_postinit inst:AddComponent("sanityaura") inst.components.sanityaura.aurafn = function(inst, observer) return TUNING.SANITYAURA_TINY end -- Other people reduce your character's sanity -- I check for other possible sanityauras for compatibility with other character mods -- in modmain AddPlayerPostInit(function(inst) if not inst.prefab == "mycharacter" then if not inst.components.sanityaura then inst:AddComponent("sanityaura") end local old = inst.components.sanityaura.aurafn if old then inst.components.sanityaura.aurafn = function(inst, observer) if observer.prefab == "mycharacter" then return -GLOBAL.TUNING.SANITYAURA_TINY + old(inst, observer) else return old(inst, observer) end end else inst.components.sanityaura.aurafn = function(inst, observer) if observer.prefab == "mycharacter" then return -GLOBAL.TUNING.SANITYAURA_TINY else return 0 end end end end end) -- Goal 3 -- in character's master_postinit inst.components.sanity.custom_rate_fn = function(inst) if TheWorld.state.isnight or TheWorld.state.israining then return TUNING.DAPPERNESS_MED else return 0 end end -- Bonus! -- elseif example inst.components.sanity.custom_rate_fn = function(inst) if TheWorld.state.isday then return TUNING.DAPPERNESS_TINY elseif TheWorld.state.isnight then return TUNING.DAPPERNESS_MED elseif TheWorld.state.israining then return TUNING.DAPPERNESS_MED_LARGE end end Link to comment https://forums.kleientertainment.com/forums/topic/54307-custom-character-needs-special-sanity-settings/#findComment-639980 Share on other sites More sharing options...
shadedareas Posted May 23, 2015 Author Share Posted May 23, 2015 Woah. Yeah... I never would've figured all that out on my own. Thank you so much, DarkXero ! Link to comment https://forums.kleientertainment.com/forums/topic/54307-custom-character-needs-special-sanity-settings/#findComment-640004 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