KXWl1 Posted January 4, 2020 Share Posted January 4, 2020 I want to make a chracter who loses sanity per min when his temperature is low and gains sanity per min when his temperature is high, but I don't know what to do. Link to comment Share on other sites More sharing options...
CarlZalph Posted January 4, 2020 Share Posted January 4, 2020 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 More sharing options...
KXWl1 Posted January 5, 2020 Author Share Posted January 5, 2020 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 More sharing options...
Ultroman Posted January 10, 2020 Share Posted January 10, 2020 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 More sharing options...
Recommended Posts
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.