TheGamerDracul Posted March 29, 2017 Share Posted March 29, 2017 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 More sharing options...
Hineios Posted March 29, 2017 Share Posted March 29, 2017 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 More sharing options...
TheGamerDracul Posted March 29, 2017 Author Share Posted March 29, 2017 I just want to make it so both the health and hunger don't reset to their base values when they have gone down, via taking damage or losing hunger. Link to comment Share on other sites More sharing options...
Hineios Posted March 29, 2017 Share Posted March 29, 2017 I'm not sure I'm understanding the problem... Could you paste the code you are using? Link to comment Share on other sites More sharing options...
TheGamerDracul Posted March 29, 2017 Author Share Posted March 29, 2017 dracul.lua Link to comment Share on other sites More sharing options...
Hineios Posted March 29, 2017 Share Posted March 29, 2017 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. But that's just my opinion. Link to comment Share on other sites More sharing options...
TheGamerDracul Posted March 29, 2017 Author Share Posted March 29, 2017 Can't figure out what you mean by the last part. ^^; Anyway where do I put your code? Link to comment Share on other sites More sharing options...
TheGamerDracul Posted March 29, 2017 Author Share Posted March 29, 2017 Ah well, it didn't work anyway unfortunately. Must be wrong. Link to comment Share on other sites More sharing options...
RedHairedHero Posted March 29, 2017 Share Posted March 29, 2017 (edited) I'd recommend taking a look at how Wolfgang's file and how his stats are handled since they adjust between states as well. Edited March 29, 2017 by RedHairedHero Link to comment Share on other sites More sharing options...
TheGamerDracul Posted March 29, 2017 Author Share Posted March 29, 2017 They're so different from how I set mine up though. Link to comment Share on other sites More sharing options...
RedHairedHero Posted March 29, 2017 Share Posted March 29, 2017 38 minutes ago, TheGamerDracul said: They're so different from how I set mine up though. It's just a recommendation, it's of course ultimately up to you on how you want to approach it. Just thought I'd provide some insight. Link to comment Share on other sites More sharing options...
TheGamerDracul Posted March 29, 2017 Author Share Posted March 29, 2017 Thanks. It's just going to take time to figure this out. I really suck at coding... Link to comment Share on other sites More sharing options...
Hineios Posted March 30, 2017 Share Posted March 30, 2017 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 More sharing options...
TheGamerDracul Posted March 30, 2017 Author Share Posted March 30, 2017 Oh man, thank you so much. I feel really bad you had to do that for me though... I really suck at coding, it's no secret. I don't even know where to start... =n= Link to comment Share on other sites More sharing options...
TheGamerDracul Posted March 30, 2017 Author Share Posted March 30, 2017 Oh man, thank you so much. I feel really bad you had to do that for me though... I really suck at coding, it's no secret. I don't even know where to start... =n= But what do you mean using percentages? Sorry if I seem like an idiot with this. =n= Link to comment Share on other sites More sharing options...
Hineios Posted March 30, 2017 Share Posted March 30, 2017 No problem. However I checked the wolfgang file as suggested and I really must insist on the use of percentages. Try both out and keep which ever feels better for your character dracul.lua Link to comment Share on other sites More sharing options...
TheGamerDracul Posted March 30, 2017 Author Share Posted March 30, 2017 I think I understand. Lemme try this one out. Link to comment Share on other sites More sharing options...
TheGamerDracul Posted March 30, 2017 Author Share Posted March 30, 2017 Yup I think the new one works best! The old one did work but it showed the max health and hunger then went back to what he originally had. I can't thank you guys enough. Be sure I'll give you guys a shout out on my mod. Thank you so much. =v= Link to comment Share on other sites More sharing options...
Hineios Posted March 30, 2017 Share Posted March 30, 2017 You are welcome! Link to comment 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