Jump to content

Need help with a character


KXWl1

Recommended Posts

Create a variable that's stored to the entity, listen for event "temperaturedelta" to modify this variable to your liking, and finally use the sanity component's "custom_rate_fn" custom function to apply the variable as a sanity rate by returning your variable in a wrapper function.

Link to comment
Share on other sites

14 hours ago, CarlZalph said:

Create a variable that's stored to the entity, listen for event "temperaturedelta" to modify this variable to your liking, and finally use the sanity component's "custom_rate_fn" custom function to apply the variable as a sanity rate by returning your variable in a wrapper function.

Thanks, could you give me some examples?

Link to comment
Share on other sites

Here's an example:

-- Put this part somewhere outside master_postinit
local myCustomSanityChangePerSecond = 1

local mySanityRateFunction = function(inst, deltaTime)
	return myCustomSanityChangePerSecond
end

-- Put this part in master_postinit
inst.components.sanity.custom_rate_fn = mySanityRateFunction

Then, somewhere else in the code, you can modify the myCustomSanityChangePerSecond variable. In the example below, I have done as @CarlZalph ("Wololooo") suggested and hooked up a custom function to a listener listening for "temperaturedelta", which is the event called when SetTemperature() is called on the temperature component. You want your myCustomSanityChangePerSecond to be calculated using the temperature, so listening for changes to it is a good way to go.

-- Put this part somewhere outside master_postinit
local myTemperatureChangeFunction = function(inst, data)
	-- Here we can access the data from the event. In the case of "temperaturedelta",
	-- we get data.last and data.new, which are the previous temperature value
	-- and the new temperature value, respectively.
	-- Do whatever calculations you want with them, to find the current sanity rate you want,
	-- and set myCustomSanityChangePerSecond to something.
	myCustomSanityChangePerSecond = 0
end

-- Put this part in master_postinit
inst:ListenForEvent("temperaturedelta", myTemperatureChangeFunction)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...