Hydrogenek Posted March 21, 2023 Share Posted March 21, 2023 (edited) I've been making a pretty basic character mod and have basically finished everything, but I just can't figure out how to make the character regenerate health based on the time of day. Basically I'd like the character to start regenerating health during dusk and night, stopping once it becomes day again. The rate of regeneration should be faster during the night. I'm still pretty new to making mods for the game in general so any help would be greatly appreciated! Edited March 21, 2023 by Hydrogenek Issue solved Link to comment https://forums.kleientertainment.com/forums/topic/146654-solved-need-help-with-making-health-regeneration-dependent-on-the-day-phases/ Share on other sites More sharing options...
Merkyrrie Posted March 21, 2023 Share Posted March 21, 2023 You can use inst:WatchWorldState for this. There's a couple options for what "world state" to watch for but simplest option would be to use "phase", so something like this: -- In your master_postinit inst:WatchWorldState("phase", myFunction) -- A function outside your master_postinit, somewhere above local myFunction(inst) local phase = TheWorld.state.phase -- Your code here end This is more or less how Abigail does her damage changes. I know the Caves use some different world states but I don't know for sure if it still uses "phase" the same way or not, so that could use some testing. Link to comment https://forums.kleientertainment.com/forums/topic/146654-solved-need-help-with-making-health-regeneration-dependent-on-the-day-phases/#findComment-1626553 Share on other sites More sharing options...
Hydrogenek Posted March 21, 2023 Author Share Posted March 21, 2023 Using your code gave an error stating "syntax error near 'local' " at the line being quoted below 5 hours ago, Merkyrrie said: local phase = TheWorld.state.phase I apologise in advance if it's something really easy to resolve, I'm just honestly that much of a newbie to coding. Link to comment https://forums.kleientertainment.com/forums/topic/146654-solved-need-help-with-making-health-regeneration-dependent-on-the-day-phases/#findComment-1626583 Share on other sites More sharing options...
Merkyrrie Posted March 21, 2023 Share Posted March 21, 2023 11 minutes ago, Hydrogenek said: Using your code gave an error stating "syntax error near 'local' " at the line being quoted below I apologise in advance if it's something really easy to resolve, I'm just honestly that much of a newbie to coding. Oh no, sorry its my mistake. it needs to be 'local function myFunction(inst)' I forgot the word "function" in there somehow. 1 Link to comment https://forums.kleientertainment.com/forums/topic/146654-solved-need-help-with-making-health-regeneration-dependent-on-the-day-phases/#findComment-1626585 Share on other sites More sharing options...
Hydrogenek Posted March 21, 2023 Author Share Posted March 21, 2023 Everything seems to be working now, thank you very much! Link to comment https://forums.kleientertainment.com/forums/topic/146654-solved-need-help-with-making-health-regeneration-dependent-on-the-day-phases/#findComment-1626612 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