kokoekwjd Posted February 24, 2023 Share Posted February 24, 2023 (edited) Hi! i need some help! I want my custom character's sanity to increase as the my character's health goes down... but I can't solve that. Can anyone please tell me how to do it? Please? T.T Edited February 24, 2023 by kokoekwjd Link to comment https://forums.kleientertainment.com/forums/topic/146144-help-custom-character-perks-code/ Share on other sites More sharing options...
Merkyrrie Posted March 1, 2023 Share Posted March 1, 2023 Depends on if you want it to be like +3/minute at say 50% health, or if you want it to go up by say 1 sanity for every 1 damage taken. The former would want to use the custom sanity fn built into the sanity component to effect your current sanity rate, the latter would want to do a ListenForEvent for the healthdelta event pushed whenever your character takes damage of any kind. Link to comment https://forums.kleientertainment.com/forums/topic/146144-help-custom-character-perks-code/#findComment-1622644 Share on other sites More sharing options...
kokoekwjd Posted March 8, 2023 Author Share Posted March 8, 2023 On 3/1/2023 at 1:14 PM, Merkyrrie said: Depends on if you want it to be like +3/minute at say 50% health, or if you want it to go up by say 1 sanity for every 1 damage taken. The former would want to use the custom sanity fn built into the sanity component to effect your current sanity rate, the latter would want to do a ListenForEvent for the healthdelta event pushed whenever your character takes damage of any kind. Oh, thank you! Sorry for checking late. I want to regen sanity of 1/sec when my character's health is less than 50%! What should I do in this case?? Link to comment https://forums.kleientertainment.com/forums/topic/146144-help-custom-character-perks-code/#findComment-1624237 Share on other sites More sharing options...
Merkyrrie Posted March 21, 2023 Share Posted March 21, 2023 You can probably just use custom_rate_fn then, -- In your master_postinit inst.components.sanity.custom_rate_fn = myFunction myFunction can be named whatever your function will be named, within the function you can do an if statement to check your current health's percentage with inst.components.health:GetPercent() Then return the positive change to your sanity at the end of the function local myFunction(inst) local delta = 0 if inst.components.health:GetPercent() <= .5 then delta = 1 -- This should be how much you want it to be recovering, I don't know the exact number to place here to get 1 sanity per second end return delta end the returned value from custom_rate_fn is then directly added to the change whenever sanity is lowered overtime Link to comment https://forums.kleientertainment.com/forums/topic/146144-help-custom-character-perks-code/#findComment-1626555 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