Jump to content

Recommended Posts

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 by Hydrogenek
Issue solved

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.

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.

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.

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...