Jump to content

Recommended Posts

Ello again.

Today I have yet another minor issue. Nothing too major, but something I may need to fix later on.
Firstly, I'm seeing an issue with my character's health and hunger changing during the phases of day. 
He starts out weak during the day, so he has low health but greater hunger. And during dusk and night his health increases and his hunger decreases. The issue I'm having is, they reset to their assigned number even after hunger went down or I've been damaged.

Eg. During the day his health is base 100, he took damage and was reduced to 50. But dusk rolls around and his stats change to his base health which is suppose to be 200.
I want to make it so he still retains the damage but his base health still changes. 
Same with hunger. If his hunger went down I'd like it to carry over to the other phases rather than resetting. 
Hopefully I am making sense? ^^;

Link to comment
Share on other sites

How are you changing the Health and Hunger max values?
 

I believe you should do something like this

inst.components.hunger:SetMax(TUNING.CHAR_HUNGER)

Another question is how do you wanna update the current Hunger/Health. Do you want to keep the same value or keep the same percentage of the total?
Either way, if you are having trouble with the final value after increasing the max value, store it before you change the max value and then update the current value to whatever you want.

Link to comment
Share on other sites

Ok I understand your problem now.

You'll have to do has I said before: store it before you change the max value and then update the current value to whatever you want.

So, you would need to do something like this

local hunger = inst.components.hunger.current
inst.components.hunger:SetMax(somevalue)
inst.components.hunger.current = hunger

local health = ins.components.health.currenthealth
inst.components.health:SetMaxHealth(somevalue)
inst.components.health:SetCurrentHealth(health)

However I would recommend you to use percentages over the current value.
I think it will more interesting that way.
For example: when changing from night to day the total value will decrease from say 100 to 50. if the current value is 50, in the beginning of the day the character will start with full hunger points (50) while if you use the percentage of the previous total the player will start the day with 25 hunger points.
It makes for a bigger challenge when transitioning to the day while also making a bigger reward when transitioning to the night. :D
But that's just my opinion.

Link to comment
Share on other sites

7 hours ago, TheGamerDracul said:

Can't figure out what you mean by the last part. ^^;

Anyway where do I put your code?

 

The attached file should work.

I'll try to explain better.

Right now the way it should work whenever a phase changes the player will retain the same amount of HP only changing it's maximum.
However I believe this is bad. Why?
Imagine the end of your first day. During the night the player managed to get is life up to the maximum (333 HP). Then the second day begins and his life is updated to 150. It's all okay, but when dusk begins, the player will retain 150 HP while the maximum HP is now 200.
So basically over the course of the day the player managed to loose 183 HP.

In order to counter this I think you should use percentages. Meaning that whenever the max life got updated, the current HP is also updated to the correspondent amount. Using the same example, over the course of the day, dusk and night cycle the player would always have 100% HP (be it 150 during the day, 200 during dusk or 333 during night).

If he got damaged it would reflect in the following cycles without throwing resources to waste.
This would make the character harder to kill during the night since it has higher HP, but easier to heal during the day where it has low HP.

dracul.lua

Link to comment
Share on other sites

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
 Share

×
  • Create New...