sorachan8 Posted June 17, 2015 Share Posted June 17, 2015 I've got a character mod that I would like to set it up so he gains sanity and health in the rain, but loses sanity whenever it's not raining. I love the help if anyone could tell me what I need to do. >u< Link to comment Share on other sites More sharing options...
Zackreaver Posted June 19, 2015 Share Posted June 19, 2015 (edited) Would you like your character to gain sanity and health while it's raining? Or sanity and health while your characters wet?Cause you can have either In your characters master_postinit function in the file scripts/prefabs/yourcharactername.luatry putting thisinst.components.sanity.custom_rate_fn = function (guy) local easing = require "easing" local drypenalty = -1 local wetbonus = 1 if guy.components.moisture and guy.components.moisture:GetMoisture() > 1 then local delta = (easing.inSine(guy.components.moisture:GetMoisture(), 0, wetbonus, guy.components.moisture:GetMaxMoisture())) guy.components.health:DoDelta(delta,true) return delta else return drypenalty end end It will make your character lose sanity initially, but you should gain health and sanity as your character gets more wet. You can increase or decrease the bonus sanity by the wetbonus accordingly. As well as increase or decrease the initial penalty for being dry as you see fit. However if you would rather have just static values for when it's raining or not, here's code from DarkXero on another post that asked the same questionlocal function RainBuff(inst) inst.components.health:StartRegen(1, 2) inst.components.sanity.custom_rate_fn = function(inst) return TUNING.DAPPERNESS_LARGE endend local function Normal(inst) inst.components.health:StopRegen() inst.components.sanity.custom_rate_fn = function(inst) return -TUNING.DAPPERNESS_LARGE endend local function onbecamezoidberg(inst) if TheWorld.state.israining then RainBuff(inst) end inst:WatchWorldState("startrain", RainBuff) inst:WatchWorldState("stoprain", Normal)end local function onbecameghost(inst) Normal(inst) inst:StopWatchingWorldState("startrain", RainBuff) inst:StopWatchingWorldState("stoprain", Normal)end -- Your central functionlocal function master_postinit(inst) -- Other code of yours is here onbecamezoidberg(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamezoidberg) inst:ListenForEvent("ms_becameghost", onbecameghost)endYou can replace TUNING.DAPPERNESS_LARGE with a number if you want. Positive makes it regen, negative makes it drain Edited June 19, 2015 by Zackreaver Link to comment Share on other sites More sharing options...
sorachan8 Posted June 19, 2015 Author Share Posted June 19, 2015 Thanks this will help alot. >u< 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