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 https://forums.kleientertainment.com/forums/topic/114778-need-help-with-a-character/ 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 https://forums.kleientertainment.com/forums/topic/114778-need-help-with-a-character/#findComment-1296600 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 https://forums.kleientertainment.com/forums/topic/114778-need-help-with-a-character/#findComment-1296731 Share on other sites More sharing options...
Ultroman Posted January 10, 2020 Share Posted January 10, 2020 (edited) 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) Edited February 15, 2020 by Ultroman Link to comment https://forums.kleientertainment.com/forums/topic/114778-need-help-with-a-character/#findComment-1297951 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