Jump to content

Need help with mod coding >u<

Recommended Posts

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.lua

try putting this

inst.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 question

local 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)end

You can replace TUNING.DAPPERNESS_LARGE with a number if you want.  Positive makes it regen, negative makes it drain

Edited by Zackreaver
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...