Jump to content

Recommended Posts

Here's the gist; I've been creating a simple character mod but I have extremely little knowledge of coding. Everything I've done so far has been done with the help of tutorials. However, I have a specific character trait that I haven't seen anyone else give any hints on how to do. That being a boost to the sanity drain from being wet.

If anyone has any tips on where to even start with this, I'd be very grateful!

Mod folder attached.

Dolly.zip

local function onprecipitationchanged(src, preciptype)
		if preciptype == "rain" then
			inst.components.sanity.dapperness = dapperness_onrain
		else
			inst.components.sanity.dapperness = -1
		end
	end
	inst:ListenForEvent("precipitationchanged", function(wrld, data) onprecipitationchanged(inst, data) end, TheWorld)
	
	
	inst.OnLoad = onload
    inst.OnNewSpawn = onload

This is from the mod Drako, a character who gained sanity from the rain, but I tweaked the code to make the character lose sanity during the rain. This code goes into master postinit.

2 hours ago, Andreasgamming said:

local function onprecipitationchanged(src, preciptype)
		if preciptype == "rain" then
			inst.components.sanity.dapperness = dapperness_onrain
		else
			inst.components.sanity.dapperness = -1
		end
	end
	inst:ListenForEvent("precipitationchanged", function(wrld, data) onprecipitationchanged(inst, data) end, TheWorld)
	
	
	inst.OnLoad = onload
    inst.OnNewSpawn = onload

This is from the mod Drako, a character who gained sanity from the rain, but I tweaked the code to make the character lose sanity during the rain. This code goes into master postinit.

Tysm! This is amazing help, but I'm not quite sure where the 'master postinit' is. Is it located in the character mod folder or...?

1 hour ago, Andreasgamming said:

Oh, it is located under scripts-->prefabs--->dolly.lua

The code that manages the amount of health, sanity and hunger.

Again, thank you for your help. However, when I put this line of code into the master postinit, I ran a game, hosted the mod, turned on rain and got this crash.

Image attached.

crash log.PNG

Okay I fixed it, I forgot to give you the code that Declared the actual function. Here you go, I tested it too to make sure it worked and it does, right now the current setting is set to where she loses 1 sanity per second when it rains.

Dolly.zip

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